Run the wsgi application from virtualenv as a Linux system service

I am currently developing a bottle app in virtualenv. I intend to serve it using the bjoern WSGI server (but that probably doesn't matter much). I also intend to serve the application using lighty or nginx reverse proxy. One way or another, is it possible to run the application from your virtual virtual server as a system service? And if so, how would this be done?

+3
source share
1 answer

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 .

+4

Source: https://habr.com/ru/post/1782971/


All Articles