Wednesday, 26 September 2018

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"?



Answer



This approach is fast and cheap and not bulletproof:


#!/usr/bin/perl -w
$l = `ps x`;
if (not $l =~ /mzscheme/) {
system('~/utils/src/plt/bin/mzscheme &');
}

I put that script in a cron file.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...