django fastcgi init.d script for gentoo

參考這一篇文章 Django FastCGI init.d script for Gentoo Linux , 加上一點小修改, 然後將設定值搬到 conf.d 裡面。 用來跑 lighttpd + fastcgi + django。

然後只要在 /var/django 裡面用 django-admin.py startproject mysite 來建立 project 之後, 到設定檔的 DJANGO_SITES 加入 project 即可。

/etc/conf.d/django-fastcgi

DJANGO_SITES="mysite mysite2"  
SITES_PATH="/var/django"  
RUNFILES_PATH="$SITES_PATH/run"  
HOST="127.0.0.1"  
PORT_START=3000  
RUN_AS="www"```

/etc/init.d/django-fastcgi

!/sbin/runscript

Copyright 1999-2009 Gentoo Foundation

Distributed under the terms of the GNU General Public License v2

$Header: $

depend() {

need lighttpd

}

start() { ebegin "Starting django-fastcgi" PORT=${PORTSTART} for SITE in ${DJANGOSITES} do VERBOSENAME="${SITE} ${HOST}:${PORT}" if [ -f ${RUNFILESPATH}/${SITE}.pid ]; then ewarn "${VERBOSENAME} already running (${RUNFILESPATH}/${SITE}.pid)" else start-stop-daemon --start --chuid ${RUNAS} --exec /usr/bin/env -- python ${SITESPATH}/${SITE}/manage.py runfcgi method=threaded host=${HOST} port=${PORT} pidfile=${RUNFILESPATH}/${SITE}.pid chmod 400 ${RUNFILESPATH}/${SITE}.pid einfo "${VERBOSENAME} started" fi let "PORT = ${PORT} + 1" done eend $? }

stop() { ebegin "Stopping django-fastcgi" for SITE in ${DJANGOSITES} do VERBOSENAME=${SITE} start-stop-daemon --stop --pidfile ${RUNFILESPATH}/${SITE}.pid && einfo "${VERBOSENAME} stopped" || ewarn "${VERBOSENAME} not running" if [ -f ${RUNFILESPATH}/${SITE}.pid ]; then rm ${RUNFILESPATH}/${SITE}.pid fi done eend $? }

```

tzangms

Read more posts by this author.

Subscribe to Oceanic / 海海人生

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!