在virtualenv中作为Linux系统服务启动wsgi应用程序

2024-06-26 10:44:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在virtualenv中开发一个瓶子应用程序。我打算使用bjoernwsgi服务器为其提供服务(但这可能并不重要)。我还打算使用lighty或nginx反向代理来为应用程序提供服务。不管怎样,这个应用程序可以作为一个系统服务从它自己的virtualenv中运行吗?如果是这样的话,人们会怎么做呢?在


Tags: 服务器应用程序瓶子代理virtualenv系统nginxlighty
1条回答
网友
1楼 · 发布于 2024-06-26 10:44:21

根据我的经验,我建议您可以使用Supervisord将web服务器作为守护程序服务运行。虽然您可以在/etc/init.d中编写一些Linux服务脚本,但是它们确实很难正确地完成。这里有一个example init.d script for nginx,可以在Ubuntu中将其作为服务运行。你不想写一个吧?在

要运行依赖virtualenv作为守护程序服务的python服务器,下面是我在生产环境中使用的配置。在

[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 ;

您可以在python/field/path中运行python/field/path。而且,要在启动时运行supervisord,可以在根帐户中编写crontab,如下所示:

^{pr2}$

当然,如果您没有低于1024的端口号可以打开,那么可以将这个启动crontab写入一个非特权帐户。在

相关问题 更多 >