Mojolicious
view release on metacpan or search on metacpan
lib/Mojo/Server/Hypnotoad.pm view on Meta::CPAN
# Upgrade
if ($self->{upgrade} && !$self->{finished}) {
# Fresh start
my $ut = $self->upgrade_timeout;
unless ($self->{new}) {
$log->info("Starting zero downtime software upgrade ($ut seconds)");
die "Can't fork: $!" unless defined(my $pid = $self->{new} = fork);
exec $^X, $ENV{HYPNOTOAD_EXE} or die "Can't exec: $!" unless $pid;
}
# Timeout
kill 'KILL', $self->{new} if $self->{upgrade} + $ut <= steady_time;
}
}
sub _stop {
_exit('Hypnotoad server not running.') unless my $pid = shift->prefork->check_pid;
kill 'QUIT', $pid;
_exit("Stopping Hypnotoad server $pid gracefully.");
}
1;
=encoding utf8
=head1 NAME
Mojo::Server::Hypnotoad - A production web serv...ALL GLORY TO THE HYPNOTOAD!
=head1 SYNOPSIS
use Mojo::Server::Hypnotoad;
my $hypnotoad = Mojo::Server::Hypnotoad->new;
$hypnotoad->run('/home/sri/myapp.pl');
=head1 DESCRIPTION
L<Mojo::Server::Hypnotoad> is a full featured, UNIX optimized, pre-forking non-blocking I/O HTTP and WebSocket server,
built around the very well tested and reliable L<Mojo::Server::Prefork>, with IPv6, TLS, SNI, UNIX domain socket, Comet
(long polling), keep-alive, multiple event loop and hot deployment support that just works. Note that the server uses
signals for process management, so you should avoid modifying signal handlers in your applications.
To start applications with it you can use the L<hypnotoad> script, which listens on port C<8080>, automatically
daemonizes the server process and defaults to C<production> mode for L<Mojolicious> and L<Mojolicious::Lite>
applications.
$ hypnotoad ./myapp.pl
You can run the same command again for automatic hot deployment.
$ hypnotoad ./myapp.pl
Starting hot deployment for Hypnotoad server 31841.
This second invocation will load the application again, detect the process id file with it, and send a L</"USR2">
signal to the already running server.
For better scalability (epoll, kqueue) and to provide non-blocking name resolution, SOCKS5 as well as TLS support, the
optional modules L<EV> (4.32+), L<Net::DNS::Native> (0.15+), L<IO::Socket::Socks> (0.64+) and L<IO::Socket::SSL>
(2.009+) will be used automatically if possible. Individual features can also be disabled with the C<MOJO_NO_NNR>,
C<MOJO_NO_SOCKS> and C<MOJO_NO_TLS> environment variables.
See L<Mojolicious::Guides::Cookbook/"DEPLOYMENT"> for more.
=head1 MANAGER SIGNALS
The L<Mojo::Server::Hypnotoad> manager process can be controlled at runtime with the following signals.
=head2 INT, TERM
Shut down server immediately.
=head2 QUIT
Shut down server gracefully.
=head2 TTIN
Increase worker pool by one.
=head2 TTOU
Decrease worker pool by one.
=head2 USR2
Attempt zero downtime software upgrade (hot deployment) without losing any incoming connections.
Manager (old)
|- Worker [1]
|- Worker [2]
|- Worker [3]
|- Worker [4]
+- Manager (new)
|- Worker [1]
|- Worker [2]
|- Worker [3]
+- Worker [4]
The new manager will automatically send a L</"QUIT"> signal to the old manager and take over serving requests after
starting up successfully.
=head1 WORKER SIGNALS
L<Mojo::Server::Hypnotoad> worker processes can be controlled at runtime with the following signals.
=head2 QUIT
Stop worker gracefully.
=head1 SETTINGS
L<Mojo::Server::Hypnotoad> can be configured with the following settings, see
L<Mojolicious::Guides::Cookbook/"Hypnotoad"> for examples.
=head2 accepts
accepts => 100
( run in 1.114 second using v1.01-cache-2.11-cpan-39bf76dae61 )