AnyEvent::Watchdog - generic watchdog/program restarter
# MUST be use'd as the very first thing in the main program, # as it clones/forks the program before it returns. use AnyEvent::Watchdog;
This module implements a watchdog that can repeatedly fork the program and thus effectively restart it - as soon as the module is use'd, it will fork the program (if possible) and continue to run it normally in the child, while the parent becomes a supervisor.
The child can then ask the supervisor to restart itself instead of exiting, or ask the supervisor to restart it gracefully or forcefully.
NOTE: This module MUST be used as the first thing in the main program. It will cause weird effects when used from another module, as perl does not expect to be forked inside BEGIN blocks.
BEGIN
Use AnyEvent::Watchdog solely as a convenient on-demand-restarter:
use AnyEvent::Watchdog; # and whenever you want to restart (e.g. to upgrade code): use AnyEvent::Watchdog::Util; AnyEvent::Watchdog::Util::restart;
Use AnyEvent::Watchdog to kill the program and exit when the event loop fails to run for more than two minutes:
use AnyEvent::Watchdog autorestart => 1, heartbeat => 120;
Use AnyEvent::Watchdog to automatically kill (but not restart) the program when it fails to handle events for longer than 5 minutes:
use AnyEvent::Watchdog heartbeat => 300;
This module is controlled via the AnyEvent::Watchdog::Util module:
use AnyEvent::Watchdog::Util; # attempt restart AnyEvent::Watchdog::Util::restart; # check if it is running AnyEvent::Watchdog::Util::enabled or croak "not running under watchdog!";
AnyEvent::Watchdog::Util, AnyEvent.
Marc Lehmann <schmorp@schmorp.de> http://home.schmorp.de/
To install AnyEvent::Watchdog, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::Watchdog
CPAN shell
perl -MCPAN -e shell install AnyEvent::Watchdog
For more information on module installation, please visit the detailed CPAN module installation guide.