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