Perl: process monitoring

Checker:


#!/usr/bin/env perl

use strict;
use IO::File;

use constant PID_FILE  => '/var/run/jobmond.pid';
use constant EXEC_FILE => '/usr/local/bin/jobmond.py';

my $fh = IO::File->new(PID_FILE);
if($fh) {
  my $pid = <$fh>;
  if (!kill(0, $pid)) {
     kill(9, $pid);
     print "Killed old daemon\n";
     exec(EXEC_FILE, '--pidfile', '/var/run/jobmond.pid');
  }
  print "Yes\n";
} else {
 print "Pid file doesn't exists. Start new process.\n";
 exec(EXEC_FILE, '--pidfile', '/var/run/jobmond.pid');
}
exit;

Scroll to top