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
#!/bin/sh
DIR="/path/to/project/dir"
PID="$DIR/fcgi.pid"
SOCKET="/path/to/socket/file"
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
echo "Killing $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
cmd="/usr/bin/env python $DIR/manage.py runfcgi method=threaded socket=$SOCKET pidfile=$PID umask=000"
echo
echo "Starting daemon with command:"
echo $cmd
echo
$cmd
fi