从virtualenv作为Linux系统服务启动wsgi应用程序 [英] Start a wsgi app from within virtualenv as a Linux system service

查看:120
本文介绍了从virtualenv作为Linux系统服务启动wsgi应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在virtualenv中开发一个Bottle应用程序.我打算使用bjoern WSGI服务器为其提供服务(但这可能没什么大不了的).我还打算为轻量级或nginx反向代理提供服务.无论如何,该应用程序可以在其自己的virtualenv中作为系统服务运行吗?如果是这样,怎么办呢?

I'm currently developing a bottle app within virtualenv. I intend to serve it using bjoern WSGI server (but that probably doesn't matter too much). I also intend to serve the app with a lighty or nginx reverse proxy. Anyhow, can the app be run from within its own virtualenv as a system service? And if so, how would one go about it?

推荐答案

根据我的经验,我建议您可以使用 Supervisord 将Web服务器作为守护程序运行.尽管您可以在/etc/init.d中编写一些Linux服务脚本,但是它们确实很难正确执行.这是 nginx的示例init.d脚本,以在Ubuntu中将其作为服务运行.你不想写一个,是吗?

According to my experience, I suggest that you can use Supervisord to run your web server as daemon service. Although you can write some Linux service scripts in /etc/init.d, but they are really difficult to do it correctly. Here is an example init.d script for nginx to run it as a service in Ubuntu. You don't want to write one, do you?

要运行具有virtualenv作为守护程序的守护程序服务的python服务器,这是我在生产环境中使用的配置.

To run a python server which depends on virtualenv as daemon service with supervisord, here is the configuration I am using 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 ;

您可以使用/path/to/virtualenv/bin/python在命令字段中运行自己的python脚本.并且,要在启动时运行受监管的主机,可以在根帐户中编写如下的crontab:

You can use /path/to/virtualenv/bin/python to run your own python script in the command field. And, to run the supervisord on start-up, you can write crontab like this in your root account:

@reboot /usr/local/bin/supervisord -c /home/root/supervisord.conf 

当然,如果您要打开的端口号小于1024,则可以使用非特权帐户编写此启动crontab.

Of course, if you don't have port numbers lower than 1024 to open, you can write this start-up crontab in a non-privilege account.

这篇关于从virtualenv作为Linux系统服务启动wsgi应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆