Got the FCGI on lighttpd working better2008-06-01 00:49:02Oh what a quagmire of crud to walk through. All of the Django docs on FCGI and lighttpd are pretty sparse and the examples are not what I would recommend for a production service. So first step was to improve the FCGI tie in for Django. This turned out better then I thought. I had to do a lot of guessing and testing. But now I have it set up so that when the lighttpd service is started and stopped the FCGI processes are also started and stopped. In other words the web service application actually controls its own subprocesses including the FCGI linking to python for the Django service.
I'll have to create a wiki pages on how I configured this place. But to save you time if you want to see my script here it is: -- BEG start-fcgi.sh -- #!/usr/bin/env bash
NOW=`date +%Y-%m-%d_%T`
MY_LOG_DIR=/tmp
[ -n "${OUT_LOG}" ] && MY_LOG_DIR=${OUT_LOG%/*}
[ -n "${DJANGO_LOG_DIR}" ] && MY_LOG_DIR=${DJANGO_LOG_DIR}
[ ! -d $MY_LOG_DIR ] && mkdir -p $MY_LOG_DIR
[ ! -d $MY_LOG_DIR ] && echo "$0 ERROR log dir $MY_LOG_DIR is not a directory" >&2 && exit -1
MY_LOG=${MY_LOG_DIR}/start_fcgi_${NOW}_$$.out
rm -rf $MY_LOG
echo "$0 process $$ started log file = $MY_LOG"
echo "$0 process $$ started" >> ${MY_LOG}
MY_DIR=${0%/*}
cd $MY_DIR
echo "command line: $0 $@" > ${MY_LOG}
echo "----- BEG ENV -----" >> ${MY_LOG}
env >> ${MY_LOG}
echo "----- END ENV -----" >> ${MY_LOG}
PIDFILE="pidfile=${MY_LOG_DIR}/django_fcgi_$$.pid"
[ -n "${DJANGO_PID}" ] && PIDFILE="pidfile=${DJANGO_PID}"
# if socket is not specified the fcgi process handling will negotiate the correct
# socket file via the fcgi API so best to NOT specify it
SOCKET=""
[ -n "${DJANGO_SOCKET}" ] && SOCKET="socket=${DJANGO_SOCKET}"
METHOD="method=prefork"
[ -n "${DJANGO_METHOD}" ] && METHOD="method=${DJANGO_METHOD}"
# stdout and stderr will go to the http server logs if not otherwise specified
OUTLOG=""
[ -n "${OUT_LOG}" ] && OUTLOG="outlog=${OUT_LOG}"
ERRLOG=""
[ -n "${ERROR_LOG}" ] && ERRLOG="errlog=${ERROR_LOG}"
CMD="./manage.py runfcgi $METHOD $SOCKET $PIDFILE $OUTLOG $ERRLOG"
echo "executing : exec ${CMD}" >> ${MY_LOG}
exec ${CMD}
-- END start-fcgi.sh --
You will note that this is controlled via the lighttpd.conf file. Here is the relevant section of mine: -- BEG lighttpd.conf subsection -- ## Special fastcgi handling for each domain under django python
# If the hostname is '*.nodsw.com' or 'nodsw.com' ...
$HTTP["host"] =~ "(^|\.)nodsw.com" {
fastcgi.server += (
"/mysite.fcgi" => (
"main" => (
"socket" => "/tmp/nodsw.socket", # This will get auto-incremented by fcgi
"check-local" => "disable",
"bin-path" => "/django/nodsw.com/start_fcgi.sh",
"bin-environment" => (
"DJANGO_LOG_DIR" => "/django/logs",
#"ERROR_LOG" => "/django/logs/nodsw.django_error.log",
#"OUT_LOG" => "/django/logs/nodsw.django_out.log",
#"DJANGO_PID" => "/django/logs/nodws.django.pid"
#"DJANGO_SOCKET" => "/tmp/nodsw.socket", # don't use this unless you are sure
#"PYTHONPATH" => "/django/greydragon/project"
)
)
)
)
alias.url = (
"/media/" => "/django/nodsw.com/media/",
)
url.rewrite-once = (
"^(/media.*)$" => "$1",
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/.*)$" => "/mysite.fcgi$1",
)
}
-- END lighttpd.conf subsection --
Posted by Leeland 0 Comments |
|
| Comments: |
|---|
Page: 1
Please login to post a reply.

