#!/usr/bin/env perl
use strict;
use warnings;
use Pod::Usage;
use Getopt::Long qw( :config pass_through );
GetOptions(\my %opt, qw( config:s verbose help ));
pod2usage(0) if $opt{help};
$opt{config} ||= '/etc/perlbal/perlbal.conf';
## fetch ports from conf file
my @ports;
{
open my $fh, '<', $opt{config}
or die "can't open $opt{config}: $!\n";
my $conf = do { local $/; <$fh> };
close $fh;
$conf =~ s{^\s*listen\s*=\s*((?:.*:)?\d+)}{push(@ports, $1) && ''}iemg;
die "no ports found in $opt{config}\n"
unless @ports;
}
## build command options
my @cmd_opts;
for my $port (@ports) {
push @cmd_opts, '--port', $port;
}
push @cmd_opts, '--interval', 5;
push @cmd_opts, @ARGV if @ARGV;
## run
if ($opt{verbose}) {
print "listening: " . join(', ', @ports) . "\n";
}
exec 'start_server', @cmd_opts, '--', 'perlbal', '-c', $opt{config};
__END__
=pod
=head1 NAME
start_perlbal - run perlbal via start_server command
=head1 SYNOPSIS
$ start_perlbal [options]
=head1 DESCRIPTION
start_perlbal is a warpper script of perlbal to run via start_server.
=head1 OPTIONS
=over 4
=item B<-c|--config E<lt>/path/to/perlbal.confE<gt>>
path of perlbal config. (default: /etc/perlbal/perlbal.conf)
=item B<-v|--verbose>
print verbose message.
=item B<-h|--help>
print this document.
=back
And all of pases through other options to start_server, so the most options of L<start_server> such as "--pid-file" or "--interval" works fine too.
=cut