Sys::RunAlone::User - make sure only one invocation of a script is active at a time per user


 use Sys::RunAlone::User;
 # code of which there may only be on instance running for user

 use Sys::RunAlone::User silent => 1;
 # be silent if other running instance detected

 use Sys::RunAlone::User retry => 50;
 # retry execution 50 times with wait time of 1 second in between

 use Sys::RunAlone::User retry => '55,60';
 # retry execution 55 times with wait time of 60 seconds in between

 use Sys::RunAlone::User pid_dir => '/tmp';
 # set the directory to store the pid lock files (Default: /tmp)

 use Sys::RunAlone::User pid_file => 'filename.lock';
 # set the filename for the lock file, if this is used for multiple users it is adviseable to use a unique name

 use Sys::RunAlone::User callback => sub { };
 # set a anonymous callback function that will be executed if the script is already running and have reached the retry limit


Provide a simple way to make sure the script from which this module is loaded, is only running once on the server. Optionally allow for retrying execution until the other instance of the script has finished.


This documentation describes version 0.01.


There are no methods.


At INIT Time this module will create a PID lock file in the tmp directory (or where you specified). If one already exists it will check the PID in the file to see if it's running or not, if it is the script will exit with value 1 and execute the callback if one was provided.

If retry was set the script will continue to try and run, if it reaches the end of tries it will exit and execute the callback if one was provided.

There are two forms of the retry value:

 use Sys::RunAlone::User retry => 55;  # retry 55 times, with 1 second intervals

Specify the number of times to retry, with 1 second intervals.

 use Sys::RunAlone::User retry => '55,60'; # retry 55 times, with 60 second intervals

Specify both the number of retries as well as the number of seconds interval between tries.

This is particularly useful for minutely and hourly scripts that run a long and sometimes run into the next period. Instead of then not doing anything for the next period, it will start processing again as soon as it is possible. This makes the chance of catching up so that the period after the next period everything is in sync again.


 Elizabeth Mattijsen for writing the original Sys::RunAlone




 Madison Koenig <pedlar AT cpan DOT org>


Copyright (c) 2012 Madison Koenig All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.