File Coverage

blib/lib/Mojolicious/Command/prefork.pm
Criterion Covered Total %
statement 19 31 61.2
branch 7 8 87.5
condition n/a
subroutine 5 17 29.4
pod 2 2 100.0
total 33 58 56.9


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