Skip to content

Commit

Permalink
simplify process id and lock file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 28, 2014
1 parent 35c4533 commit 2d60ce9
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -37,7 +37,7 @@ sub run {
my ($self, $app) = @_;

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

# Remember executable and application for later
$ENV{HYPNOTOAD_EXE} ||= $0;
Expand All @@ -50,7 +50,7 @@ sub run {
die "Can't exec: $!" if !$ENV{HYPNOTOAD_REV}++ && !exec $ENV{HYPNOTOAD_EXE};

# Preload application and configure server
my $prefork = $self->prefork;
my $prefork = $self->prefork->cleanup(0);
$prefork->load_app($app)->config->{hypnotoad}{pid_file}
//= catfile dirname($ENV{HYPNOTOAD_APP}), 'hypnotoad.pid';
$self->configure('hypnotoad');
Expand All @@ -60,7 +60,7 @@ sub run {
$prefork->on(finish => sub { $self->{finished} = 1 });
# Testing
$self->_exit('Everything looks good!') if $ENV{HYPNOTOAD_TEST};
_exit('Everything looks good!') if $ENV{HYPNOTOAD_TEST};
# Stop running server
$self->_stop if $ENV{HYPNOTOAD_STOP};
Expand All @@ -74,20 +74,19 @@ sub run {
# Start accepting connections
local $SIG{USR2} = sub { $self->{upgrade} ||= steady_time };
$prefork->run;
$prefork->cleanup(1)->run;
}
sub _exit { shift->prefork->cleanup(0) and say shift and exit 0 }
sub _exit { say shift and exit 0 }
sub _hot_deploy {
my $self = shift;
# Make sure server is running
return unless my $pid = $self->prefork->check_pid;
return unless my $pid = shift->prefork->check_pid;
# Start hot deployment
kill 'USR2', $pid;
$self->_exit("Starting hot deployment for Hypnotoad server $pid.");
_exit("Starting hot deployment for Hypnotoad server $pid.");
}
sub _manage {
Expand Down Expand Up @@ -127,12 +126,10 @@ sub _reap {
}

sub _stop {
my $self = shift;

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

1;
Expand Down

0 comments on commit 2d60ce9

Please sign in to comment.