UPWORK/ODESK guru: Tips and Tricks for clients

skype: upwork.link , email: info@upwork.link

Perl: process monitoring

without comments

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;

Written by spectre

December 30th, 2014 at 12:00 pm

Posted in Perl

Leave a Reply

*