需要用于Python应用程序的init.d脚本

2 python ubuntu init.d

我有一个基于python的应用程序,它像feed聚合器一样工作,需要成为init.d脚本的一部分,这样我就可以用start/stop/restart选项控制执行.另外,我希望将init.d脚本设置为cron作业(我在这里有例子).

我在这里找到了一个样本http://homepage.hispeed.ch/py430/python/daemon

(PS.我不希望脚本用python本身编写).

小智 7

您可以考虑为使用Upstart的操作系统编写Upstart任务.

例:

# Start zeya
#

description     "Start Zeya music server"

start on startup

task
exec python /home/r00t/code-hacking/serve-music/zeya/src/zeya/zeya.py
--path=/home/r00t/Music
Run Code Online (Sandbox Code Playgroud)

将其添加到文件中,例如/ etc/init中的'zeya.conf'

然后你可以使用'initctl'控制作业.例如:

initctl status zeya
initctl stop zeya
Run Code Online (Sandbox Code Playgroud)