add files
|
1 |
package Mojolicious::Command::prefork; |
2 |
use Mojo::Base 'Mojolicious::Command'; |
|
3 | ||
4 |
use Getopt::Long qw(GetOptionsFromArray :config no_auto_abbrev no_ignore_case); |
|
5 |
use Mojo::Server::Prefork; |
|
6 | ||
7 |
has description => |
|
8 |
"Start application with preforking HTTP and WebSocket server.\n"; |
|
9 |
has usage => <<EOF; |
|
10 |
usage: $0 prefork [OPTIONS] |
|
11 | ||
12 |
These options are available: |
|
13 |
-A, --accepts <number> Number of connections for workers to |
|
14 |
accept, defaults to 1000. |
|
15 |
-a, --accept-interval <seconds> Accept interval, defaults to 0.025. |
|
16 |
-b, --backlog <size> Listen backlog size, defaults to |
|
17 |
SOMAXCONN. |
|
18 |
-c, --clients <number> Maximum number of concurrent clients, |
|
19 |
defaults to 1000. |
|
20 |
-G, --graceful-timeout <seconds> Graceful timeout, defaults to 20. |
|
21 |
-g, --group <name> Group name for process. |
|
22 |
--heartbeat-interval <seconds> Heartbeat interval, defaults to 5. |
|
23 |
-H, --heartbeat-timeout <seconds> Heartbeat timeout, defaults to 20. |
|
24 |
-i, --inactivity <seconds> Inactivity timeout, defaults to the |
|
25 |
value of MOJO_INACTIVITY_TIMEOUT or 15. |
|
26 |
--lock-file <path> Path to lock file, defaults to a random |
|
27 |
file. |
|
28 |
-L, --lock-timeout <seconds> Lock timeout, defaults to 1. |
|
29 |
-l, --listen <location> One or more locations you want to |
|
30 |
listen on, defaults to the value of |
|
31 |
MOJO_LISTEN or "http://*:3000". |
|
32 |
--multi-accept <number> Number of connection to accept at once, |
|
33 |
defaults to 50. |
|
34 |
-P, --pid-file <path> Path to process id file, defaults to a |
|
35 |
random file. |
|
36 |
-p, --proxy Activate reverse proxy support, |
|
37 |
defaults to the value of |
|
38 |
MOJO_REVERSE_PROXY. |
|
39 |
-r, --requests <number> Maximum number of requests per |
|
40 |
keep-alive connection, defaults to 25. |
|
41 |
-u, --user <name> Username for process. |
|
42 |
-w, --workers <number> Number of workers, defaults to 4. |
|
43 |
EOF |
|
44 | ||
45 |
sub run { |
|
46 |
my ($self, @args) = @_; |
|
47 | ||
48 |
my $prefork = Mojo::Server::Prefork->new(app => $self->app); |
|
49 |
GetOptionsFromArray \@args, |
|
50 |
'A|accepts=i' => sub { $prefork->accepts($_[1]) }, |
|
51 |
'a|accept-interval=f' => sub { $prefork->accept_interval($_[1]) }, |
|
52 |
'b|backlog=i' => sub { $prefork->backlog($_[1]) }, |
|
53 |
'c|clients=i' => sub { $prefork->max_clients($_[1]) }, |
|
54 |
'G|graceful-timeout=i' => sub { $prefork->graceful_timeout($_[1]) }, |
|
55 |
'g|group=s' => sub { $prefork->group($_[1]) }, |
|
56 |
'heartbeat-interval=i' => sub { $prefork->heartbeat_interval($_[1]) }, |
|
57 |
'H|heartbeat-timeout=i' => sub { $prefork->heartbeat_timeout($_[1]) }, |
|
58 |
'i|inactivity=i' => sub { $prefork->inactivity_timeout($_[1]) }, |
|
59 |
'lock-file=s' => sub { $prefork->lock_file($_[1]) }, |
|
60 |
'L|lock-timeout=f' => sub { $prefork->lock_timeout($_[1]) }, |
|
61 |
'l|listen=s' => \my @listen, |
|
62 |
'multi-accept=i' => sub { $prefork->multi_accept($_[1]) }, |
|
63 |
'P|pid-file=s' => sub { $prefork->pid_file($_[1]) }, |
|
64 |
'p|proxy' => sub { $ENV{MOJO_REVERSE_PROXY} = 1 }, |
|
65 |
'r|requests=i' => sub { $prefork->max_requests($_[1]) }, |
|
66 |
'u|user=s' => sub { $prefork->user($_[1]) }, |
|
67 |
'w|workers=i' => sub { $prefork->workers($_[1]) }; |
|
68 | ||
69 |
$prefork->listen(\@listen) if @listen; |
|
70 |
$prefork->run; |
|
71 |
} |
|
72 | ||
73 |
1; |
|
74 | ||
75 |
=encoding utf8 |
|
76 | ||
77 |
=head1 NAME |
|
78 | ||
79 |
Mojolicious::Command::prefork - Prefork command |
|
80 | ||
81 |
=head1 SYNOPSIS |
|
82 | ||
83 |
use Mojolicious::Command::prefork; |
|
84 | ||
85 |
my $prefork = Mojolicious::Command::prefork->new; |
|
86 |
$prefork->run(@ARGV); |
|
87 | ||
88 |
=head1 DESCRIPTION |
|
89 | ||
90 |
L<Mojolicious::Command::prefork> starts applications with |
|
91 |
L<Mojo::Server::Prefork> backend. |
|
92 | ||
93 |
This is a core command, that means it is always enabled and its code a good |
|
94 |
example for learning to build new commands, you're welcome to fork it. |
|
95 | ||
96 |
=head1 ATTRIBUTES |
|
97 | ||
98 |
L<Mojolicious::Command::prefork> inherits all attributes from |
|
99 |
L<Mojolicious::Command> and implements the following new ones. |
|
100 | ||
101 |
=head2 description |
|
102 | ||
103 |
my $description = $prefork->description; |
|
104 |
$prefork = $prefork->description('Foo!'); |
|
105 | ||
106 |
Short description of this command, used for the command list. |
|
107 | ||
108 |
=head2 usage |
|
109 | ||
110 |
my $usage = $prefork->usage; |
|
111 |
$prefork = $prefork->usage('Foo!'); |
|
112 | ||
113 |
Usage information for this command, used for the help screen. |
|
114 | ||
115 |
=head1 METHODS |
|
116 | ||
117 |
L<Mojolicious::Command::prefork> inherits all methods from |
|
118 |
L<Mojolicious::Command> and implements the following new ones. |
|
119 | ||
120 |
=head2 run |
|
121 | ||
122 |
$prefork->run(@ARGV); |
|
123 | ||
124 |
Run this command. |
|
125 | ||
126 |
=head1 SEE ALSO |
|
127 | ||
128 |
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>. |
|
129 | ||
130 |
=cut |