forked from kazuho/p5-Server-Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_server
executable file
·120 lines (77 loc) · 2.62 KB
/
start_server
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
#! /usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use Server::Starter qw(start_server restart_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 signal-on-hup=s signal-on-term=s
status-file=s restart 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;
}
# 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)
TCP port to listen to (if omitted, will not bind to any ports)
=head2 --path=path
path at where to listen using unix socket (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 --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 --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