From: Tomas Doran Date: Mon, 18 Jul 2011 22:31:01 +0000 (+0100) Subject: Fix background option X-Git-Tag: 5.89003~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=07b56dc9ccb03a4fdd4cfe017cfc42359fe51529 Fix background option --- diff --git a/TODO b/TODO index 302bf1a..75ed7a3 100644 --- a/TODO +++ b/TODO @@ -47,7 +47,7 @@ Although --pidfile is supported --pid seems to be preferred, and if we are bothe --pidfile handling is shiit. MooseX::Daemonize will blow up really nastilly if not installed.. - --background seem to does nothing. + --background handling also shit. ### Nice to have diff --git a/lib/Catalyst/Script/Server.pm b/lib/Catalyst/Script/Server.pm index 700ba55..d587b4f 100644 --- a/lib/Catalyst/Script/Server.pm +++ b/lib/Catalyst/Script/Server.pm @@ -68,6 +68,11 @@ sub BUILD { my $self = shift; $self->pidfile->write if $self->_has_pidfile; + if ($self->background) { + # FIXME - This is evil. Should we just add MX::Daemonize to the deps? + Class::MOP::load_class('MooseX::Daemonize::Core'); + MooseX::Daemonize::Core->meta->apply($self); + } } has keepalive => ( @@ -206,6 +211,16 @@ sub run { $restarter->run_and_watch; } else { + if ($self->background) { + $self->daemon_fork; + + return 1 unless $self->is_daemon; + + Class::MOP::load_class($self->application_name); + + $self->daemon_detach; + } + $self->_run_application; }