Write out the pid file after double fork.
Tomas Doran [Mon, 18 Jul 2011 22:34:59 +0000 (23:34 +0100)]
Therefore we get the pid of the actual server process saved, rather than
that of the runner

lib/Catalyst/Script/Server.pm

index d587b4f..3afb632 100644 (file)
@@ -66,8 +66,7 @@ has pidfile => (
 
 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');
@@ -191,6 +190,8 @@ sub run {
     if ( $self->restart ) {
         die "Cannot run in the background and also watch for changed files.\n"
             if $self->background;
+        die "Cannot write out a pid file and fork for the restarter.\n"
+            if $self->_has_pidfile;
 
         # If we load this here, then in the case of a restarter, it does not
         # need to be reloaded for each restart.
@@ -221,6 +222,9 @@ sub run {
             $self->daemon_detach;
         }
 
+        $self->pidfile->write
+            if $self->_has_pidfile;
+
         $self->_run_application;
     }