-
Notifications
You must be signed in to change notification settings - Fork 2
/
daemon.sh
50 lines (45 loc) · 1.13 KB
/
daemon.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
#!/bin/bash
PIDFILE=/tmp/django-fcgi.pid
stop() {
kill `cat -- $PIDFILE`
}
start() {
pid=$(cat $PIDFILE ) 2>&-
if [ "X""$pid" != "X" ] ; then
check=$(ps ax | grep python |grep $pid)
if [ "X""$check" != "X" ]; then
echo "Error: process is already running pid - $pid"
exit 1;
fi
fi
source ../bin/activate && /usr/bin/env python manage.py runfcgi daemonize=true pidfile=$PIDFILE host=127.0.0.1 port=7777
}
restart() {
stop
start
}
status() {
pid=$( cat $PIDFILE ) 2>&-
if [ "X"${pid} = "X" ]; then
echo "Status: $host is down"
exit 0;
fi
check=$(ps aux|awk '{print $2}'| grep $pid)
if [ "X"${check} = "X" ]; then
echo "Status: $host is down"
else
echo "Status: $host is up and running pid $pid"
fi
}
# checking we've got valid number of args
if [ $# != 1 ]; then
echo 'Usage: daemon.sh start|stop|restart'
exit 1
fi
#actual job
case "$1" in
start) start ;;
stop) stop ;;
status) status ;;
restart) restart ;;
esac