When I complete a TurboGears2 application, I got a problem, how to keep my tg2 application always running on Webfaction? You know, there is scheduled downtime of virtul host. Therefore, if you just run “paster serve –daemon production.ini”, once the machine down, your application is down, too. So you have to find a way to keep your tg2 application up. I can use crontab to check tg2 application every 5 minutes, but during the just-start-up 5 minutes, your application is not working, so it is not a good idea. I notice Webfaction use a autostart CGI script for TurboGears1 application. So I decide to use that autostart CGI script to run my tg2 application. You might ask, what is autostart and how it works? Autostart script is a simple script to keep your web application up. It is executed when mod_rewrite of apache can’t connect to your server. By using autostart script, the application runs on-demand! If there are no users browse your application, it’s no need to run your application, that saves your memory usage.
However, the autostart Webfaction provided is for tg1, so I modify it for tg2, here is the modified version of autostart:
Site is starting ...click here"""
else:
print """
Restarting site ...click here"""
os.system(
'source /home/victorlin/webapps/tiange/tg2env/bin/activate;'
'cd /home/victorlin/webapps/tiange/tiange/tiange;'
'paster serve daemon production.ini')
]]>