| 1 | = Django FastCGI init.d script for Gentoo Linux = |
| 2 | |
| 3 | If you're not using Gentoo Linux and for more information about FastCGI/init.d go back to [wiki:InitdScriptForLinux Django FastCGI init.d script for Linux] |
| 4 | |
| 5 | == The initialisation script == |
| 6 | |
| 7 | This version uses TCP connections. I'm working on a socket-version too. |
| 8 | |
| 9 | {{{ |
| 10 | #!/sbin/runscript |
| 11 | |
| 12 | DJANGO_SITES="stdout stuffit" |
| 13 | SITES_PATH=/var/django/sites |
| 14 | RUNFILES_PATH=/var/django/run |
| 15 | HOST=127.0.0.1 |
| 16 | PORT_START=3000 |
| 17 | |
| 18 | start() { |
| 19 | ebegin "Starting django-fgci" |
| 20 | PORT=$PORT_START |
| 21 | for SITE in $DJANGO_SITES |
| 22 | do |
| 23 | VERBOSE_NAME="$SITE $HOST:$PORT" |
| 24 | if [ -f $RUNFILES_PATH/$SITE.pid ]; then |
| 25 | ewarn "$VERBOSE_NAME already running ($RUNFILES_PATH/$SITE.pid)" |
| 26 | else |
| 27 | start-stop-daemon --start \ |
| 28 | --pidfile $RUNFILES_PATH/$SITE.pid \ |
| 29 | --exec /usr/bin/env -- python \ |
| 30 | $SITES_PATH/$SITE/manage.py runfcgi \ |
| 31 | method=threaded \ |
| 32 | host=$HOST port=$PORT pidfile=$RUNFILES_PATH/$SITE.pid |
| 33 | chmod 400 $RUNFILES_PATH/$SITE.pid |
| 34 | einfo "$VERBOSE_NAME started" |
| 35 | fi |
| 36 | let "PORT = $PORT + 1" |
| 37 | done |
| 38 | eend $? |
| 39 | } |
| 40 | |
| 41 | stop() { |
| 42 | ebegin "Stopping django-fgci" |
| 43 | for SITE in $DJANGO_SITES |
| 44 | do |
| 45 | VERBOSE_NAME="$SITE" |
| 46 | start-stop-daemon --stop \ |
| 47 | --pidfile $RUNFILES_PATH/$SITE.pid \ |
| 48 | && einfo "$VERBOSE_NAME stopped" \ |
| 49 | || ewarn "$VERBOSE_NAME not running" |
| 50 | if [ -f $RUNFILES_PATH/$SITE.pid ]; then |
| 51 | rm $RUNFILES_PATH/$SITE.pid |
| 52 | fi |
| 53 | done |
| 54 | eend $? |
| 55 | } |
| 56 | }}} |