In my experience, I suggest you use Supervisord to start your web server as a daemon service. Although you can write some Linux service scripts in /etc/init.d, they are really hard to do right. Here is an example init.d script for nginx to run it as a service in Ubuntu. You do not want to write, do you?
To start the python server, which depends on virtualenv as a daemon service with supervisord, here is the configuration I use in a production environment.
[program:web01]
command=/home/victorlin/tg2env/bin/paster serve production.ini ;
process_name=%(program_name)s ;
directory=/home/victorlin/ ;
user=victorlin ;
priority=999 ;
redirect_stderr=true ;
stdout_logfile=/home/victorlin/logs/web01_out.txt ;
stderr_logfile=/home/victorlin/logs/web01_err.txt ;
environment=PYTHON_EGG_CACHE=/home/victorlin/.python-eggs ;
You can use / path / to / virtualenv / bin / python to run your own python script in the command field. And to start the supervisor at startup, you can write crontab like this in your root account:
@reboot /usr/local/bin/supervisord -c /home/root/supervisord.conf
, 1024, crontab .