bin bash Configuration SITE should be defined in parent script SITE py

 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
#!/bin/bash
# Configuration
# SITE should be defined in parent script
#SITE="pyjob"
DIR="/web/$SITE"
PID_FILE="${PIDFILE:-/var/run/www/$SITE.pid}"
SOCKET_FILE="${SOCKET_FILE:-/var/run/www/$SITE.sock}"
ERRLOG_FILE="${ERRLOG_FILE:-/var/log/www/$SITE-error-fcgi.log}"
WORKERS="${WORKERS:-1}"
THREADS="${THREADS:-1}"
CHMOD="${CHMOD:-777}"
DEFAULT_COMMAND="$DIR/manage.py runsuperfcgi socket=$SOCKET_FILE workers=$WORKERS threads=$THREADS daemonize=true pidfile=$PID_FILE errlog=$ERRLOG_FILE"
COMMAND="${COMMAND:-$DEFAULT_COMMAND}"
NOHUP="${NOHUP:-}"
ACTION=$1
NEED_START="yes"
PROCESS=""
if [ -f $PID_FILE ]; then
pid=$(cat $PID_FILE)
if [ -n "$pid" ]; then
if [ -e /proc/$pid ]; then
PROCESS=$pid;
fi
if [ -n "$PROCESS" ]; then
echo "Found active daemon with pid $pid"
if [ "$ACTION" == "restart" -o "$ACTION" == "stop" ]; then
# Kill all children
for child in $(ps -o pid --ppid $pid --no-headers); do
echo "Killing child process with pid $child"
kill $child
done
# Kill parent process
echo "Killing parent process with pid $pid"
kill $pid
# Wait for parent process termination
for x in $(seq 1 30); do
if [ -e /proc/$pid ]; then
echo "Waiting for process termination: $x"
sleep 0.1
else
break
fi
done
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_FILE ]; then
echo "Deleting old socket $SOCKET_FILE"
rm $SOCKET_FILE
fi
if [ -n "$NOHUP" ]; then
echo "Starting daemon in background with command:"
echo $COMMAND
COMMAND="nohup $COMMAND"
$COMMAND &
echo $! > $PID_FILE
# Wait for socket file
for x in $(seq 1 30); do
if [ -e $SOCKET_FILE ]; then
break
else
echo "Waiting for socket file"
sleep 0.1
fi
done
else
echo "Starting daemon with command:"
echo $COMMAND
$COMMAND
fi
chmod $CHMOD $SOCKET_FILE
fi