需要让我的 python Web 应用程序像守护进程一样进行自我监控(保持活动)
我使用 BaseHTTPServer 编写了 python Web 应用程序。它旨在在本地主机中运行并服务本地主机请求。它旨在托管在主要的 VPS 中。
所以我需要一些可靠的方法来让它保持活力。 Apache(以及它所提供的服务)在停止时可以轻松地重新生成。同样,我可以让 CRON 定期执行“tomcat 启动”,以便在出现故障时启动它。
如何让我的 python 应用程序也活跃起来?我更喜欢能够响应 CRON 命令的东西
I wrote my python web application with BaseHTTPServer. It is intended to run in localhost and serve localhost requests. It is intended to be hosted in a major VPS.
So I need some reliable way to keep it alive. Apache (and what's being served under it) can easily re-spawn when it's stopped. Similarly, I can make CRON do a "tomcat start" periodically, so that it starts up if it went down.
How do I make my python app also alive? I prefer something that responds to commands from CRON
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第一种方法是使用 supervisor。另一种选择是使用 python-daemon 并创建一个系统范围的初始化脚本系统启动时启动。
另外,为了快速破解 - 您可以在可拆卸外壳内运行应用程序,例如 screen 或 < a href="http://tmux.sourceforge.net/" rel="nofollow">tmux。
First approach would be using supervisor. Another option is to use python-daemon and create a system-wide init-script that is started when system boots.
Also, for a quick hack - you can run the app inside the detachable shell like screen or tmux.
您需要的是一个进程监视器,就像前面提到的 supervisord 一样,但是有很多替代方案可供选择,例如 < a href="http://god.rubyforge.org/" rel="nofollow">上帝,监控,<一href="http://upstart.ubuntu.com/" rel="nofollow">Upstart 等等。
我自己只使用过supervisord,它有一个XMLRPC 接口,您可以从其他应用程序(即由CRON 运行的应用程序)使用该接口。
What you need is a process monitor, like the previously mentioned supervisord, but there's a lot of alternatives to choose from, like God, Monit, Upstart Et.c.
I've only used supervisord myself, and it has got an XMLRPC-interface which you could use from your other applications, i.e. something that's run by CRON.
另一种选择可能是类似于此处概述的自我监控脚本(使用
subprocess
)(这可能不是最全面的参考,但应该可以帮助您上路):http://www.tsheffler.com/blog/?p=377
Another option could be something along the lines of the self monitoring scripts (using
subprocess
) outlined here (this might not be the most comprehensive reference, but should get you on your way):http://www.tsheffler.com/blog/?p=377