|
Revision 2891, 1.3 kB
(checked in by tokuhirom, 5 years ago)
|
|
lang/perl/Moxy: import Moxy.
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/usr/bin/perl |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use FindBin; |
|---|
| 5 | use Path::Class; |
|---|
| 6 | use YAML; |
|---|
| 7 | use Getopt::Long; |
|---|
| 8 | use Pod::Usage; |
|---|
| 9 | |
|---|
| 10 | use lib file( $FindBin::RealBin, 'lib' )->stringify; |
|---|
| 11 | use Moxy; |
|---|
| 12 | |
|---|
| 13 | sub stdio_close { |
|---|
| 14 | close(STDIN); |
|---|
| 15 | close(STDOUT); |
|---|
| 16 | close(STDERR); |
|---|
| 17 | |
|---|
| 18 | open(STDIN, "+>/dev/null"); ## no critic. |
|---|
| 19 | open(STDOUT, "+>&STDIN"); ## no critic. |
|---|
| 20 | open(STDERR, "+>&STDIN"); ## no critic. |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | my $conf_file = file( $FindBin::RealBin, 'config.yaml' )->stringify; |
|---|
| 24 | |
|---|
| 25 | Getopt::Long::GetOptions( |
|---|
| 26 | '--man' => \my $man, |
|---|
| 27 | '--daemon' => \my $daemon, |
|---|
| 28 | '--config=s' => \$conf_file, |
|---|
| 29 | ) or pod2usage(2); |
|---|
| 30 | Getopt::Long::Configure("bundling"); |
|---|
| 31 | pod2usage(-verbose => 2) if $man; |
|---|
| 32 | |
|---|
| 33 | my $config = YAML::LoadFile($conf_file); |
|---|
| 34 | $config->{global}->{log} ||= { level => 'debug' }; |
|---|
| 35 | |
|---|
| 36 | sub start { |
|---|
| 37 | my $moxy = Moxy->new($config); |
|---|
| 38 | $moxy->run; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | if ($daemon) { |
|---|
| 42 | if (my $pid = fork) { |
|---|
| 43 | exit 0; |
|---|
| 44 | } elsif (defined $pid) { |
|---|
| 45 | stdio_close(); |
|---|
| 46 | start(); |
|---|
| 47 | } else { |
|---|
| 48 | die "fork failed: $@"; |
|---|
| 49 | } |
|---|
| 50 | } else { |
|---|
| 51 | start(); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | __END__ |
|---|
| 55 | |
|---|
| 56 | =head1 SYNOPSIS |
|---|
| 57 | |
|---|
| 58 | $ moxy.pl |
|---|
| 59 | |
|---|
| 60 | Options: |
|---|
| 61 | --daemon => run as daemon |
|---|
| 62 | --config=s => path to config file(default: config.yaml) |
|---|
| 63 | --man => show this manual |
|---|
| 64 | |
|---|
| 65 | =head1 DESCRIPTION |
|---|
| 66 | |
|---|
| 67 | Proxy server for mobile web service development. |
|---|
| 68 | |
|---|