Alex White (wu) > Proc-Launcher-0.0.35 > Proc::Launcher::Manager

Download:
Proc-Launcher-0.0.35.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.0.35   Source  

NAME ^

Proc::Launcher::Manager - manage multiple Proc::Launcher objects

VERSION ^

version 0.0.35

SYNOPSIS ^

    use Proc::Launcher::Manager;

    my $shared_config = { x => 1, y => 2 };

    my $monitor = Proc::Launcher::Manager->new( app_name  => 'MyApp' );

    # a couple of different components
    $monitor->register( daemon_name  => 'component1',
                        start_method => sub { MyApp->start_component1( $config ) }
                   );
    $monitor->register( daemon_name  => 'component2',
                        start_method => sub { MyApp->start_component2( $config ) }
                   );

    # using class/method/context rather than a code ref
    $monitor->register( daemon_name  => 'webui',
                        class        => 'MyApp::WebUI',
                        start_method => 'start_webui',
                        context      => $config,
                   );

    # start all registered daemons.  processes that are already
    # running won't be restarted.
    $monitor->start();

    # stop all daemons
    $monitor->stop();
    sleep 1;
    $monitor->force_stop();

    # display all processes stdout/stderr from the log file that's
    # been generated since we started
    $monitor->read_log( sub { print "$_[0]\n" } );

    # get a specific daemon or perform actions on one
    my $webui = $monitor->daemon('webui');
    $monitor->daemon('webui')->start();

    # start the process supervisor.  this will start up an event loop
    # and won't exit until it is killed.  any processes not already
    # running will be started.  all processes will be monitored and
    # automatically restarted if they exit.
    $monitor->supervisor->start();

    # shut down/restart the supervisor
    $monitor->supervisor->stop();
    $monitor->supervisor->force_stop();
    $monitor->supervisor->restart();

DESCRIPTION ^

This library makes it easier to deal with multiple Proc::Launcher processes by providing methods to start and stop all daemons with a single command. Please see the documentation in Proc::Launcher to understand how this these libraries differ from other similar forking and controller modules.

It also provides a supervisor() method which will fork a daemon that will monitor the other daemons at regular intervals and restart any that have stopped. Note that only one supervisor can be running at any given time for each pid_dir.

There is no tracking of inter-service dependencies nor predictable ordering of service startup. Instead, daemons should be designed to wait for needed resources. See Launcher::Cascade if you need to handle dependencies.

METHODS ^

register( %options )

Create a new Proc::Launcher object with the specified options. If the specified daemon already exists, no changes will be made.

daemon( 'daemon_name' )

Return the Proc::Launcher object for a specified daemon.

daemons()

Return a list of Proc::Launcher objects.

daemons_names()

Return a list of the names of all registered daemons.

is_running()

Return a list of the names of daemons that are currently running.

This will begin by calling rm_zombies() on one of daemon objects, sleeping a second, and then calling rm_zombies() again. So far the test cases have always passed when using this strategy, and inconsistently passed with any subset thereof.

While it seems that this is more complicated than shutting down a single process, it's really just trying to be a bit more efficient. When managing a single process, is_running might be called a few times until the process exits. Since we might be managing a lot of daemons, this method is likely to be a bit more efficient and will hopefully only need to be called once (after the daemons have been given necessary time to shut down).

This may be reworked a bit in the future since calling sleep will halt all processes in single-threaded cooperative multitasking frameworks.

start( $data )

Call the start() method on all registered daemons. If the daemon is already running it will not be restarted.

stop()

Call the stop() method on all daemons.

force_stop()

Call the force_stop method on all daemons.

disable()

Call the disable() method on all daemons.

enable()

Call the enable() method on all daemons.

read_log()
tail( $output_callback, $timeout_secs )

Poll all daemons for output for the specified number of seconds. Any output received in that time will be sent to $output_callback. Each line of output will be prefixed with the daemon name.

syntax highlighting: