Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
removed daemonize method from Mojo::Server::Prefork
  • Loading branch information
kraih committed Jan 16, 2013
1 parent 8e45606 commit a7b0e8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
15 changes: 13 additions & 2 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -7,6 +7,7 @@ use Cwd 'abs_path';
use File::Basename 'dirname';
use File::Spec::Functions 'catfile';
use Mojo::Server::Prefork;
use POSIX 'setsid';
use Scalar::Util 'weaken';

sub run {
Expand Down Expand Up @@ -47,8 +48,18 @@ sub run {
$self->_hot_deploy unless $ENV{HYPNOTOAD_PID};

# Daemonize as early as possible (but not for restarts)
$prefork->daemonize
if !$ENV{HYPNOTOAD_FOREGROUND} && $ENV{HYPNOTOAD_REV} < 3;
if (!$ENV{HYPNOTOAD_FOREGROUND} && $ENV{HYPNOTOAD_REV} < 3) {

# Fork and kill parent
die "Can't fork: $!" unless defined(my $pid = fork);
exit 0 if $pid;
setsid or die "Can't start a new session: $!";

# Close file handles
open STDIN, '</dev/null';
open STDOUT, '>/dev/null';
open STDERR, '>&STDOUT';
}

# Clean manager environment
local $SIG{USR2} = sub { $self->{upgrade} ||= time };
Expand Down
21 changes: 1 addition & 20 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -5,7 +5,7 @@ use Fcntl ':flock';
use File::Spec::Functions qw(catfile tmpdir);
use IO::Poll 'POLLIN';
use List::Util 'shuffle';
use POSIX qw(setsid WNOHANG);
use POSIX 'WNOHANG';
use Scalar::Util 'weaken';
use Time::HiRes 'ualarm';

Expand All @@ -30,19 +30,6 @@ sub DESTROY {
if (my $file = $self->{pid_file}) { unlink $file if -w $file }
}

sub daemonize {

# Fork and kill parent
die "Can't fork: $!" unless defined(my $pid = fork);
exit 0 if $pid;
setsid or die "Can't start a new session: $!";

# Close file handles
open STDIN, '</dev/null';
open STDOUT, '>/dev/null';
open STDERR, '>&STDOUT';
}

sub run {
my $self = shift;

Expand Down Expand Up @@ -455,12 +442,6 @@ worker processes per CPU core.
L<Mojo::Server::Prefork> inherits all methods from L<Mojo::Server::Daemon> and
implements the following new ones.
=head2 daemonize
$prefork->daemonize;
Daemonize process.
=head2 run
$prefork->run;
Expand Down

0 comments on commit a7b0e8b

Please sign in to comment.