Need init.d script for Python application

拜拜、爱过 提交于 2019-12-05 04:00:28

问题


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).


回答1:


You could consider writing a Upstart task for operating systems which use Upstart.

Example:

# 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

Add this to a file, say 'zeya.conf' in /etc/init

and then you can control the job using 'initctl'. For eg:

initctl status zeya
initctl stop zeya



回答2:


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.




回答3:


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.




回答4:


I found one sample here http://homepage.hispeed.ch/py430/python/daemon

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.

(PS. I don't want the script to be written in python itself).

The Script is written in shell command language.



来源:https://stackoverflow.com/questions/1984847/need-init-d-script-for-python-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!