Skip to content

Instantly share code, notes, and snippets.

/systemd.diff Secret

Created July 29, 2016 17:59
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/87e6d7bee2be1a4175741307cb97bdb4 to your computer and use it in GitHub Desktop.
Save anonymous/87e6d7bee2be1a4175741307cb97bdb4 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..195d914 100644
--- a/lib/Mojo/Server/Hypnotoad.pm
+++ b/lib/Mojo/Server/Hypnotoad.pm
@@ -56,7 +56,7 @@ sub run {
weaken $self;
$prefork->on(wait => sub { $self->_manage });
$prefork->on(reap => sub { $self->_cleanup(pop) });
- $prefork->on(finish => sub { $self->{finished} = 1 });
+ $prefork->on(finish => sub { $self->_finish });
# Testing
_exit('Everything looks good!') if $ENV{HYPNOTOAD_TEST};
@@ -87,6 +87,16 @@ sub _cleanup {
sub _exit { say shift and exit 0 }
+sub _finish {
+ my $self = shift;
+
+ $self->{finish} = 1;
+ return unless my $new = $self->{new};
+ my $prefork = $self->prefork->cleanup(0);
+ unlink $prefork->pid_file;
+ $prefork->ensure_pid_file($new);
+}
+
sub _hot_deploy {
# Make sure server is running
@@ -121,7 +131,7 @@ sub _manage {
}
# Timeout
- kill 'KILL', $self->{new}
+ $prefork->cleanup(1) and kill 'KILL', $self->{new}
if $self->{upgrade} + $self->upgrade_timeout <= steady_time;
}
}
diff --git a/lib/Mojo/Server/Prefork.pm b/lib/Mojo/Server/Prefork.pm
index 4ccac85..bd4ee7a 100644
--- a/lib/Mojo/Server/Prefork.pm
+++ b/lib/Mojo/Server/Prefork.pm
@@ -39,7 +39,7 @@ sub check_pid {
}
sub ensure_pid_file {
- my $self = shift;
+ my ($self, $pid) = (shift, shift // $$);
# Check if PID file already exists
return if -e (my $file = $self->pid_file);
@@ -50,7 +50,7 @@ sub ensure_pid_file {
unless open my $handle, '>', $file;
$self->app->log->info(qq{Creating process id file "$file"});
chmod 0644, $handle;
- print $handle $$;
+ print $handle $pid;
}
sub healthy {
@@ -433,6 +433,7 @@ not running.
=head2 ensure_pid_file
$prefork->ensure_pid_file;
+ $prefork->ensure_pid_file($pid);
Ensure L</"pid_file"> exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment