简体   繁体   中英

Need init.d script for Python application

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

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM