Skip to content

Commit

Permalink
clean up PID file more consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 28, 2014
1 parent 821844b commit 4f8bb14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -24,7 +24,7 @@ sub DESTROY {
my $self = shift;

# Worker
return unless $self->{finished};
return if $self->{worker};

# Manager
if (my $file = $self->{lock_file}) { unlink $file if -w $file }
Expand Down Expand Up @@ -169,10 +169,10 @@ sub _spawn {
unless open my $handle, '>', $file;

# Change user/group
my $loop = $self->setuidgid->ioloop;
$self->setuidgid->{worker}++;

# Accept mutex
$loop->lock(
my $loop = $self->ioloop->lock(
sub {

# Blocking ("ualarm" can't be imported on Windows)
Expand Down
8 changes: 5 additions & 3 deletions t/mojo/prefork.t
Expand Up @@ -19,13 +19,15 @@ use Mojo::Util 'spurt';
my $prefork = Mojo::Server::Prefork->new;
my $file = $prefork->pid_file;
ok !$prefork->check_pid, 'no process id';
$prefork->ensure_pid_file;
ok -e $file, 'file exists';
is $prefork->check_pid, $$, 'right process id';
spurt "\n", $file;
ok -e $file, 'file exists';
ok !$prefork->check_pid, 'no process id';
ok !-e $file, 'file has been cleaned up';
$prefork->ensure_pid_file;
ok -e $file, 'file exists';
is $prefork->check_pid, $$, 'right process id';
undef $prefork;
ok !-e $file, 'file has been cleaned up';

# Multiple workers and graceful shutdown
my $port = Mojo::IOLoop->generate_port;
Expand Down

0 comments on commit 4f8bb14

Please sign in to comment.