On Oct 10, 2010, at 9:45 AM, Michele Alzetta wrote: > Hello, I wonder if someone has created a "normal" initscript for Web2Py. > > For the moment I manage with the following hack, but it is not elegant and I > would prefer something that integrates better with the rest of the system.
You might want to rm -f $PIDFILE at the end of the stop function, or at least in the kill -9 path. I think that init scripts tend to be rather system-specific. There's a Red Hat script in the scripts directory, and maybe some others. > > My hack: > > start.sh ( in web2py directory ): > > ------------------------- > > #!/bin/bash > > exec /usr/bin/python /my/path/to/web2py/web2py.py -a mypassword -i 127.0.0.1 > -p 8000 > > ------------------------ > > In /etc/init.d the following file (copied from a lighttpd startup script): > > ------------------------ > > #!/bin/sh > > PIDFILE=/my/path/to/web2py/httpserver.pid > HTTPD=/my/path/to/web2py/start.sh > > PID=0 > if [ -e $PIDFILE ]; then > PID=`cat $PIDFILE` > if [ "x" == "x$PID" ]; then > PID=0 > fi > fi > > case "$1" in > start) > if [ 0 -ne $PID ]; then > running=`ps --pid $PID | grep $PID |wc -l` > if [ $running ]; then > echo "web2py is already running" > exit 1 > fi > > echo "web2py does not appear to be running, but old PID file > exists. Removing..." > rm $PIDFILE > PID=0 > fi > > echo "Starting Web2Py..." > $HTTPD > /dev/null 2>&1 > ;; > stop) > if [ 0 -eq $PID ]; then > echo "Web2Py was not running" > exit 1 > fi > > echo "Attempting to kill process $PID (Web2Py)" > kill $PID > tries="" > while [ -e $PIDFILE ]; do > if [ "x$tries" == "x.........." ]; then > break > fi > sleep 2 > tries=".$tries" > done > if [ -e $PIDFILE ]; then > echo "Unable to kill Web2Py in 10 attempts. Killing with -9 > flag..." > kill -9 $PID > > ------------------- > > > HTH somebody, but a regular init script would be so much better :) > > Michele