从 virtualenv 中启动 wsgi 应用程序作为 Linux 系统服务
我目前正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的经验,我建议您可以使用 Supervisord 将您的 Web 服务器作为守护程序服务运行。虽然你可以在/etc/init.d中编写一些Linux服务脚本,但是正确地执行它们确实很困难。这是一个 nginx 的 init.d 脚本示例,用于在 Ubuntu 中将其作为服务运行。你不想写一篇,是吗?
要使用 Supervisord 运行依赖于 virtualenv 作为守护进程服务的 python 服务器,这是我在生产环境中使用的配置。
您可以使用 /path/to/virtualenv/bin/python 在命令字段中运行您自己的 python 脚本。并且,要在启动时运行supervisord,您可以在root帐户中像这样编写crontab:
当然,如果您没有低于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.
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:
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.