root/lang/perl/Moxy/trunk/moxy.pl @ 4942

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
2use strict;
3use warnings;
4use FindBin;
5use Path::Class;
6use YAML;
7use Getopt::Long;
8use Pod::Usage;
9
10use lib file( $FindBin::RealBin, 'lib' )->stringify;
11use Moxy;
12
13sub 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
23my $conf_file = file( $FindBin::RealBin, 'config.yaml' )->stringify;
24
25Getopt::Long::GetOptions(
26    '--man'           => \my $man,
27    '--daemon'        => \my $daemon,
28    '--config=s'      => \$conf_file,
29) or pod2usage(2);
30Getopt::Long::Configure("bundling");
31pod2usage(-verbose => 2) if $man;
32
33my $config = YAML::LoadFile($conf_file);
34$config->{global}->{log} ||= { level => 'debug' };
35
36sub start {
37    my $moxy = Moxy->new($config);
38    $moxy->run;
39}
40
41if ($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
67Proxy server for mobile web service development.
68
Note: See TracBrowser for help on using the browser.