Skip to content

Commit

Permalink
no need to generate PID file all the time
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 19, 2014
1 parent fa82aba commit 8076a27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
13 changes: 6 additions & 7 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base -base;

# "Bender: I was God once.
# God: Yes, I saw. You were doing well, until everyone died."
use Cwd qw(abs_path getcwd);
use Cwd 'abs_path';
use File::Basename 'dirname';
use File::Spec::Functions 'catfile';
use Mojo::Server::Prefork;
Expand All @@ -19,20 +19,18 @@ sub configure {
# Hypnotoad settings
my $prefork = $self->prefork;
my $c = $prefork->app->config($name) || {};
$c->{listen} ||= ['http://*:8080'];
$self->upgrade_timeout($c->{upgrade_timeout}) if $c->{upgrade_timeout};

# Prefork settings
$ENV{MOJO_REVERSE_PROXY} = $c->{proxy} if defined $c->{proxy};
$prefork->listen($c->{listen} || ['http://*:8080']);
my $dir = $ENV{HYPNOTOAD_APP} ? dirname $ENV{HYPNOTOAD_APP} : getcwd;
$prefork->pid_file($c->{pid_file} || catfile $dir, 'hypnotoad.pid');
$prefork->max_clients($c->{clients}) if $c->{clients};
$prefork->max_requests($c->{keep_alive_requests})
if $c->{keep_alive_requests};
defined $c->{$_} and $prefork->$_($c->{$_})
for qw(accept_interval accepts backlog graceful_timeout group),
qw(heartbeat_interval heartbeat_timeout inactivity_timeout lock_file),
qw(lock_timeout multi_accept user workers);
qw(heartbeat_interval heartbeat_timeout inactivity_timeout listen),
qw(lock_file lock_timeout multi_accept pid_file user workers);
}

sub run {
Expand All @@ -53,7 +51,8 @@ sub run {

# Preload application and configure server
my $prefork = $self->prefork;
$prefork->load_app($app);
$prefork->load_app($app)->config->{hypnotoad}{pid_file}
//= catfile dirname($ENV{HYPNOTOAD_APP}), 'hypnotoad.pid';
$self->configure('hypnotoad');
weaken $self;
$prefork->on(wait => sub { $self->_manage });
Expand Down
5 changes: 1 addition & 4 deletions t/mojo/hypnotoad.t
Expand Up @@ -10,8 +10,7 @@ use Test::More;
plan skip_all => 'set TEST_HYPNOTOAD to enable this test (developer only!)'
unless $ENV{TEST_HYPNOTOAD};

use Cwd 'getcwd';
use File::Spec::Functions qw(catdir catfile);
use File::Spec::Functions 'catdir';
use File::Temp 'tempdir';
use FindBin;
use IO::Socket::INET;
Expand Down Expand Up @@ -48,8 +47,6 @@ use Mojo::Util qw(slurp spurt);
is $hypnotoad->upgrade_timeout, 60, 'right default';
$hypnotoad->configure('test');
is_deeply $hypnotoad->prefork->listen, ['http://*:8080'], 'right value';
is $hypnotoad->prefork->pid_file, catfile(getcwd, 'hypnotoad.pid'),
'right value';
$hypnotoad->configure('myserver');
is $hypnotoad->prefork->accept_interval, 33, 'right value';
is $hypnotoad->prefork->accepts, 13, 'right value';
Expand Down

0 comments on commit 8076a27

Please sign in to comment.