-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudRun
More file actions
executable file
·199 lines (157 loc) · 3.54 KB
/
cloudRun
File metadata and controls
executable file
·199 lines (157 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
echo
echo ==== Using cloudRun $CLOUD_DIR ====
echo
usage() {
echo "usage: $0 start|stop|stopall|restart|status" >&2
exit 1
}
if test $# != 1; then
usage
fi
cmd=$1
# Return the actor's pid, or the empty string.
#
get_pid() {
PID=""
pid=`/bin/ps -e -ww -o pid,user,command | egrep -v 'awk|grep' | grep 'cloudProcess.py' | awk '{print $1}'`
PID=$pid
PID2=""
pid2=`/bin/ps -e -ww -o pid,user,command | egrep -v 'awk|grep' | grep 'CloudCam.py' | awk '{print $1}'`
PID2=$pid2
PID3=""
pid3=`/bin/ps -e -ww -o pid,user,command | egrep -v 'awk|grep' | grep 'wiggleCloud.py' | awk '{print $1}'`
PID3=$pid3
PID4=""
pid4=`/bin/ps -e -ww -o pid,user,command | egrep -v 'awk|grep' | grep 'clouduino_interface.py' | awk '{print $1}'`
PID4=$pid4
if test "$pid"; then
echo "cloudProcess is running as process $pid"
else
echo "cloudProcess is not running"
fi
if test "$pid2"; then
echo "CloudCam is running as process $pid2"
else
echo "CloudCamera is not running"
fi
if test "$pid3"; then
echo "wiggleCloud is running as process $pid3"
else
echo "wiggleCloud is not running"
fi
if test "$pid4"; then
echo "clouduino_interface is running as process $pid4"
else
echo "clouduino_inteface is not running"
fi
}
# Start a new actor. Complain if the actor is already running, and do not start a new one.
#
do_start() {
get_pid
if test "$PID"; then
echo "NOT starting new CloudCamera. Use restart if you want a new one."
return
fi
echo "Starting new CloudCamera..."
# run the actor, as follows:
# disable buffering of stdout using "stdbuf -o0"
# redirect stdout to logger at priority "warning" and stderr at priority "error"
{
nohup python cloudProcess.py
} &
# Check that it really started...
#
sleep 1
get_pid
if test "$PID"; then
echo " done."
else
echo " FAILED!"
fi
}
# Stop runCloudProcess.
#
do_stop() {
get_pid
if test ! "$PID"; then
return
fi
echo "Stopping runCloudProcess."
kill -TERM $PID
echo "Stopping CloudCam."
kill -TERM $PID2
echo "Stopping wiggleCloud."
kill -TERM $PID3
echo "Stopping clouduino_interface."
kill -TERM $PID4
}
# Stop all Cloud associated process.
#
do_stopall() {
get_pid
if test ! "$PID"; then
return
fi
echo "Stopping runCloudProcess."
kill -TERM $PID
if test ! "$PID2"; then
return
fi
echo "Stopping CloudCam."
kill -TERM $PID2
if test ! "$PID3"; then
return
fi
echo "Stopping wiggleCloud."
kill -TERM $PID3
if test ! "$PID4"; then
return
fi
echo "Stopping clouduino_interface."
kill -TERM $PID4
}
# Stop any running actor fairly violently.
#
do_stopdead() {
get_pid
if test ! "$PID"; then
return
fi
echo "Stopping arcticICC gently."
kill -TERM $PID
sleep 2
echo "Stopping arcticICC meanly."
kill -KILL $PID
kill -KILL $PID2
kill -KILL $PID3
kill -KILL $PID4
}
case $cmd in
start)
do_start
;;
stop)
do_stop
;;
stopall)
do_stopall
;;
stopdead)
do_stopdead
;;
status)
# Check whether the actor is running
get_pid
;;
restart)
do_stop
sleep 2
do_start
;;
*)
usage
;;
esac
exit 0