Upload xAutoRunTo5m.sh
Browse files- xAutoRunTo5m.sh +139 -0
xAutoRunTo5m.sh
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# version 1
|
4 |
+
|
5 |
+
# being undecided
|
6 |
+
FLAG_NAME=$1
|
7 |
+
|
8 |
+
# null
|
9 |
+
FLAG_NULL=$2
|
10 |
+
|
11 |
+
# flag Key
|
12 |
+
FLAG_KEY=$3
|
13 |
+
|
14 |
+
if [ -z "$FLAG_NAME" ] || [ "$FLAG_NAME" = " " ]; then
|
15 |
+
FLAG_NAME="null"
|
16 |
+
fi
|
17 |
+
if [ -z "$FLAG_NULL" ]; then
|
18 |
+
FLAG_NULL="null"
|
19 |
+
fi
|
20 |
+
if [ -z "$FLAG_KEY" ]; then
|
21 |
+
FLAG_KEY="null"
|
22 |
+
fi
|
23 |
+
|
24 |
+
cd /workspace
|
25 |
+
cd *
|
26 |
+
|
27 |
+
R_PATH="$(pwd)"
|
28 |
+
|
29 |
+
if [ ! -d "$R_PATH/SD" ]; then
|
30 |
+
echo "SD folder not found."
|
31 |
+
exit 101
|
32 |
+
fi
|
33 |
+
|
34 |
+
MUID=""
|
35 |
+
|
36 |
+
if [ -f "$R_PATH/SD/MUID.txt" ]; then
|
37 |
+
MUID=$(<./SD/MUID.txt)
|
38 |
+
MUID=${MUID%%+( )}
|
39 |
+
MUID=${MUID%%+(\n)}
|
40 |
+
#MUID_LEN=${#MUID}
|
41 |
+
#MUID=${MUID:1:MUID_LEN-2}
|
42 |
+
else
|
43 |
+
RANDOM_STR1="$(head -c 128 /dev/urandom | tr -dc 'A-Z')ZZ"
|
44 |
+
RANDOM_STR2="$(head -c 384 /dev/urandom | tr -dc 'A-Z0-9')ZZZZZZZZZZZZZZ"
|
45 |
+
MUID="${RANDOM_STR1::1}${RANDOM_STR2::14}${RANDOM_STR1:1:1}"
|
46 |
+
echo -e "$MUID" >> ./SD/MUID.txt
|
47 |
+
fi
|
48 |
+
|
49 |
+
MUIDL="${MUID::3}${MUID:13:3}"
|
50 |
+
|
51 |
+
OUPUT_PATH="SD/output"
|
52 |
+
OUPUT_PATH2="output"
|
53 |
+
|
54 |
+
#echo "$FLAG_NAME $FLAG_NULL $FLAG_KEY $R_PATH $OUPUT_PATH $MUID $MUIDL"
|
55 |
+
|
56 |
+
func_kill()
|
57 |
+
{
|
58 |
+
kill -9 $(ps -ef | grep 'autoUpload.sh' | grep -v 'grep' | awk '{print $2}')
|
59 |
+
kill -9 $(ps -ef | grep 'run.sh' | grep -v 'grep' | awk '{print $2}')
|
60 |
+
kill -9 $(ps -ef | grep 'webui' | grep -v 'grep' | awk '{print $2}')
|
61 |
+
kill -9 $(ps -ef | grep 'launch.py' | grep -v 'grep' | awk '{print $2}')
|
62 |
+
kill -9 $(ps -ef | grep 'gradio' | grep -v 'grep' | awk '{print $2}')
|
63 |
+
rm -rf /tmp/*
|
64 |
+
rm -rf $R_PATH/$OUPUT_PATH
|
65 |
+
rm -rf $R_PATH/$OUPUT_PATH2
|
66 |
+
for item in $(find . -name "output_${MUIDL}*.zip"); do
|
67 |
+
rm -rf $item
|
68 |
+
done
|
69 |
+
}
|
70 |
+
|
71 |
+
if [ "$FLAG_KEY" = "null" ]; then
|
72 |
+
# enter when the user runs manually.
|
73 |
+
kill -9 $(ps -ef | grep 'jupyter' | grep -v 'grep' | awk '{print $2}')
|
74 |
+
func_kill
|
75 |
+
apt-get install -y inotify-tools
|
76 |
+
apt-get install -y zip
|
77 |
+
pip3 install pcloud
|
78 |
+
CURRNET_PID=$$
|
79 |
+
#kill -9 $(ps -ef | grep 'xAutoRunTo5m' | grep -v 'grep' | awk '{print $2}')
|
80 |
+
kill -9 $(ps -ef | grep 'xAutoRunTo5m' | grep -v 'grep' | awk -v pid=$CURRNET_PID '$2 != pid {print $2}')
|
81 |
+
FLAG_KEY="startDaemon"
|
82 |
+
bash -c ". $R_PATH/xAutoRunTo5m.sh $FLAG_NAME $FLAG_NULL $FLAG_KEY"
|
83 |
+
elif [ "$FLAG_KEY" = "startDaemon" ]; then
|
84 |
+
cd /workspace
|
85 |
+
cd *
|
86 |
+
FLAG_KEY="runningDaemon"
|
87 |
+
chmod 755 xAutoRunTo5m.sh
|
88 |
+
nohup ./xAutoRunTo5m.sh $FLAG_NAME $FLAG_NULL $FLAG_KEY 2>&1 &
|
89 |
+
elif [ "$FLAG_KEY" = "runningDaemon" ]; then
|
90 |
+
cd /workspace
|
91 |
+
cd *
|
92 |
+
w1=0
|
93 |
+
w2=0
|
94 |
+
w3=0
|
95 |
+
while :
|
96 |
+
do
|
97 |
+
uptime_minutes=$(awk '{print int($1/60)}' /proc/uptime)
|
98 |
+
current_minute=$(date +%M)
|
99 |
+
if [ "$uptime_minutes" -ge 181 ]; then
|
100 |
+
func_kill
|
101 |
+
kill -15 $(ps -ef | grep 'xAutoRunTo5m.sh' | grep -v 'grep' | awk '{print $2}')
|
102 |
+
echo "kill xAutoRunTo5m"
|
103 |
+
exit 100
|
104 |
+
fi
|
105 |
+
if [ $(expr ${current_minute} % 5) -eq 0 ]; then
|
106 |
+
w2=0
|
107 |
+
if [ ${w1} -eq 0 ]; then
|
108 |
+
w1=1
|
109 |
+
chmod 755 run.sh
|
110 |
+
nohup ./run.sh 2>&1 &
|
111 |
+
sleep 50s
|
112 |
+
for item in $(find . -name "output_${MUIDL}*.zip"); do
|
113 |
+
rm -rf $item
|
114 |
+
done
|
115 |
+
fi
|
116 |
+
elif [ $(expr ${current_minute} % 5) -eq 4 ]; then
|
117 |
+
w1=0
|
118 |
+
if [ ${w2} -eq 0 ]; then
|
119 |
+
w2=1
|
120 |
+
sleep 50s
|
121 |
+
kill -9 $(ps -ef | grep 'run.sh' | grep -v 'grep' | awk '{print $2}')
|
122 |
+
kill -9 $(ps -ef | grep 'webui' | grep -v 'grep' | awk '{print $2}')
|
123 |
+
kill -9 $(ps -ef | grep 'launch.py' | grep -v 'grep' | awk '{print $2}')
|
124 |
+
kill -9 $(ps -ef | grep 'gradio' | grep -v 'grep' | awk '{print $2}')
|
125 |
+
rm -rf /tmp/*
|
126 |
+
bash -c ". $R_PATH/out.sh 1 $MUIDL && sleep 2 && rm -rf $R_PATH/$OUPUT_PATH && rm -rf $R_PATH/$OUPUT_PATH2"
|
127 |
+
sleep 1s
|
128 |
+
fi
|
129 |
+
fi
|
130 |
+
sleep 2s
|
131 |
+
done
|
132 |
+
elif [ "$FLAG_KEY" = "kill" ]; then
|
133 |
+
func_kill
|
134 |
+
kill -15 $(ps -ef | grep 'xAutoRunTo5m.sh' | grep -v 'grep' | awk '{print $2}')
|
135 |
+
echo "kill xAutoRunTo5m"
|
136 |
+
exit 100
|
137 |
+
else
|
138 |
+
:
|
139 |
+
fi
|