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