/
automation-daemon
executable file
·69 lines (62 loc) · 1.06 KB
/
automation-daemon
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
#!/bin/bash -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cmd="uwsgi --plugin python --http-socket 0.0.0.0:8798 --wsgi-file tvflask.py --callable app"
pid_file="$DIR/pid"
log_file="$DIR/log"
get_pid() {
cat "$pid_file"
}
is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting"
cd "$DIR"
$cmd >> "$log_file" 2>&1 &
echo $! > "$pid_file"
fi
if ! is_running; then
echo "Unable to start, see $log_file"
exit 1
fi
;;
stop)
if is_running; then
echo "Stopping"
kill `get_pid`
for i in {1..10}
do
if ! is_running; then
break
fi
done
if is_running; then
echo "Not stopped"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
restart)
"$0" stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac