| 1 | {{{ |
| 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 | # |
| 21 | # Version: @(#)fastcgi 0.2 13-Jun-2007 jannis AT leidel.info |
| 22 | # |
| 23 | |
| 24 | #### SERVER SPECIFIC CONFIGURATION |
| 25 | |
| 26 | # django project names/directories |
| 27 | DJANGO_SITES="myapp myapp2 myapp3" |
| 28 | |
| 29 | # path to the directory with your django projects |
| 30 | SITES_PATH=/path/to/django/projects |
| 31 | |
| 32 | # path to the directory for socket and pid files |
| 33 | RUNFILES_PATH=$SITES_PATH/run |
| 34 | |
| 35 | # please make sure this is NOT root |
| 36 | # local user prefered, www-data accepted |
| 37 | RUN_AS=www-data |
| 38 | |
| 39 | # maximum requests before fast-cgi process respawns |
| 40 | # (a.k.a. get killed and let live) |
| 41 | MAXREQUESTS=1000 |
| 42 | |
| 43 | #### DO NOT CHANGE ANYTHING AFTER THIS LINE! |
| 44 | set -e |
| 45 | |
| 46 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
| 47 | DESC="FastCGI servers" |
| 48 | NAME=$0 |
| 49 | SCRIPTNAME=/etc/init.d/$NAME |
| 50 | mkdir -p $RUNFILES_PATH |
| 51 | chown -R $RUN_AS:$RUN_AS $RUNFILES_PATH |
| 52 | |
| 53 | # |
| 54 | # Function that starts the daemon/service. |
| 55 | # |
| 56 | d_start() |
| 57 | { |
| 58 | # Starting all Django FastCGI processes |
| 59 | # PORT=$PORT_START |
| 60 | for SITE in $DJANGO_SITES |
| 61 | do |
| 62 | echo -n ", $SITE" |
| 63 | if [ -f $RUNFILES_PATH/$SITE.pid ]; then |
| 64 | echo -n " already running" |
| 65 | else |
| 66 | start-stop-daemon --start --quiet \ |
| 67 | --pidfile $RUNFILES_PATH/$SITE.pid \ |
| 68 | --chuid $RUN_AS --exec /usr/bin/env -- python \ |
| 69 | $SITES_PATH/$SITE/manage.py runfcgi \ |
| 70 | protocol=fcgi method=threaded maxrequests=$MAXREQUESTS \ |
| 71 | socket=$RUNFILES_PATH/$SITE.socket \ |
| 72 | pidfile=$RUNFILES_PATH/$SITE.pid |
| 73 | chmod 400 $RUNFILES_PATH/$SITE.pid |
| 74 | fi |
| 75 | sleep 1 |
| 76 | done |
| 77 | } |
| 78 | |
| 79 | # |
| 80 | # Function that stops the daemon/service. |
| 81 | # |
| 82 | d_stop() { |
| 83 | # Killing all Django FastCGI processes running |
| 84 | for SITE in $DJANGO_SITES |
| 85 | do |
| 86 | echo -n ", $SITE" |
| 87 | start-stop-daemon --stop --quiet --pidfile $RUNFILES_PATH/$SITE.pid \ |
| 88 | || echo -n " not running" |
| 89 | if [ -f $RUNFILES_PATH/$SITE.pid ]; then |
| 90 | rm -f $RUNFILES_PATH/$SITE.pid |
| 91 | fi |
| 92 | sleep 1 |
| 93 | done |
| 94 | } |
| 95 | |
| 96 | ACTION="$1" |
| 97 | case "$ACTION" in |
| 98 | start) |
| 99 | echo -n "Starting $DESC: $NAME" |
| 100 | d_start |
| 101 | echo "." |
| 102 | ;; |
| 103 | |
| 104 | stop) |
| 105 | echo -n "Stopping $DESC: $NAME" |
| 106 | d_stop |
| 107 | echo "." |
| 108 | ;; |
| 109 | |
| 110 | restart|force-reload) |
| 111 | echo -n "Restarting $DESC: $NAME" |
| 112 | d_stop |
| 113 | sleep 2 |
| 114 | d_start |
| 115 | echo "." |
| 116 | ;; |
| 117 | |
| 118 | *) |
| 119 | echo "Usage: $NAME {start|stop|restart|force-reload}" >&2 |
| 120 | exit 3 |
| 121 | ;; |
| 122 | esac |
| 123 | |
| 124 | exit 0 |
| 125 | |
| 126 | }}} |