Nginx+daemontools

Running nginx with daemontools
Hey guys I m trying to figure out how to run nginx and the backends
using
supervise in daemon mode
the idea is to run the fastcgi backends in supervise daemonzied mode so
that
if they get killed due to memory leaks or overload or whatever error
they
can be rebooted by supevise automatically wtihout human intervention
thanks for sharing ideas

Syntax: daemon on | off

Default: on

daemon off;

Do not use the “daemon” and “master_process” directives in a production
mode, these options are mainly used for development only. You can use
daemon off safely in production mode with runit / daemontools
however
you can’t do a graceful upgrade. master_process off should never be
used
in production.

On Wed, 2008-01-30 at 15:55 -0800, [email protected] wrote:

Running nginx with daemontools
Hey guys I m trying to figure out how to run nginx and the backends
using supervise in daemon mode
the idea is to run the fastcgi backends in supervise daemonzied mode
so that if they get killed due to memory leaks or overload or whatever
error they can be rebooted by supevise automatically wtihout human
intervention
thanks for sharing ideas

I think the best idea is to not run Nginx under daemontools. But by
all means run your FCGI processes under it since Nginx won’t
automatically restart them if they die.

Regards,
Cliff

I’m using nginx as a reverse proxy and so I’ve got several sites which
use exactly the same config with the exception of the port. Is there
a way to do something like…

array {10,20,99}

for each i in array {
server {
listen $i;

}
}

Perhaps an odd question, but nginx has all kinds of useful features
I’d never thought of before.

Casey

Thanks cliff so the best practises for python backends is daemontools
supervise?
thanks a lot

http://www.google.com/search?hl=en&client=mozilla&rls=org.mozilla%3Aen-US%3Aunofficial&q=daemontools-nginx&btnG=Search
incidentally what is daemontools-nginx then?

Please share spawn fcgi run file for multiple python backends
it is not working with spawn-fcgi
since spawnfcgi spawns a child
and exits
so supervise keeps trying to spawn childs
continuously

service/run
#!/bin/sh
cd /home/mark/work/code

exec /opt/local/bin/spawn-fcgi -f /home/mark/work/code/code.py -p 9500

/tmp/restart.log 2>&1 &
exec cat /tmp/restart.log &
exec /opt/local/bin/spawn-fcgi -f /home/mark/work/code/code.py -p 9501

/tmp/restart.log 2>&1 &
exec cat /tmp/restart.log &

exec /opt/local/bin/spawn-fcgi -f /home/mark/work/code/code.py -p 9502

/tmp/restart.log 2>&1 &
exec cat /tmp/restart.log &

exec /opt/local/bin/spawn-fcgi -f /home/mark/work/code/code.py -p 9503 >
/tmp/restart.log 2>&1 ^
exec cat /tmp/restart.log &
~

Starting the backends
supervise service

Error
it keeps trying to restart the backends since

afaik, no. but you can easily hack ERB or some other templating system
into your deployment process.

ruby -rerb -e ‘puts ERB.new(IO.read(“nginx.rconf”)).result’ > nginx.conf

then you could do stuff like:

<% [10, 20, 99].each do |port| %>
server {
listen <%= port %>;

}
<% end %>

mucho ugly, but it makes things shorter :slight_smile:

it is not working with spawn-fcgi
since spawnfcgi spawns a child
and exits
so supervise keeps trying to spawn childs
continuously

service/run
#!/bin/sh
cd /home/mark/work/code

exec /opt/local/bin/spawn-fcgi -f /home/mark/work/code/code.py -p 9500

/tmp/restart.log 2>&1 &
exec cat /tmp/restart.log &
exec /opt/local/bin/spawn-fcgi -f /home/mark/work/code/code.py -p 9501

/tmp/restart.log 2>&1 &
exec cat /tmp/restart.log &

exec /opt/local/bin/spawn-fcgi -f /home/mark/work/code/code.py -p 9502

/tmp/restart.log 2>&1 &
exec cat /tmp/restart.log &

exec /opt/local/bin/spawn-fcgi -f /home/mark/work/code/code.py -p 9503 >
/tmp/restart.log 2>&1 ^
exec cat /tmp/restart.log &
~

Starting the backends
supervise service

Error
it keeps trying to restart the backends since

Yeah. Currently doing it with a shell script, but was curious if
there was a “righter” way. Thanks for the help.

Thanks,
Casey

On Wed, Jan 30, 2008 at 06:06:40PM -0600, Casey Rayman wrote:

}
}

Perhaps an odd question, but nginx has all kinds of useful features
I’d never thought of before.

No, nginx has no macro support.

However, if your servers different in port number only, then you can use

server {
listen 10;
listen 20;
listen 99;

}

Hi,

Here is a run template you can use, credits go to Allan Parker from
this mailing-list. I use a same type of file, customize it to your
needs.


#!/bin/sh

CHILDREN=“25”

FCGI_HOST=127.0.0.1
FCGI_USER=php
FCGI_GROUP=php
FCGI_BIN=/usr/bin/php-cgi
FCGI_PORT=1705

test -x $FCGI_BIN || { echo “$FCGI_BIN not installed”;
if [ “$1” = “stop” ]; then exit 0;
else exit 5; fi; }

export SHELL="/bin/bash"
exec /usr/bin/spawn-fcgi -n
-f $FCGI_BIN
-a $FCGI_HOST
-p $FCGI_PORT
-u $FCGI_USER
-g $FCGI_GROUP
-C $CHILDREN

On Wed, Jan 30, 2008 at 06:20:08PM -0800, [email protected]
wrote:

exec /opt/local/bin/spawn-fcgi -f /home/mark/work/code/code.py -p 9500 >
exec /opt/local/bin/spawn-fcgi -f /home/mark/work/code/code.py -p 9503 >
/tmp/restart.log 2>&1 ^
exec cat /tmp/restart.log &

Try removing those cats (leaving only the spawn-fcgi lines) and adding:

wait

to the very end of the script (not tested).

Best regards,
Grzegorz N.

Hey

Is the “spawn-fcgi” the one that is built with Lighttpd? If so, add
the “-n” flag so that it won’t fork to the background. I “spawn-fcgi”
to handle PHP built as a FastCGI application.

Mike

In my case, yes indeed it is the one that comes with Lighttpd.