Question

I'm on CentOS 6.3.

I've written a script in Python for the purpose of an app that I'm making. I want it to run as a process that will restart itself if it fails.

I have a .conf file like so:

start on runlevel [2345]
stop on runlevel [06]
script
    /usr/bin/python /home/myself/myscript.py
end script

I can start it with initctl start myscript but when it fails, it doesn't restart. If I do initctl status myscript it says stop/waiting.

Was it helpful?

Solution

I seem to have solved this.

start on runlevel [2345]
stop on runlevel [06]
respawn
script
    exec /usr/bin/python /home/myself/myscript.py
end script

I added respawn and placed exec before the command. According to this: http://newcome.wordpress.com/2012/02/26/running-programs-as-linux-daemons-using-upstart/ exec is an Upstart specific stanza instead of the normal exec command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top