Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want my python program sample.py to be always up and running. I have read some things and asked people about ways to do this. So far I have following options -

  • Upstart
  • Cron

I am trying things with upstart right now. I have created a sample.conf in $HOME/.init/.

#sample.conf
description "gearmanWorker1"
author "hussain"
pre-start script
  logger "pre-start for sample"
end script

post-start script
  logger "post-start for sample"
end script

script
  logger "just before executing sample.sh"
  exec /usr/bin/python /home/magic/Documents/gearman-python/Worker.py
end script

But when I do sudo initctl start sample / sudo start sample it says -

start: Unknown job: sample

When I do status sample, it says -

sample stop/waiting

which means sample process is not running yet.
I don't know if I am doing this right; I am very new to this. Also I don't think cron will be the best way to achieve what I want. Because I just want to monitor sample in such a way that it will automatically restart after a failure/abort. It should also restart after a reboot.

Also feel free to suggest any other better ways to do this.

share|improve this question
add comment

1 Answer

Put the script in /etc/init or read cookbook section about enabling user jobs: http://upstart.ubuntu.com/cookbook/#id96

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.