If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

Before you start you may like some instructions on how to configure nginx to use SCGI and web2py. If so you can go to the following article:

http://www.web2pyslices.com/slice/show/1466/nginx-and-scgi

D.J. Bernstein daemontools http://cr.yp.to/daemontools.html are a set of simple programs that can help you turn a program into a long lasting daemon process.

Don't be fooled by the word simple. daemontools are top of the notch tools as any of Bernstein products:   rock solid by design and resource minimalistic.  They just do what they have to, no more.  Plain *nix philosophy.

This comes with a price, since setting up a long running process the first time seems a daunting task, because of the operations involved.  Don't panic with this instruction you will see how easy it is, after all.

 

On your *nix box there will be a directory where you want to put your services.  Some common choices are:

/service

 

/etc/service

We will refer to the above directory as <service_dir>

On many linux distributions installing daemontools is a matter of installing a package.  Refer to your distribution or go to http://cr.yp.to/daemontools.html for detailed instructions.

 

under your <service_dir> create a directory with another directory inside named log:

 

mkdir -p web2py-scgi/log

Now suppose you have installed your web2py framework under /home/web2py/web2py owned by the user web2py. You simply write the following script that you will name "run"  under <service_dir>/web2py-scgi:

 

#!/bin/bash

WEB2PYDIR=/home/web2py/web2py

cd ${WEB2PYDIR}
exec setuidgid web2py  ./scgihandler.py

Now to log the output from scgihandler you can use the multilog program that comes included with daemontools.  To do so you have to write the following script named "run" again under the directory <service_dir>/web2py-scgi/log:

#!/bin/sh
exec multilog t ./main

If daemontools are properly installed the web2py SCGI server and log will start as soon the "run" scripts are saved.

 

If you need to stop the server, for an upgrade. You can do so by simply doing:

 

svc -d <service_dir>/web2py-scgi

 

To start the service:

 

svc -u <service_dir>/web2py-scgi
 

To restart:

 

 

svc -t <service_dir>/web2py-scgi
 
To check status:
svstat  <service_dir>/web2py-scgi
 
If for any reason the service is killed the daemontools will restart it properly without creating process duplicates.
 
There is still one thing that can be done this way since in SCGI mode web2py cron does not start.  We have to start a process that cleans the old sessions from the disk.  Easily accomplished by creating a new subdirectory under <service_dir> containing a "run" script like the following:
 
#!/bin/bash

WEB2PYDIR=/home/web2py/web2py

cd ${WEB2PYDIR}
exec setuidgid web2py  ./web2py.py -M -S <your_application_name_here>  -R scripts/sessions2trash.py 

daemontools will take care of keeping your processes up and running.

 

 

Related slices

Comments (0)


Hosting graciously provided by:
Python Anywhere