NAME

App::DistSync::Lock - Lock File Manipulation

VERSION

Version 1.01

SYNOPSIS

use File::Pid;

my $lock = new App::DistSync::Lock(
        file => '/some/file.lock',
        hold => 3600,
        pid  => $$,
    );

if ( my $pid = $lock->running ) {
    die "Already running: $num\n";
}

DESCRIPTION

This module manages a lock file. It will create a lock file, query the process within to discover if it's still running, and remove the lock file. This module based on File::Pid and LockFile::Simple.

new

my $lock = new App::DistSync::Lock;

my $lock = new App::DistSync::Lock(
      file => '/var/run/daemon.pid',
      hold => 3600,
      pid  => $$,
  );

This constructor takes three optional paramters.

file - The name of the lock file to work on. If not specified, a lock file located in current directory will be created that matches MANIFEST.LOCK.

hold - Max amount of seconds before breaking lock (0 for never, default is 3600)

pid - The pid to write to a new lockfile. If not specified, $$ is used when the lock file doesn't exist. When the lock file does exist, the pid inside it is used.

running

my $pid = $lock->running;
die "Service already running: $pid\n" if $pid;

Checks to see if the pricess identified in the lock file is still running. If the process is still running, the pid is returned. Otherwise undef or 0 is returned.

status

my $status = $lock->status;

Returns current status

error

my $error = $lock->error;

Returns current error message

HISTORY

See Changes file

DEPENDENCIES

CTK

TO DO

See TODO file

BUGS

* none noted

SEE ALSO

CTK

AUTHOR

Serż Minus (Sergey Lepenkov) http://www.serzik.com <abalama@cpan.org>

COPYRIGHT

Copyright (C) 1998-2019 D&D Corporation. All Rights Reserved

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See LICENSE file and https://dev.perl.org/licenses/