bin bash SITE pyjob DIR web SITE PID var run www SITE pid SOCKET tmp S

 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
#!/bin/bash
SITE="pyjob"
DIR="/web/$SITE"
PID="/var/run/www/$SITE.pid"
SOCKET="/tmp/$SITE.sock"
ERRLOG="/var/log/www/$SITE-error-fcgi.log"
WORKERS="1"
THREADS="1"
CHMOD="777"
ACTION=$1
NEED_START="yes"
PROCESS=""
if [ -f $PID ]; then
pid=$(cat $PID)
if [ -n "$pid" ]; then
PROCESS=$(ps -p $pid --no-headers)
if [ -n "$PROCESS" ]; then
echo "Found active daemon with pid $pid"
if [ "$ACTION" == "restart" -o "$ACTION" == "stop" ]; then
for child in $(ps -o pid --ppid $pid --no-headers); do
echo "Killing child process with pid $child"
kill $child
done
echo "Killing parent process with pid $pid"
kill $pid
else
NEED_START="no"
fi
fi
fi
fi
if [ -z "$PROCESS" ]; then
echo "No active daemon"
fi
if [ "$ACTION" == "stop" ]; then
NEED_START="no"
fi
if [ "$NEED_START" == "yes" ]; then
if [ -e $SOCKET ]; then
echo "Deleting old socket $SOCKET"
rm $SOCKET
fi
cmd="$DIR/manage.py runsuperfcgi socket=$SOCKET workers=$WORKERS threads=$THREADS daemonize=true pidfile=$PID errlog=$ERRLOG"
echo
echo "Starting daemon with command:"
echo $cmd
echo
$cmd
chmod $CHMOD $SOCKET
fi