Fix background option
Tomas Doran [Mon, 18 Jul 2011 22:31:01 +0000 (23:31 +0100)]
TODO
lib/Catalyst/Script/Server.pm

diff --git a/TODO b/TODO
index 302bf1a..75ed7a3 100644 (file)
--- 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
 
index 700ba55..d587b4f 100644 (file)
@@ -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;
     }