File Coverage

blib/lib/Mojolicious/Command/daemon.pm
Criterion Covered Total %
statement 19 24 79.1
branch 7 8 87.5
condition n/a
subroutine 5 10 50.0
pod 2 2 100.0
total 33 44 75.0


line stmt bran cond sub pod time code
1             package Mojolicious::Command::daemon;
2 1     1   9 use Mojo::Base 'Mojolicious::Command';
  1         3  
  1         10  
3              
4 1     1   9 use Mojo::Server::Daemon;
  1         4  
  1         9  
5 1     1   6 use Mojo::Util qw(getopt);
  1         2  
  1         505  
6              
7             has description => 'Start application with HTTP and WebSocket server';
8             has usage => sub { shift->extract_usage };
9              
10             sub build_server {
11 5     5 1 39 my ($self, @args) = @_;
12              
13 5         20 my $daemon = Mojo::Server::Daemon->new(app => $self->app);
14             die $self->usage
15             unless getopt \@args,
16 0     0   0 'b|backlog=i' => sub { $daemon->backlog($_[1]) },
17 0     0   0 'c|clients=i' => sub { $daemon->max_clients($_[1]) },
18 0     0   0 'i|inactivity-timeout=i' => sub { $daemon->inactivity_timeout($_[1]) },
19 0     0   0 'k|keep-alive-timeout=i' => sub { $daemon->keep_alive_timeout($_[1]) },
20             'l|listen=s' => \my @listen,
21             'p|proxy:s' => \my @proxy,
22 5 100   0   64 'r|requests=i' => sub { $daemon->max_requests($_[1]) };
  0         0  
23              
24 4 50       50 $daemon->listen(\@listen) if @listen;
25 4 100       19 $daemon->reverse_proxy(1) if @proxy;
26 4         10 my @trusted = grep {length} @proxy;
  6         16  
27 4 100       23 $daemon->trusted_proxies(\@trusted) if @trusted;
28 4         18 return $daemon;
29             }
30              
31 1     1 1 39 sub run { shift->build_server(@_)->run }
32              
33             1;
34              
35             =encoding utf8
36              
37             =head1 NAME
38              
39             Mojolicious::Command::daemon - Daemon command
40              
41             =head1 SYNOPSIS
42              
43             Usage: APPLICATION daemon [OPTIONS]
44              
45             ./myapp.pl daemon
46             ./myapp.pl daemon -m production -p -l http://*:8080
47             ./myapp.pl daemon -l http://127.0.0.1:8080 -l https://[::]:8081
48             ./myapp.pl daemon -l 'https://*:443?cert=./server.crt&key=./server.key'
49             ./myapp.pl daemon -l http+unix://%2Ftmp%2Fmyapp.sock
50             ./myapp.pl daemon -l http://127.0.0.1:8080 -p 127.0.0.0/8 -p fc00::/7
51              
52             Options:
53             -b, --backlog Listen backlog size, defaults to
54             SOMAXCONN
55             -c, --clients Maximum number of concurrent
56             connections, defaults to 1000
57             -h, --help Show this summary of available options
58             --home Path to home directory of your
59             application, defaults to the value of
60             MOJO_HOME or auto-detection
61             -i, --inactivity-timeout Inactivity timeout, defaults to the
62             value of MOJO_INACTIVITY_TIMEOUT or 30
63             -k, --keep-alive-timeout Keep-alive timeout, defaults to the
64             value of MOJO_KEEP_ALIVE_TIMEOUT or 5
65             -l, --listen One or more locations you want to
66             listen on, defaults to the value of
67             MOJO_LISTEN or "http://*:3000"
68             -m, --mode Operating mode for your application,
69             defaults to the value of
70             MOJO_MODE/PLACK_ENV or "development"
71             -p, --proxy [] Activate reverse proxy support,
72             defaults to the value of
73             MOJO_REVERSE_PROXY, optionally takes
74             one or more trusted proxy addresses or
75             networks
76             -r, --requests Maximum number of requests per
77             keep-alive connection, defaults to 100
78              
79             =head1 DESCRIPTION
80              
81             L starts applications with the L backend.
82              
83             This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
84             you're welcome to fork it.
85              
86             See L for a list of commands that are available by default.
87              
88             =head1 ATTRIBUTES
89              
90             L inherits all attributes from L and implements the following new
91             ones.
92              
93             =head2 description
94              
95             my $description = $daemon->description;
96             $daemon = $daemon->description('Foo');
97              
98             Short description of this command, used for the command list.
99              
100             =head2 usage
101              
102             my $usage = $daemon->usage;
103             $daemon = $daemon->usage('Foo');
104              
105             Usage information for this command, used for the help screen.
106              
107             =head1 METHODS
108              
109             L inherits all methods from L and implements the following new
110             ones.
111              
112             =head2 build_server
113              
114             my $server = $daemon->build_server(@ARGV);
115              
116             Build L instance from command line arguments.
117              
118             =head2 run
119              
120             $daemon->run(@ARGV);
121              
122             Run this command.
123              
124             =head1 SEE ALSO
125              
126             L, L, L.
127              
128             =cut