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

发布于 2024-10-09 18:11:43 字数 168 浏览 0 评论 0原文

我目前正在 virtualenv 中开发一个 Bottle 应用程序。我打算使用 bjoern WSGI 服务器来提供它(但这可能并不重要)。我还打算使用 lighty 或 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澉约 2024-10-16 18:11:43

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

要使用 Supervisord 运行依赖于 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 ;

您可以使用 /path/to/virtualenv/bin/python 在命令字段中运行您自己的 python 脚本。并且,要在启动时运行supervisord,您可以在root帐户中像这样编写crontab:

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

当然,如果您没有低于1024的端口号要打开,您可以在非- 特权帐户。

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?

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 ;

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 

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文