Need init.d script for Python application

2019-04-01 23:10发布

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

4条回答
我想做一个坏孩纸
2楼-- · 2019-04-01 23:42

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-04-01 23:42

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.

查看更多
可以哭但决不认输i
4楼-- · 2019-04-01 23:50

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.

查看更多
我想做一个坏孩纸
5楼-- · 2019-04-02 00:03

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
查看更多
登录 后发表回答