-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcgi
executable file
·82 lines (75 loc) · 1.97 KB
/
fcgi
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
#!/bin/bash
MYAPP=treeio
PIDFILE=/var/run/${MYAPP}_fcgi.pid
SOCKET=/tmp/${MYAPP}.fcgi
# Site settings
SETTINGS=treeio.settings
# Maximum requests for a child to service before expiring
#MAXREQ=100
# Spawning method - prefork or threaded
METHOD=prefork
# Maximum number of children to have idle
MAXSPARE=10
# Minimum number of children to have idle
MINSPARE=5
# Maximum number of children to spawn
MAXCHILDREN=100
cd "`dirname $0`"
function failure () {
STATUS=$?;
echo; echo "Failed $1 (exit code ${STATUS}).";
exit ${STATUS};
}
function start_server () {
python manage.py runfcgi socket=$SOCKET pidfile=$PIDFILE \
${MAXREQ:+maxrequests=$MAXREQ} \
${METHOD:+method=$METHOD} \
${MAXSPARE:+maxspare=$MAXSPARE} \
${MINSPARE:+minspare=$MINSPARE} \
${MAXCHILDREN:+maxchildren=$MAXCHILDREN} \
${DAEMONISE:+damonize=True} \
${SETTINGS:+--settings=$SETTINGS}
echo python manage.py runfcgi socket=$SOCKET pidfile=$PIDFILE \
${MAXREQ:+maxrequests=$MAXREQ} \
${METHOD:+method=$METHOD} \
${MAXSPARE:+maxspare=$MAXSPARE} \
${MINSPARE:+minspare=$MINSPARE} \
${MAXCHILDREN:+maxchildren=$MAXCHILDREN} \
${DAEMONISE:+damonize=True} \
${SETTINGS:+--settings=$SETTINGS}
chmod 777 $SOCKET
}
function stop_server () {
kill `cat $PIDFILE` || failure "stopping fcgi"
rm $PIDFILE
}
DAEMONISE=$2
case "$1" in
start)
echo -n "Starting fcgi: "
[ -e $PIDFILE ] && { echo "PID file exsts."; exit; }
start_server || failure "starting fcgi"
echo "Done."
;;
stop)
echo -n "Stopping fcgi: "
[ -e $PIDFILE ] || { echo "No PID file found."; exit; }
stop_server
echo "Done."
;;
poll)
[ -e $PIDFILE ] && exit;
start_server || failure "starting fcgi"
;;
restart)
echo -n "Restarting fcgi: "
[ -e $PIDFILE ] || { echo -n "No PID file found..."; }
stop_server
start_server || failure "restarting fcgi"
echo "Done."
;;
*)
echo "Usage: $0 {start|stop|restart} [--daemonise]"
;;
esac
exit 0