Changeset View
Changeset View
Standalone View
Standalone View
src/daemon/PhutilDaemonHandle.php
Show First 20 Lines • Show All 335 Lines • ▼ Show 20 Lines | final class PhutilDaemonHandle { | ||||
public function didReceiveNotifySignal($signo) { | public function didReceiveNotifySignal($signo) { | ||||
$pid = $this->pid; | $pid = $this->pid; | ||||
if ($pid) { | if ($pid) { | ||||
posix_kill($pid, $signo); | posix_kill($pid, $signo); | ||||
} | } | ||||
} | } | ||||
public function didReceiveReloadSignal($signo) { | |||||
$signame = phutil_get_signal_name($signo); | |||||
if ($signame) { | |||||
$sigmsg = pht( | |||||
'Reloading in response to signal %d (%s).', | |||||
$signo, | |||||
$signame); | |||||
} else { | |||||
$sigmsg = pht( | |||||
'Reloading in response to signal %d.', | |||||
$signo); | |||||
} | |||||
$this->logMessage('RELO', $sigmsg, $signo); | |||||
// This signal means "stop the current process gracefully, then launch | |||||
// 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) | |||||
// without aborting any running tasks. | |||||
// 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 | |||||
// unhandled exception. | |||||
$pid = $this->pid; | |||||
exec("kill -INT {$pid}"); | |||||
} | |||||
public function didReceiveGracefulSignal($signo) { | public function didReceiveGracefulSignal($signo) { | ||||
$this->shouldShutdown = true; | $this->shouldShutdown = true; | ||||
if (!$this->isRunning()) { | if (!$this->isRunning()) { | ||||
// If we aren't running a daemon, emit this event now. Otherwise, we'll | // If we aren't running a daemon, emit this event now. Otherwise, we'll | ||||
// emit it when the daemon exits. | // emit it when the daemon exits. | ||||
$this->dispatchEvent(self::EVENT_WILL_EXIT); | $this->dispatchEvent(self::EVENT_WILL_EXIT); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |