Monday, November 19, 2012

Perl script to remove stale PID file

Here's a script for removing a stale PID file. It is my first real world perl script. This also happens to be my first blog this year, following the renaming of this blog from locait.blogspot.com. I had to create this script when apacheds refused to start due to a stale PID file.

#!/usr/bin/perl
# perl script to remove state pid file
# adapted from example at http://search.cpan.org/~cwest/File-Pid-1.01/lib/File/Pid.pm
# it expects the pid file as the sole argument

use File::Pid;
  if ($#ARGV < 0) {
        die "Expects the path to the pid file but received $#ARGV args";
}
  my $pidfile = File::Pid->new({
    file => "$ARGV[0]",
  });

  if (! $pidfile->running ) {
      $pidfile->remove;
  }

1 comment:

  1. Perls returns -1 when the number of arguements is zero, zero when the arguement is one and so on.

    ReplyDelete