Elizabeth Mattijsen > Sys-RunAlone-0.09 > Sys::RunAlone

Download:
Sys-RunAlone-0.09.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View Bugs
Report a bug
Module Version: 0.09   Source  

NAME ^

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

SYNOPSIS ^

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

 use Sys::RunAlone 'silent';
 # be silent if other running instance detected

DESCRIPTION ^

Provide a simple way to make sure the script from which this module is loaded, is only running once on the server.

VERSION ^

This documentation describes version 0.09.

METHODS ^

There are no methods.

THEORY OF OPERATION ^

The functionality of this module depends on the availability of the DATA handle in the script from which this module is called (more specifically: in the "main" namespace).

At INIT time, it is checked whethere there is a DATA handle: if not, it exits with an error message on STDERR and an exit value of 2.

If the DATA handle is available, and it cannot be flocked, it exits with an error message on STDERR and an exit value of 1. The error message will be surpressed when 'silent' was specified in the use statement.

If there is a DATA handle, and it could be flocked, execution continues without any further interference.

OVERRIDING CHECK ^

In some cases, the same script may need to be run simultaneously with another incarnation (but possibly with different parameters). In order to simplify this type of usage, it is possible to specify the environment variable SKIP_SYS_RUNALONE with a true value.

 SKIP_SYS_RUNALONE=1 yourscript.pl

will run the script always.

 SKIP_SYS_RUNALONE=2 yourscript.pl

will actually be verbose about this and say:

 Skipping Sys::RunAlone check for 'yourscript.pl'

REQUIRED MODULES ^

 Fcntl (any)

CAVEATS ^

symlinks

Execution of scripts that are (sym)linked to another script, will all be seen as execution of the same script, even though the error message will only show the specified script name. This could be considered a bug or a feature.

changing a running script

If you change the script while it is running, the script will effectively lose its lock on the file. Causing any subsequent run of the same script to be successful, causing two instances of the same script to run at the same time (which is what you wanted to prevent by using Sys::RunAlone in the first place). Therefore, make sure that no instances of the script are running (and won't be started by cronjobs while making changes) if you really want to be 100% sure that only one instance of the script is running at the same time.

ACKNOWLEDGEMENTS ^

Inspired by Randal Schwartz's mention of using the DATA handle as a semaphore on the London PM mailing list.

SEE ALSO ^

Sys::RunAlways.

AUTHOR ^

 Elizabeth Mattijsen

COPYRIGHT ^

Copyright (c) 2005, 2006, 2008, 2009 Elizabeth Mattijsen <liz@dijkmat.nl>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.