Skip to content

Commit

Permalink
moved PID file cleanup to hot deploy check (fixes #383)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 15, 2012
1 parent fb3d704 commit 4fa57db
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Server.pm
Expand Up @@ -28,7 +28,7 @@ sub build_tx { shift->app->build_tx }
sub load_app {
my ($self, $path) = @_;

# Clean environment (and reset FindBin)
# Clean environment (reset FindBin)
{
local $0 = $path;
FindBin->again;
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -84,7 +84,6 @@ sub run {

# Clean manager environment
my $c = $self->{config};
unlink $c->{pid_file} if $ENV{HYPNOTOAD_REV} < 3 && -w $c->{pid_file};
$SIG{INT} = $SIG{TERM} = sub { $self->{finished} = 1 };
$SIG{CHLD} = sub {
while ((my $pid = waitpid -1, WNOHANG) > 0) { $self->_reap($pid) }
Expand Down Expand Up @@ -148,9 +147,10 @@ sub _heartbeat {
sub _hot_deploy {
my $self = shift;

# Make sure server is running
# Make sure server is running and clean up PID file if necessary
return unless my $pid = $self->_pid;
return unless kill 0, $pid;
my $file = $self->{config}{pid_file};
return -w $file ? unlink $file : undef unless kill 0, $pid;

# Start hot deployment
kill 'USR2', $pid;
Expand Down

2 comments on commit 4fa57db

@coffeemonster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux (and Perl) kill 0, 0 returns true. If the pid_file is set to "0" (which Daemon::Control initialises it to) then hypnotoad will not cleanup the pid_file. May I suggest:

+  return unless defined( my $pid = $self->_pid );
   my $file = $self->{config}{pid_file};
+  return -w $file ? unlink $file : undef unless $pid and kill 0, $pid;

@kraih
Copy link
Member Author

@kraih kraih commented on 4fa57db Sep 18, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like a reasonable change.

Please sign in to comment.