#!/usr/bin/perl -wT

use strict;
use warnings;

$ENV{PATH} = '/bin'; # untaint

BEGIN {

    unless (eval { require Beekeeper }) {
        # Modules not installed yet
        unshift @INC, ($ENV{'PERL5LIB'} =~ m/([^:]+)/g);
    }
}

our $VERSION = '0.01';

use Beekeeper::WorkerPool;

Beekeeper::WorkerPool->new->run;


__END__

=head1 NAME

bkpr - Manage worker pools

=head1 VERSION

Version 0.01

=head1 SYNOPSIS

  $ bkpr --pool-id MyPool start
  Starting pool of MyApp workers: beekeeper-MyPool.
  
  $ bkpr --pool-id MyPool stop
  Stopping pool of MyApp workers: beekeeper-MyPool.
  
  $ bkpr --help
  Usage: bkpr [options] {start|stop|restart|reload|check}
   --foreground      Run in foreground (do not daemonize)
   --pool-id    str  Worker pool name (mandatory)
   --user       str  Run as specified user
   --group      str  Run as specified group
   --config-dir str  Path to directory containing config files
   --debug           Turn on workers debug flag
   --help            Shows this message

=head1 DESCRIPTION

This command line tool is used to manage worker pools: it start, stop and monitor 
pools of persistent C<Beekeeper::Worker> processes which receive RPC requests from 
message bus.

When started it daemonize itself (unless C<--foreground> option is passed) and
fork all worker processes, then monitor those forked processes and B<immediately>
respawn defunct ones.

Beekeeper applications use config files C<pool.config.json> and C<bus.config.json> to
define how clients, workers and brokers connect to each other. These files are searched
for in ENV C<BEEKEEPER_CONFIG_DIR>, C<~/.config/beekeeper>and then C</etc/beekeeper>.

=head1 SEE ALSO
 
L<Beekeeper::WorkerPool>, L<Beekeeper::Config>.

=head1 AUTHOR

José Micó, C<jose.mico@gmail.com>

=head1 COPYRIGHT AND LICENSE

Copyright 2015 José Micó.

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

This software is distributed in the hope that it will be useful, but it is 
provided “as is” and without any express or implied warranties. For details, 
see the full text of the license in the file LICENSE.

=cut
