-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
57 lines (52 loc) · 1.21 KB
/
run.sh
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
#!/bin/bash
PIDFILE=run.py.pid
case $1 in
start)
##check if pid exists and matches a running process
if [ -f $PIDFILE ]
then
PID=$(cat $PIDFILE)
ps -p $PID > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Process already running as $PID with PID file $PIDFILE"
exit 1
else
## Process not found assume not running
echo "Removing orphaned PID file $PIDFILE"
rm $PIDFILE
fi
fi
nohup python3 run.py 2>&1 >run.py.log </dev/null & echo $! > $PIDFILE
exit 0
;;
stop)
##check if pid exists and matches a running process
if [ -f $PIDFILE ]
then
PID=$(cat $PIDFILE)
ps -p $PID > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Terminating process $PID"
kill $PID
sleep 30
ps -p $PID > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "Force-terminating process $PID"
kill -9 $PID
fi
rm $PIDFILE
exit 0
else
echo "Process $PID not running, deleting $PIDFILE"
rm $PIDFILE
exit 0
fi
else
echo "Unable to find $PIDFILE to terminate process"
exit 2
fi
;;
esac