• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

builder/H03-May-2022-148

lib/Server/H03-May-2022-631480

script/H03-May-2022-18048

t/H03-May-2022-1,118915

Build.PLH A D26-Feb-20181.6 KiB7654

ChangesH A D26-Feb-20183.8 KiB11481

LICENSEH A D26-Feb-201817.9 KiB380292

MANIFESTH A D26-Feb-2018670 3838

META.jsonH A D26-Feb-20183 KiB106105

META.ymlH A D26-Feb-20182 KiB6867

README.mdH A D26-Feb-20182.5 KiB5935

cpanfileH A D26-Feb-2018207 108

minil.tomlH A D26-Feb-201843 32

README.md

1# NAME
2
3Server::Starter - a superdaemon for hot-deploying server programs
4
5# SYNOPSIS
6
7    # from command line
8    % start_server --port=80 my_httpd
9
10    # in my_httpd
11    use Server::Starter qw(server_ports);
12
13    my $listen_sock = IO::Socket::INET->new(
14        Proto => 'tcp',
15    );
16    $listen_sock->fdopen((values %{server_ports()})[0], 'w')
17        or die "failed to bind to listening socket:$!";
18
19    while (1) {
20        if (my $conn = $listen_sock->accept) {
21            ....
22        }
23    }
24
25# DESCRIPTION
26
27It is often a pain to write a server program that supports graceful restarts, with no resource leaks.  [Server::Starter](https://metacpan.org/pod/Server::Starter) solves the problem by splitting the task into two.  One is [start\_server](https://metacpan.org/pod/start_server), a script provided as a part of the module, which works as a superdaemon that binds to zero or more TCP ports or unix sockets, and repeatedly spawns the server program that actually handles the necessary tasks (for example, responding to incoming connections).  The spawned server programs under [Server::Starter](https://metacpan.org/pod/Server::Starter) call accept(2) and handle the requests.
28
29To gracefully restart the server program, send SIGHUP to the superdaemon.  The superdaemon spawns a new server program, and if (and only if) it starts up successfully, sends SIGTERM to the old server program.
30
31By using [Server::Starter](https://metacpan.org/pod/Server::Starter) it is much easier to write a hot-deployable server.  Following are the only requirements a server program to be run under [Server::Starter](https://metacpan.org/pod/Server::Starter) should conform to:
32
33- receive file descriptors to listen to through an environment variable
34- perform a graceful shutdown when receiving SIGTERM
35
36A Net::Server personality that can be run under [Server::Starter](https://metacpan.org/pod/Server::Starter) exists under the name [Net::Server::SS::PreFork](https://metacpan.org/pod/Net::Server::SS::PreFork).
37
38# METHODS
39
40- server\_ports
41
42    Returns zero or more file descriptors on which the server program should call accept(2) in a hashref.  Each element of the hashref is: (host:port|port|path\_of\_unix\_socket) => file\_descriptor.
43
44- start\_server
45
46    Starts the superdaemon.  Used by the `start_server` script.
47
48# AUTHOR
49
50Kazuho Oku
51
52# SEE ALSO
53
54[Net::Server::SS::PreFork](https://metacpan.org/pod/Net::Server::SS::PreFork)
55
56# LICENSE
57
58This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
59