#!/usr/bin/perl -w
#

=head1 NAME

Perlbal - Reverse-proxy load balancer and webserver

=head1 DESCRIPTION

For now, see example configuration files in conf/

=head1 AUTHORS

 Brad Fitzpatrick, <brad@danga.com>
 Mark Smith, <marksmith@danga.com>

=head1 SEE ALSO

 http://www.danga.com/perlbal/

=head1 BUGS

Not enough docs.

=head1 LICENSE

Copyright 2004.
You can use and redistribute Perlbal under the same terms as Perl itself.

=cut


use strict;
use warnings;
use lib 'lib';
use Perlbal;

my $opt_daemonize;
my $opt_config;
exit 1 unless
    Getopt::Long::GetOptions(
               'daemon' => \$opt_daemonize,
               'config=s' => \$opt_config,
               );

my $default_config = "/etc/perlbal/perlbal.conf";
$opt_config = $default_config if ! $opt_config && -e $default_config;

# load user config
Perlbal::load_config($opt_config, sub {
    print STDOUT join("\n", map { ref $_ eq 'ARRAY' ? @$_ : $_ } @_) . "\n";
}) if $opt_config;

if ($Perlbal::AIO_MODE eq "none") {
    print STDERR "WARNING:  AIO mode disabled or not available.  \n".
                 "          Perlbal will run slowly under load if you're doing any\n".
                 "          disk operations. (e.g. web_server mode).\n";
}

unless (Perlbal::Socket->WatchedSockets() > 0) {
    die "No services or management port configured.  Nothing to do.  Stopping.\n";
}

if ($opt_daemonize) {
    Perlbal::daemonize();
} else {
    print "Running.\n";
}

Perlbal::run();

# Local Variables:
# mode: perl
# c-basic-indent: 4
# indent-tabs-mode: nil
# End:
