Skip to content

Instantly share code, notes, and snippets.

/systemd.diff Secret

Created July 29, 2016 16:19
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/d9a34d7d41c03886e5a5bb58e4b66dbd to your computer and use it in GitHub Desktop.
Save anonymous/d9a34d7d41c03886e5a5bb58e4b66dbd to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Server/Hypnotoad.pm b/lib/Mojo/Server/Hypnotoad.pm
index 3a0af10..f884c3c 100644
--- a/lib/Mojo/Server/Hypnotoad.pm
+++ b/lib/Mojo/Server/Hypnotoad.pm
@@ -72,7 +72,8 @@ sub run {
$prefork->daemonize if !$ENV{HYPNOTOAD_FOREGROUND} && $ENV{HYPNOTOAD_REV} < 3;
# Start accepting connections
- local $SIG{USR2} = sub { $self->{upgrade} ||= steady_time };
+ local $SIG{USR2}
+ = sub { $prefork->cleanup(0) and ($self->{upgrade} ||= steady_time) };
$prefork->cleanup(1)->run;
}
@@ -107,6 +108,8 @@ sub _manage {
return unless $prefork->healthy == $prefork->workers;
$log->info("Upgrade successful, stopping $ENV{HYPNOTOAD_PID}");
kill 'QUIT', $ENV{HYPNOTOAD_PID};
+ unlink $prefork->pid_file;
+ $prefork->ensure_pid_file;
}
$ENV{HYPNOTOAD_PID} = $$ unless ($ENV{HYPNOTOAD_PID} // '') eq $$;
@@ -121,7 +124,7 @@ sub _manage {
}
# Timeout
- kill 'KILL', $self->{new}
+ $prefork->cleanup(1) and kill 'KILL', $self->{new}
if $self->{upgrade} + $self->upgrade_timeout <= steady_time;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment