Skip to content

Instantly share code, notes, and snippets.

/hup.diff Secret

Created January 30, 2015 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e47a78ff4398a5b4fd64 to your computer and use it in GitHub Desktop.
Save anonymous/e47a78ff4398a5b4fd64 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Server/Prefork.pm b/lib/Mojo/Server/Prefork.pm
index 42db1ed..853eb08 100644
--- a/lib/Mojo/Server/Prefork.pm
+++ b/lib/Mojo/Server/Prefork.pm
@@ -80,12 +80,14 @@ sub run {
$self->{poll}->mask($self->{reader}, POLLIN | POLLPRI);
# Clean manager environment
- local $SIG{INT} = local $SIG{TERM} = sub { $self->_term };
local $SIG{CHLD} = sub {
while ((my $pid = waitpid -1, WNOHANG) > 0) {
$self->emit(reap => $pid)->_stopped($pid);
}
};
+ local $SIG{HUP}
+ = sub { $_->{graceful} ||= steady_time for values %{$self->{pool}} };
+ local $SIG{INT} = local $SIG{TERM} = sub { $self->_term };
local $SIG{QUIT} = sub { $self->_term(1) };
local $SIG{TTIN} = sub { $self->workers($self->workers + 1) };
local $SIG{TTOU} = sub {
@@ -189,7 +191,7 @@ sub _spawn {
$loop->recurring($self->heartbeat_interval => $cb);
# Clean worker environment
- $SIG{$_} = 'DEFAULT' for qw(INT TERM CHLD TTIN TTOU);
+ $SIG{$_} = 'DEFAULT' for qw(CHLD HUP INT TERM TTIN TTOU);
$SIG{QUIT} = sub { $loop->max_connections(0) };
delete @$self{qw(poll reader)};
srand;
@@ -287,6 +289,10 @@ See L<Mojolicious::Guides::Cookbook/"DEPLOYMENT"> for more.
The L<Mojo::Server::Prefork> manager process can be controlled at runtime with
the following signals.
+=head2 HUP
+
+Restart all workers gracefully.
+
=head2 INT, TERM
Shut down server immediately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment