Marc Lehmann


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.


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;

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

   # check if it is running
      or croak "not running under watchdog!";


AnyEvent::Watchdg::Util, AnyEvent.


 Marc Lehmann <>

Hosting generously
sponsored by Bytemark