Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/PhutilDaemonHandle.php
| Show First 20 Lines • Show All 321 Lines • ▼ Show 20 Lines | try { | ||||
| PhutilEventEngine::dispatchEvent($event); | PhutilEventEngine::dispatchEvent($event); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| phlog($ex); | phlog($ex); | ||||
| } | } | ||||
| } | } | ||||
| private function annihilateProcessGroup() { | private function annihilateProcessGroup() { | ||||
| $pid = $this->getPID(); | $pid = $this->getPID(); | ||||
| if ($pid) { | |||||
| $pgid = posix_getpgid($pid); | $pgid = posix_getpgid($pid); | ||||
| if ($pid && $pgid) { | if ($pgid) { | ||||
| posix_kill(-$pgid, SIGTERM); | posix_kill(-$pgid, SIGTERM); | ||||
| sleep($this->getKillDelay()); | sleep($this->getKillDelay()); | ||||
| posix_kill(-$pgid, SIGKILL); | posix_kill(-$pgid, SIGKILL); | ||||
| $this->pid = null; | $this->pid = null; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| private function startDaemonProcess() { | private function startDaemonProcess() { | ||||
| $this->logMessage('INIT', pht('Starting process.')); | $this->logMessage('INIT', pht('Starting process.')); | ||||
| $this->deadline = time() + $this->getRequiredHeartbeatFrequency(); | $this->deadline = time() + $this->getRequiredHeartbeatFrequency(); | ||||
| $this->heartbeat = time() + self::getHeartbeatEventFrequency(); | $this->heartbeat = time() + self::getHeartbeatEventFrequency(); | ||||
| $this->stdoutBuffer = ''; | $this->stdoutBuffer = ''; | ||||
| $this->hibernating = false; | $this->hibernating = false; | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | public function didReceiveReloadSignal($signo) { | ||||
| // a new identical process once it exits". This can be used to update | // a new identical process once it exits". This can be used to update | ||||
| // daemons after code changes (the new processes will run the new code) | // daemons after code changes (the new processes will run the new code) | ||||
| // without aborting any running tasks. | // without aborting any running tasks. | ||||
| // We SIGINT the daemon but don't set the shutdown flag, so it will | // We SIGINT the daemon but don't set the shutdown flag, so it will | ||||
| // naturally be restarted after it exits, as though it had exited after an | // naturally be restarted after it exits, as though it had exited after an | ||||
| // unhandled exception. | // unhandled exception. | ||||
| posix_kill($this->getPID(), SIGINT); | $pid = $this->getPID(); | ||||
| if ($pid) { | |||||
| posix_kill($pid, SIGINT); | |||||
| } | |||||
| } | } | ||||
| public function didReceiveGracefulSignal($signo) { | public function didReceiveGracefulSignal($signo) { | ||||
| $this->shouldShutdown = true; | $this->shouldShutdown = true; | ||||
| $this->shouldRestart = false; | $this->shouldRestart = false; | ||||
| $signame = phutil_get_signal_name($signo); | $signame = phutil_get_signal_name($signo); | ||||
| if ($signame) { | if ($signame) { | ||||
| $sigmsg = pht( | $sigmsg = pht( | ||||
| 'Graceful shutdown in response to signal %d (%s).', | 'Graceful shutdown in response to signal %d (%s).', | ||||
| $signo, | $signo, | ||||
| $signame); | $signame); | ||||
| } else { | } else { | ||||
| $sigmsg = pht( | $sigmsg = pht( | ||||
| 'Graceful shutdown in response to signal %d.', | 'Graceful shutdown in response to signal %d.', | ||||
| $signo); | $signo); | ||||
| } | } | ||||
| $this->logMessage('DONE', $sigmsg, $signo); | $this->logMessage('DONE', $sigmsg, $signo); | ||||
| posix_kill($this->getPID(), SIGINT); | $pid = $this->getPID(); | ||||
| if ($pid) { | |||||
| posix_kill($pid, SIGINT); | |||||
| } | |||||
| } | } | ||||
| public function didReceiveTerminateSignal($signo) { | public function didReceiveTerminateSignal($signo) { | ||||
| $this->shouldShutdown = true; | $this->shouldShutdown = true; | ||||
| $this->shouldRestart = false; | $this->shouldRestart = false; | ||||
| $signame = phutil_get_signal_name($signo); | $signame = phutil_get_signal_name($signo); | ||||
| if ($signame) { | if ($signame) { | ||||
| Show All 34 Lines | |||||