minimalistic Supervisor
Perl
Latest commit 89a4ad6 Jul 24, 2014 @kazeburo Checking in changes prior to tagging of version 0.35.
Changelog diff is:

diff --git a/Changes b/Changes
index 2b8a04c..cf15099 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,10 @@ Revision history for Perl extension Proclet

 {{$NEXT}}

+0.35 2014-07-24T05:31:01Z
+
+       - add opt to disable exec message
+
 0.34 2014-04-10T15:33:21Z

        - support cron like job in Declare (EXPERIMENTAL)
Permalink
Failed to load latest commit information.
bin accept space before # Jun 20, 2013
eg
lib Checking in changes prior to tagging of version 0.35. Jul 24, 2014
t add exec_notice opt to disable exec message Jul 24, 2014
.gitignore
.travis.yml
Build.PL add exec_notice opt to disable exec message Jul 24, 2014
Changes
LICENSE
META.json
README.md
cpanfile requires String::ShellQuote Mar 12, 2014
minil.toml add travis, enable copy dotfiles Jun 18, 2013

README.md

NAME

Proclet - minimalistic Supervisor

SYNOPSIS

use Proclet;

my $proclet = Proclet->new(
    color => 1
);

# add service
$proclet->service(
    code => sub {
        my $job = $jobqueue->grab;
        work($job);
    },
    worker => 2,
    tag => 'worker'
);

$proclet->service(
    code => sub {
        my $loader = Plack::Loader->load(
            'Starlet',
            port => $port,
            host => $host || 0,
            max_workers => 4,
        );
        $loader->run($app);
    },
    tag => 'web'
);

$proclet->service(
    code => sub {
        exec('/usr/bin/memcached','-p','11211');
    },
);

$proclet->service(
    code => sub {
        scheduled_work();
    },
    tag => 'cron',
    every => '0 12 * * *', #everyday at 12:00am
);


$proclet->run;

DESCRIPTION

Proclet is minimalistic Supervisor, fork and manage many services from one perl script.

LOG

Logs from services are Displayed with timestamp and tag.

12:23:16 memcached.1 | <6 server listening (udp)
12:23:16 memcached.1 | <7 send buffer was 9216, now 3728270
12:23:16 memcached.1 | <7 server listening (udp)
12:23:16 web.1       | 2012/08/31-12:23:16 Starman::Server (type Net::Server::PreFork) starting! pid(51516)
12:23:16 web.1       | Resolved [*]:5432 to [0.0.0.0]:5432, IPv4
12:23:16 web.1       | Binding to TCP port 5432 on host 0.0.0.0 with IPv4 
12:23:16 web.1       | Setting gid to "20 20 20 401 204 100 98 81 80 79 61 12 402"

METHOD

  • new

    Create instance of Proclet.

    Attributes are as follows:

    • spawn_interval: Int

      interval in seconds between spawning services unless a service exits abnormally (default: 0)

    • err_respawn_interval: Int

      number of seconds to deter spawning of services after a service exits abnormally (default: 1)

    • color: Bool

      colored log (default: 0)

    • logger: CodeRef

      my $logger = File::RotateLogs->new(...)
      my $proclet = Proclet->new(
          logger => sub { $logger->print(@_) }
      );
      

      Sets a callback to print stdout/stderr. uses warn by default.

    • enable_log_worker: Bool

      enable worker for format logs. (default: 1) If disabled this option, cannot use logger opt too.

    • exec_notice: Bool

      enable start and exec notice message like

      16:38:12 worker.1 | Start callback: worker
      

      (default: 1)

  • service

    Add services to Proclet.

    Attributes are as follows:

    • code: CodeRef|ArrayRef|Str

      Code reference or commands of services.

      CodeRef

      $proclet->service(
        code => sub {
            MyWorker->run();
        }
      );
      

      ArrayRef

      $proclet->service(
        code => ['plackup','-a','app.psgi'],
      );
      

      Str

      $proclet->service(
        code => '/usr/bin/memcached'
      );
      
    • worker: Int

      Number of children to fork, default is "1"

    • tag: Str

      Keyword for log. optional

    • every: Str

      Crontab like format. optional

      If every option exists, Proclet execute the job as cron(8)

      $proclet->service(
          code => sub {
              scheduled_work();
          },
          tag => 'cron',
          every => '0 12 * * *', #everyday at 12:00am
      );
      
  • run

    run services. Proclet does start services by defined order

AUTHOR

Masahiro Nagano

SEE ALSO

Proc::Launcher::Manager, related module Parallel::Prefork, Proclet used internally

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.