1 | package Mojolicious::Command::prefork;
|
---|
2 | use Mojo::Base 'Mojolicious::Command';
|
---|
3 |
|
---|
4 | use Mojo::Server::Prefork;
|
---|
5 | use Mojo::Util 'getopt';
|
---|
6 |
|
---|
7 | has description =>
|
---|
8 | 'Start application with pre-forking HTTP and WebSocket server';
|
---|
9 | has usage => sub { shift->extract_usage };
|
---|
10 |
|
---|
11 | sub run {
|
---|
12 | my ($self, @args) = @_;
|
---|
13 |
|
---|
14 | my $prefork = Mojo::Server::Prefork->new(app => $self->app);
|
---|
15 | getopt \@args,
|
---|
16 | 'a|accepts=i' => sub { $prefork->accepts($_[1]) },
|
---|
17 | 'b|backlog=i' => sub { $prefork->backlog($_[1]) },
|
---|
18 | 'c|clients=i' => sub { $prefork->max_clients($_[1]) },
|
---|
19 | 'G|graceful-timeout=i' => sub { $prefork->graceful_timeout($_[1]) },
|
---|
20 | 'I|heartbeat-interval=i' => sub { $prefork->heartbeat_interval($_[1]) },
|
---|
21 | 'H|heartbeat-timeout=i' => sub { $prefork->heartbeat_timeout($_[1]) },
|
---|
22 | 'i|inactivity-timeout=i' => sub { $prefork->inactivity_timeout($_[1]) },
|
---|
23 | 'l|listen=s' => \my @listen,
|
---|
24 | 'P|pid-file=s' => sub { $prefork->pid_file($_[1]) },
|
---|
25 | 'p|proxy' => sub { $prefork->reverse_proxy(1) },
|
---|
26 | 'r|requests=i' => sub { $prefork->max_requests($_[1]) },
|
---|
27 | 's|spare=i' => sub { $prefork->spare($_[1]) },
|
---|
28 | 'w|workers=i' => sub { $prefork->workers($_[1]) };
|
---|
29 |
|
---|
30 | $prefork->listen(\@listen) if @listen;
|
---|
31 | $prefork->run;
|
---|
32 | }
|
---|
33 |
|
---|
34 | 1;
|
---|
35 |
|
---|
36 | =encoding utf8
|
---|
37 |
|
---|
38 | =head1 NAME
|
---|
39 |
|
---|
40 | Mojolicious::Command::prefork - Pre-fork command
|
---|
41 |
|
---|
42 | =head1 SYNOPSIS
|
---|
43 |
|
---|
44 | Usage: APPLICATION prefork [OPTIONS]
|
---|
45 |
|
---|
46 | ./myapp.pl prefork
|
---|
47 | ./myapp.pl prefork -m production -l http://*:8080
|
---|
48 | ./myapp.pl prefork -l http://127.0.0.1:8080 -l https://[::]:8081
|
---|
49 | ./myapp.pl prefork -l 'https://*:443?cert=./server.crt&key=./server.key'
|
---|
50 | ./myapp.pl prefork -l http+unix://%2Ftmp%2Fmyapp.sock -w 12
|
---|
51 |
|
---|
52 | Options:
|
---|
53 | -a, --accepts <number> Number of connections for workers to
|
---|
54 | accept, defaults to 10000
|
---|
55 | -b, --backlog <size> Listen backlog size, defaults to
|
---|
56 | SOMAXCONN
|
---|
57 | -c, --clients <number> Maximum number of concurrent
|
---|
58 | connections, defaults to 1000
|
---|
59 | -G, --graceful-timeout <seconds> Graceful timeout, defaults to 120.
|
---|
60 | -I, --heartbeat-interval <seconds> Heartbeat interval, defaults to 5
|
---|
61 | -H, --heartbeat-timeout <seconds> Heartbeat timeout, defaults to 30
|
---|
62 | -h, --help Show this summary of available options
|
---|
63 | --home <path> Path to home directory of your
|
---|
64 | application, defaults to the value of
|
---|
65 | MOJO_HOME or auto-detection
|
---|
66 | -i, --inactivity-timeout <seconds> Inactivity timeout, defaults to the
|
---|
67 | value of MOJO_INACTIVITY_TIMEOUT or 15
|
---|
68 | -l, --listen <location> One or more locations you want to
|
---|
69 | listen on, defaults to the value of
|
---|
70 | MOJO_LISTEN or "http://*:3000"
|
---|
71 | -m, --mode <name> Operating mode for your application,
|
---|
72 | defaults to the value of
|
---|
73 | MOJO_MODE/PLACK_ENV or "development"
|
---|
74 | -P, --pid-file <path> Path to process id file, defaults to
|
---|
75 | "prefork.pid" in a temporary directory
|
---|
76 | -p, --proxy Activate reverse proxy support,
|
---|
77 | defaults to the value of
|
---|
78 | MOJO_REVERSE_PROXY
|
---|
79 | -r, --requests <number> Maximum number of requests per
|
---|
80 | keep-alive connection, defaults to 100
|
---|
81 | -s, --spare <number> Temporarily spawn up to this number of
|
---|
82 | additional workers, defaults to 2
|
---|
83 | -w, --workers <number> Number of workers, defaults to 4
|
---|
84 |
|
---|
85 | =head1 DESCRIPTION
|
---|
86 |
|
---|
87 | L<Mojolicious::Command::prefork> starts applications with the
|
---|
88 | L<Mojo::Server::Prefork> backend.
|
---|
89 |
|
---|
90 | This is a core command, that means it is always enabled and its code a good
|
---|
91 | example for learning to build new commands, you're welcome to fork it.
|
---|
92 |
|
---|
93 | See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are
|
---|
94 | available by default.
|
---|
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<https://mojolicious.org>.
|
---|
129 |
|
---|
130 | =cut
|
---|