· 9 years ago · Oct 10, 2016, 03:42 PM
1root@SELKS:~# cat /etc/init.d/scirius
2#! /bin/sh
3### BEGIN INIT INFO
4# Provides: FastCGI servers for Django
5# Required-Start: networking
6# Required-Stop: networking
7# Default-Start: 2 3 4 5
8# Default-Stop: S 0 1 6
9# Short-Description: Start FastCGI servers with Django.
10# Description: Django, in order to operate with FastCGI, must be started
11# in a very specific way with manage.py. This must be done
12# for each Django web server that has to run.
13### END INIT INFO
14#
15# Author: Guillermo Fernandez Castellanos
16# <guillermo.fernandez.castellanos AT gmail.com>.
17#
18# Changed: Jannis Leidel
19# <jannis AT leidel.info>
20# Joost Cassee
21# <joost@cassee.net>
22# Sebastian Rahlf
23# <basti AT redtoad.de>
24#
25# Version: @(#)fastcgi 0.5 19-Nov-2009 basti AT redtoad.de
26#
27
28set -e
29
30#### CONFIGURATION (override in /etc/defaul/scirius)
31
32# django project names/directories
33DJANGO_SITES="scirius"
34
35# path to the directory with your django projects
36SITES_PATH=/opt/selks/
37
38# path to the directory conrtaining all site-specific virtualenvs
39# (see http://pypi.python.org/pypi/virtualenv for more information)
40ENVIRONMENT_PATH=$SITES_PATH/environment
41
42# path to the directory for socket and pid files
43RUNFILES_PATH=/var/run/scirius
44
45# please make sure this is NOT root
46# local user prefered, www-data accepted
47RUN_AS=www-data
48
49# maximum requests before fast-cgi process respawns
50# (a.k.a. get killed and let live)
51MAXREQUESTS=1000
52
53#### END CONFIGURATION
54
55# Include defaults if available
56if [ -f /etc/default/scirius ] ; then
57 . /etc/default/scirius
58fi
59
60PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
61DESC="Scirius Django FastCGI servers"
62NAME=$0
63SCRIPTNAME=/etc/init.d/$NAME
64mkdir -p $RUNFILES_PATH
65chown -R $RUN_AS:$RUN_AS $RUNFILES_PATH
66
67# A specific site can be started/stopped by appending its name
68SITE=$2
69if [ -n "$SITE" ]; then
70 DJANGO_SITES=$SITE
71fi
72
73DJANGO_SITES="scirius"
74
75#
76# Function that starts the daemon/service.
77#
78d_start()
79{
80 # Starting all Django FastCGI processes
81 for SITE in $DJANGO_SITES
82 do
83 echo -n " $SITE"
84
85 # find python binary to use
86 if [ -f $ENVIRONMENT_PATH/$SITE/bin/python ]; then
87 PYTHON=$ENVIRONMENT_PATH/$SITE/bin/python
88 else
89 PYTHON=`which python`
90 fi
91
92 if [ -f $RUNFILES_PATH/$SITE.pid ]; then
93 echo -n " already running"
94 else
95 start-stop-daemon --start --quiet \
96 --pidfile $RUNFILES_PATH/$SITE.pid \
97 --chuid $RUN_AS --exec /usr/bin/env -- $PYTHON \
98 $SITES_PATH/$SITE/manage.py runfcgi \
99 protocol=fcgi method=threaded maxrequests=$MAXREQUESTS \
100 host=127.0.0.1 port=8080 \
101 pidfile=$RUNFILES_PATH/$SITE.pid
102 if [ -f $RUNFILES_PATH/$SITE.pid ]; then
103 chmod 400 $RUNFILES_PATH/$SITE.pid
104 fi
105 fi
106 sleep 1
107 done
108}
109
110#
111# Function that stops the daemon/service.
112#
113d_stop() {
114 # Killing all Django FastCGI processes running
115 for SITE in $DJANGO_SITES
116 do
117 echo -n " $SITE"
118 start-stop-daemon --stop --quiet --pidfile $RUNFILES_PATH/$SITE.pid \
119 || echo -n " not running"
120 if [ -f $RUNFILES_PATH/$SITE.pid ]; then
121 rm -f $RUNFILES_PATH/$SITE.pid
122 fi
123 sleep 1
124 done
125}
126
127ACTION="$1"
128case "$ACTION" in
129 start)
130 echo -n "Starting $DESC:"
131 d_start
132 echo "."
133 ;;
134
135 stop)
136 echo -n "Stopping $DESC:"
137 d_stop
138 echo "."
139 ;;
140
141 status)
142 echo "Status of $DESC:"
143 for SITE in $DJANGO_SITES
144 do
145 echo -n " $SITE"
146 if [ -f $RUNFILES_PATH/$SITE.pid ]; then
147 echo " running ($(cat $RUNFILES_PATH/$SITE.pid))"
148 else
149 echo " not running"
150 fi
151 done
152 ;;
153
154 restart|force-reload)
155 echo -n "Restarting $DESC: $NAME"
156 d_stop
157 sleep 2
158 d_start
159 echo "."
160 ;;
161
162 *)
163 echo "Usage: $NAME {start|stop|restart|force-reload|status} [site]" >&2
164 exit 3
165 ;;
166esac
167
168exit 0
169root@SELKS:~#