Services – Automatically restart a Unix job if it goes down?

I have a job that I would like to “daemonize” on Unix: I want it to come up when the computer boots, and I want it to restart if it goes down.

A simple way to do this is to setup a cronjob that runs every 10 or 20 minutes. The cronjob should restart the application if it’s not already running.

How do I write this last part of the script:”If the job is not currently running, then start the job”?

Solution:

If your program runs in the foreground, use Gerrit Pape’s runit. Advantages:

  • Its pretty well bullet proof (based on Dan Berstein’s daemontools).
  • It runs on a wide variety of platforms (portable).
  • It is packaged on Ubuntu and Debian (along w/ above..).
  • It is relatively easy to configure (run script, log script, some symlinks).
๐Ÿ’ 

๐Ÿ”ต Best-selling hard drives, USB flash drives & SSDs everyone's buying.

Fast, reliable, and on sale now. Thousands pick these weekly โ€” don't miss Amazon's lowest storage prices.

โšก Top 10 Bestsellers
๐Ÿ† 4.7โ˜…+ Reviews
๐Ÿ“ฆ Prime Shipping
๐Ÿ‘‰ See today's best-selling Data storage on Amazon.com HDD ยท USB Flash Drives ยท SSD ยท External Drives
๐Ÿ›’
โœ… Updated hourly โ€” Amazon real-time ranking ๐Ÿ”ฅ Limited stock deals ๐Ÿ”— Affiliate
โญ Click to see complete best-selling list โญ
Scroll to Top