[Answered ]-How can I reliably launch multiple DJango FCGI servers at startup?

1👍

  1. Create an init script and assign it to the appropriate runlevel.
  2. You need to implement this in your startup/init script (that you would write in step 1)

Or, use a process manager like supervisord which takes care of all your concerns.

Here is a configuration example for fcgi from supervisord.

[fcgi-program:fcgiprogramname]
command=/usr/bin/example.fcgi
socket=unix:///var/run/supervisor/%(program_name)s.sock
process_name=%(program_name)s_%(process_num)02d
numprocs=5
priority=999
autostart=true
autorestart=unexpected
startsecs=1
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=10
user=chrism
redirect_stderr=true
stdout_logfile=/a/path
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stderr_logfile=/a/path
stderr_logfile_maxbytes=1MB
stderr_logfile_backups
environment=A=1,B=2

1👍

How can I launch a list of sites (stored in a plain text file) automatically on startup?

In general, your OS provides a file where you can hook your commands at startup. For example, arch linux uses rc.local, gentoo either /etc/local.start either /etc/local.d/*.start, debian requires you to make an init script – which is basically a script that takes “start” or “stop” as argument and lives in /etc/init.d or /etc/rc.d depending on the distribution …

You can use some bash code as such.

for site in $(</path/to/text/file); do
    /var/django/server.sh $site start
done

How can I get rid of the .pid file if the process doesn’t exist and attempt to start the server as normal?

if [[ -f $PIDFILE ]]; then # if pidfile exists
    if [[ ! -d /proc/$(<$PIDFILE)/ ]]; then # if it contains a non running proc
        unlink $PIDFILE # delete the pidfile
    fi
fi
👤jpic

Leave a comment