summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/p5-Server-Starter/script/start_server
blob: 20dd9fab7e9caec6a5d36c56467668288174ea65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!perl

use strict;
use warnings;

use Getopt::Long;
use Pod::Usage;
use Server::Starter qw(start_server restart_server stop_server);

my %opts = (
    port => [],
    path => [],
);

GetOptions(
    map {
        $_ => do {
            my $name = (split '=', $_, 2)[0];
            $name =~ s/-/_/g;
            $opts{$name} ||= undef;
            ref($opts{$name}) ? $opts{$name} : \$opts{$name};
        },
    } qw(port=s path=s interval=i log-file=s pid-file=s dir=s signal-on-hup=s signal-on-term=s
         backlog=i envdir=s enable-auto-restart=i daemonize auto-restart-interval=i kill-old-delay=i
         status-file=s restart stop help version),
) or exit 1;
pod2usage(
    -exitval => 0,
    -verbose => 1,
) if $opts{help};
if ($opts{version}) {
    print "$Server::Starter::VERSION\n";
    exit 0;
}

if ($opts{restart}) {
    restart_server(%opts);
    exit 0;
}

if ($opts{stop}) {
    stop_server(%opts);
    exit 0;
}

if ($opts{daemonize}) {
    die "Usage: --log-file option must be specified together with --deamonize\n"
        unless defined $opts{log_file};
}

# validate options
die "server program not specified\n"
    unless @ARGV;

start_server(
    %opts,
    exec => \@ARGV,
);

__END__

=head1 NAME

start_server - a superdaemon for hot-deploying server programs

=head1 SYNOPSIS

  start_server [options] -- server-prog server-arg1 server-arg2 ...

  # start Plack using Starlet listening at TCP port 8000
  start_server --port=8000 -- plackup -s Starlet --max-workers=100 index.psgi

=head1 DESCRIPTION

This script is a frontend of L<Server::Starter>.  For more information please refer to the documentation of the module.

=head1 OPTIONS

=head2 --port=(port|host:port|port=fd|host:port=fd)

TCP port to listen to (if omitted, will not bind to any ports)

If host is not specified, then the program will bind to the default address of IPv4 ("0.0.0.0").
Square brackets should be used to specify an IPv6 address (e.g. --port=[::1]:8080)

If fd is specified, then start_server allocates the socket at the given number.

=head2 --path=path

path at where to listen using unix socket (optional)

=head2 --dir=path

working directory, start_server do chdir to before exec (optional)

=head2 --interval=seconds

minimum interval to respawn the server program (default: 1)

=head2 --signal-on-hup=SIGNAL

name of the signal to be sent to the server process when start_server receives a SIGHUP (default: SIGTERM). If you use this option, be sure to also use C<--signal-on-term> below.

=head2 --signal-on-term=SIGNAL

name of the signal to be sent to the server process when start_server receives a SIGTERM (default: SIGTERM)

=head2 --pid-file=filename

if set, writes the process id of the start_server process to the file

=head2 --status-file=filename

if set, writes the status of the server process(es) to the file

=head2 --envdir=ENVDIR

directory that contains environment variables to the server processes.
It is intended for use with C<envdir> in C<daemontools>.
This can be overwritten by environment variable C<ENVDIR>.

=head2 --log-file=file

=head2 --log-file="| cmd args..."

if set, redirects STDOUT and STDERR to given file or command

=head2 --daemonize

deamonizes the server (by doing fork,setsid,fork).  Must be used together with C<--log-file>.

=head2 --enable-auto-restart

enables automatic restart by time.
This can be overwritten by environment variable C<ENABLE_AUTO_RESTART>.

=head2 --auto-restart-interval=seconds

automatic restart interval (default 360). It is used with C<--enable-auto-restart> option.
This can be overwritten by environment variable C<AUTO_RESTART_INTERVAL>.

=head2 --kill-old-delay=seconds

time to suspend to send a signal to the old worker. The default value is 5 when C<--enable-auto-restart> is set, 0 otherwise.
This can be overwritten by environment variable C<KILL_OLD_DELAY>.

=head2 --backlog=size

specifies a listen backlog parameter, whose default is SOMAXCONN (usually 128 on Linux). While SOMAXCONN is enough for most loads, large backlog is required for heavy loads.

=head2 --restart

this is a wrapper command that reads the pid of the start_server process from --pid-file, sends SIGHUP to the process and waits until the server(s) of the older generation(s) die by monitoring the contents of the --status-file

=head2 --stop

this is a wrapper command that reads the pid of the start_server process from --pid-file, sends SIGTERM to the process.

=head2 --help

prints this help

=head2 --version

prints the version number

=head1 AUTHOR

Kazuho Oku

=head1 SEE ALSO

L<Server::Starter>

=head1 LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

=cut