Merge pull request #23 from dsteinbrunner/patch-2
[perlbal.git] / perlbal
blobf4fef81c71a5b9c3db8ef63754928ed90e13f80c
1 #!/usr/bin/perl -w
4 =head1 NAME
6 Perlbal - Reverse-proxy load balancer and webserver
8 =head1 DESCRIPTION
10 For now, see example configuration files in conf/ from the CPAN tarball
12 http://search.cpan.org/dist/Perlbal/
14 =head1 AUTHORS
16 Brad Fitzpatrick, <brad@danga.com>
17 Mark Smith, <marksmith@danga.com>
19 =head1 SEE ALSO
21 http://www.danga.com/perlbal/
23 =head1 COPYRIGHT AND LICENSE
25 Copyright 2004, Danga Interactive, Inc.
26 Copyright 2005-2007, Six Apart, Ltd.
28 You can use and redistribute Perlbal under the same terms as Perl itself.
30 =cut
33 use strict;
34 use warnings;
35 use lib 'lib';
36 use Perlbal;
38 my $opt_daemonize;
39 my $opt_config;
40 my $opt_help;
41 my $opt_version;
42 usage(1) unless
43 Getopt::Long::GetOptions(
44 'daemon' => \$opt_daemonize,
45 'config=s' => \$opt_config,
46 'help' => \$opt_help,
47 'version' => \$opt_version,
50 my $default_config = "/etc/perlbal/perlbal.conf";
51 $opt_config = $default_config if ! $opt_config && -e $default_config;
53 usage(0) if $opt_help;
55 sub usage {
56 my $rv = shift;
57 print STDERR <<USAGE;
58 Usage: perlbal [OPTS]
59 --help This usage info
60 --version Print perlbal release version
61 --config=[file] Specify Perlbal config file
62 (default: /etc/perlbal/perlbal.conf)
63 --daemon Daemonize
64 USAGE
66 exit($rv);
69 if ($opt_version) {
70 print STDOUT "Perlbal version $Perlbal::VERSION\n";
71 exit 0;
74 # load user config
75 if ($opt_config && ! Perlbal::load_config($opt_config, sub { print STDOUT "$_[0]\n"; })) {
76 die "Error starting up.\n";
79 # FIXME: warn harder if web_server services are enabled
80 if ($Perlbal::AIO_MODE eq "none") {
81 print STDERR "WARNING: AIO mode disabled or not available. \n".
82 " Perlbal will run slowly under load if you're doing any\n".
83 " disk operations. (e.g. web_server mode).\n".
84 " Install IO::AIO for better performance.\n";
87 unless (Perlbal::Socket->WatchedSockets() > 0) {
88 die "No services or management port configured. Nothing to do. Stopping.\n";
91 if ($opt_daemonize) {
92 Perlbal::daemonize();
93 } else {
94 print "Running.\n";
97 exit 0 if Perlbal::run();
98 exit 1;
100 # Local Variables:
101 # mode: perl
102 # c-basic-indent: 4
103 # indent-tabs-mode: nil
104 # End: