Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed small bug where Hypnotoad would clean up process id and lock fi…
…les too early
  • Loading branch information
kraih committed Jun 28, 2014
1 parent a0c8c19 commit b6b88ae
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,9 +1,12 @@

5.10 2014-06-28
- Added cleanup attribute to Mojo::Server::Prefork.
- Improved Mojo::Server::Prefork to keep sending heartbeat messages when
stopping gracefully.
- Fixed small bug where Mojo::Server::Daemon was too eager to reconfigure
Mojo::IOLoop.
- Fixed small bug where Hypnotoad would clean up process id and lock files
too early.

5.09 2014-06-24
- Improved .ep templates to make the current controller available as $c.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Asset/File.pm
Expand Up @@ -179,7 +179,7 @@ implements the following new ones.
my $bool = $file->cleanup;
$file = $file->cleanup($bool);
Delete file automatically once it's not used anymore.
Delete L</"path"> automatically once the file is not used anymore.
=head2 handle
Expand Down
16 changes: 9 additions & 7 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -37,7 +37,7 @@ sub run {
my ($self, $app) = @_;

# No Windows support
_exit('Hypnotoad not available for Windows.') if $^O eq 'MSWin32';
$self->_exit('Hypnotoad not available for Windows.') if $^O eq 'MSWin32';

# Remember executable and application for later
$ENV{HYPNOTOAD_EXE} ||= $0;
Expand All @@ -60,7 +60,7 @@ sub run {
$prefork->on(finish => sub { $self->{finished} = 1 });
# Testing
_exit('Everything looks good!') if $ENV{HYPNOTOAD_TEST};
$self->_exit('Everything looks good!') if $ENV{HYPNOTOAD_TEST};
# Stop running server
$self->_stop if $ENV{HYPNOTOAD_STOP};
Expand All @@ -77,7 +77,7 @@ sub run {
$prefork->run;
}
sub _exit { say shift and exit 0 }
sub _exit { shift->prefork->cleanup(0) and say shift and exit 0 }
sub _hot_deploy {
my $self = shift;
Expand All @@ -87,7 +87,7 @@ sub _hot_deploy {
# Start hot deployment
kill 'USR2', $pid;
_exit("Starting hot deployment for Hypnotoad server $pid.");
$self->_exit("Starting hot deployment for Hypnotoad server $pid.");
}
sub _manage {
Expand Down Expand Up @@ -127,10 +127,12 @@ sub _reap {
}

sub _stop {
_exit('Hypnotoad server not running.')
unless my $pid = shift->prefork->check_pid;
my $self = shift;

$self->_exit('Hypnotoad server not running.')
unless my $pid = $self->prefork->check_pid;
kill 'QUIT', $pid;
_exit("Stopping Hypnotoad server $pid gracefully.");
$self->_exit("Stopping Hypnotoad server $pid gracefully.");
}

1;
Expand Down
14 changes: 11 additions & 3 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -12,18 +12,18 @@ use Time::HiRes ();

has accepts => 1000;
has [qw(accept_interval multi_accept)];
has [qw(cleanup lock_timeout)] => 1;
has [qw(graceful_timeout heartbeat_timeout)] => 20;
has heartbeat_interval => 5;
has lock_file => sub { catfile tmpdir, 'prefork.lock' };
has lock_timeout => 1;
has pid_file => sub { catfile tmpdir, 'prefork.pid' };
has workers => 4;

sub DESTROY {
my $self = shift;

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

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

# Change user/group
$self->setuidgid->{worker}++;
$self->setuidgid->cleanup(0);

# Accept mutex
my $loop = $self->ioloop->lock(
Expand Down Expand Up @@ -405,6 +405,14 @@ connections indefinitely. Note that up to half of this value can be subtracted
randomly to improve load balancing, and that worker processes will stop
sending heartbeat messages once the limit has been reached.
=head2 cleanup
my $bool = $prefork->cleanup;
$prefork = $prefork->cleanup($bool);
Delete L</"lock_file"> and L</"pid_file"> automatically once they are not
needed anymore.
=head2 graceful_timeout
my $timeout = $prefork->graceful_timeout;
Expand Down

0 comments on commit b6b88ae

Please sign in to comment.