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

create the file /root/bin/web2pytest.sh to check if web2py runs and start web2py if it is not running

if
        ! ` netcat -z localhost 8000 `
        then pgrep -flu myusername web2py | cut -d\  -f1 | xargs kill > /dev/null  2>&1
        chown myusername: /var/log/web2py.log
        su myusername -c 'cd /home/myusername/web2py && ./web2py.py -p 8000 -a password 2>&1 >> /var/log/web2py.log'
        sleep 3
        if 
                ! ` netcat -z localhost 8000 `
                then echo "web2py/sysbio could not be started!"
                else echo "web2py/sysbio was restarted"
        fi
fi

now add the following line to crontab to execute the script every 3 minutes

*/3 * * * * /root/bin/web2pytest.sh > /dev/null

thanks to Ivo Maintz, you da best :)

Related slices

Comments (2)

  • Login to post



  • 0
    select 3 years ago
    Our setup is that we have a server running in front (apache or lighttpd) and a web2py server instance in the back. Since we use some libraries that are sometime unstable they also crash the web2py server from time to time. To automatically start the web2py server again we use this cron script. If you would have web2py running with WSGI in e.g. lighttpd the script could also be rewritten to start your lighttpd server on crashes.

  • 0
    virtualdisaster 3 years ago
    Newbie question: is this only needed if you're running the web server that comes with web2py? It is NOT needed if you are running Apache or another web server?

Hosting graciously provided by:
Python Anywhere