Python 应用程序需要 init.d 脚本
我有一个基于 python 的应用程序,它的工作方式类似于 feed 聚合器,并且需要成为 init.d 脚本的一部分,以便我可以使用启动/停止/重新启动选项来控制执行。另外,我希望将 init.d 脚本设置为 cron 作业(我在这里有示例)。
我在这里找到了一个示例 http://homepage.hispeed.ch/py430/python/daemon
(PS。我不希望脚本本身是用Python编写的)。
I have a python based application which works like a feed aggregator and needs to be part of init.d script so that I could control the execution with start/stop/restart options. Also I want the init.d script to be setup as a cron job (I have example here).
I found one sample here http://homepage.hispeed.ch/py430/python/daemon
(PS. I don't want the script to be written in python itself).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以考虑为使用 Upstart 的操作系统编写 Upstart 任务。
示例:
将其添加到文件中,例如 /etc/init 中的“zeya.conf”
,然后您可以使用“initctl”控制作业。例如:
You could consider writing a Upstart task for operating systems which use Upstart.
Example:
Add this to a file, say 'zeya.conf' in /etc/init
and then you can control the job using 'initctl'. For eg:
我最近做了类似的事情,并使用 Supervisord 编写了一些小配置文件。
从初始化脚本(几乎是准系统)中,我只是使用适当的参数调用了supervisor-ctl。
另外,您应该注意,实际功能(例如
start-stop-daemon
)因发行版而异。I did something like this recently and wrote some small config files using Supervisord.
From the init script (pretty much barebones), I simply called supervisor-ctl with the appropriate arguments.
Also, you should note that the actual functions (eg.
start-stop-daemon
) vary from distro to distro.这确实是一个反问题,但我注意到,您提到了 cron,这意味着您的应用程序将定期运行,而不是以所谓的守护进程方式连续运行。
对于定期运行的应用程序来说,使用启动、停止和重新启动等命令有何意义?我的意思是,你的应用程序将每小时运行一次(或其他),为什么需要启动、停止和重新启动?
不管怎样,既然你提到了 ubuntu,我必须说,你链接的脚本不符合 ubuntu 和 debian lenny 的当前 initscripts 标准。您可以在
/etc/init.d/sculpture
中看到正确的模板。重申一下,为什么您需要 initscript 来实现计划任务?
编辑
考虑到评论,即使应用程序崩溃或终止,保持应用程序运行的某种“规范”方法是 inittab。当然,您也可以通过 cron 作业来完成。
A counter-question really, but I've noticed, that you've mentioned cron, meaning, your app is going to be run periodically, as opposed to being run continously, in a so-called daemon fashion.
What is the sense in having commands like start, stop and restart for an application that is run periodically? I mean, your app is going to run once per hour (or something), why the need for start, stop and restart?
Anyway, since you've mentioned ubuntu, I must say, that the script you've linked doesn't comply with the current standard for initscripts neither for ubuntu nor for debian lenny. You can see the correct template in
/etc/init.d/skeleton
To reiterate, why would you need an initscript for a cron job?
EDIT
Taking into consideration the comment, the somewhat "canonical" way to keep the application running even if it crashes or gets terminated is inittab. Of course, you can do it with a cron job as well.
我知道这是一个老问题,但实际上您找到的示例是在 ubuntu 和 debian 中执行此操作(启动/停止/重新启动)的推荐方法。然后你可以执行 cron 作业来查看你的程序是否正在运行。
该脚本是用 shell 命令语言编写的。
I know is an old question but actually the example that you found is the recommended way to do that(start/stop/restart) in ubuntu and debian. And then you could do a cron job to see if your program is running.
The Script is written in shell command language.