diff --git a/src/daemon/PhutilDaemonHandle.php b/src/daemon/PhutilDaemonHandle.php --- a/src/daemon/PhutilDaemonHandle.php +++ b/src/daemon/PhutilDaemonHandle.php @@ -122,7 +122,6 @@ if ($this->shouldShutdown) { $this->restartAt = null; - $this->dispatchEvent(self::EVENT_WILL_EXIT); } else { $this->scheduleRestart(); } @@ -362,11 +361,7 @@ public function didReceiveGracefulSignal($signo) { $this->shouldShutdown = true; - if (!$this->isRunning()) { - // If we aren't running a daemon, emit this event now. Otherwise, we'll - // emit it when the daemon exits. - $this->dispatchEvent(self::EVENT_WILL_EXIT); - } + $this->shouldRestart = false; $signame = phutil_get_signal_name($signo); if ($signame) { @@ -386,6 +381,9 @@ } public function didReceiveTerminalSignal($signo) { + $this->shouldShutdown = true; + $this->shouldRestart = false; + $signame = phutil_get_signal_name($signo); if ($signame) { $sigmsg = pht( @@ -398,7 +396,6 @@ $this->logMessage('EXIT', $sigmsg, $signo); $this->annihilateProcessGroup(); - $this->dispatchEvent(self::EVENT_WILL_EXIT); } private function logMessage($type, $message, $context = null) { @@ -415,4 +412,8 @@ )); } + public function didRemoveDaemon() { + $this->dispatchEvent(self::EVENT_WILL_EXIT); + } + } diff --git a/src/daemon/PhutilDaemonOverseer.php b/src/daemon/PhutilDaemonOverseer.php --- a/src/daemon/PhutilDaemonOverseer.php +++ b/src/daemon/PhutilDaemonOverseer.php @@ -261,6 +261,8 @@ unset($this->daemons[$id]); + $daemon->didRemoveDaemon(); + return $this; }