Changeset View
Changeset View
Standalone View
Standalone View
src/daemon/PhutilDaemonOverseer.php
Show First 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | if ($this->daemonize) { | ||||
throw new Exception(pht('Unable to fork!')); | throw new Exception(pht('Unable to fork!')); | ||||
} else if ($pid) { | } else if ($pid) { | ||||
exit(0); | exit(0); | ||||
} | } | ||||
} | } | ||||
$this->modules = PhutilDaemonOverseerModule::getAllModules(); | $this->modules = PhutilDaemonOverseerModule::getAllModules(); | ||||
declare(ticks = 1); | |||||
pcntl_signal(SIGUSR2, array($this, 'didReceiveNotifySignal')); | pcntl_signal(SIGUSR2, array($this, 'didReceiveNotifySignal')); | ||||
pcntl_signal(SIGHUP, array($this, 'didReceiveReloadSignal')); | pcntl_signal(SIGHUP, array($this, 'didReceiveReloadSignal')); | ||||
pcntl_signal(SIGINT, array($this, 'didReceiveGracefulSignal')); | pcntl_signal(SIGINT, array($this, 'didReceiveGracefulSignal')); | ||||
pcntl_signal(SIGTERM, array($this, 'didReceiveTerminalSignal')); | pcntl_signal(SIGTERM, array($this, 'didReceiveTerminalSignal')); | ||||
} | } | ||||
public function addLibrary($library) { | public function addLibrary($library) { | ||||
Show All 16 Lines | foreach ($this->config['daemons'] as $config) { | ||||
$this->argv, | $this->argv, | ||||
array( | array( | ||||
'log' => $this->log, | 'log' => $this->log, | ||||
'argv' => $config['argv'], | 'argv' => $config['argv'], | ||||
'load' => $this->libraries, | 'load' => $this->libraries, | ||||
'autoscale' => $config['autoscale'], | 'autoscale' => $config['autoscale'], | ||||
)); | )); | ||||
$daemon->setSilent((!$this->traceMode && !$this->verbose)); | |||||
$daemon->setTraceMemory($this->traceMemory); | $daemon->setTraceMemory($this->traceMemory); | ||||
$this->addDaemon($daemon, $config); | $this->addDaemon($daemon, $config); | ||||
} | } | ||||
$should_reload = false; | $should_reload = false; | ||||
while (true) { | while (true) { | ||||
foreach ($this->modules as $module) { | foreach ($this->modules as $module) { | ||||
try { | try { | ||||
if ($module->shouldReloadDaemons()) { | if ($module->shouldReloadDaemons()) { | ||||
$this->logMessage( | |||||
'RELO', | |||||
pht( | |||||
'Reloading daemons (triggered by overseer module "%s").', | |||||
get_class($module))); | |||||
$should_reload = true; | $should_reload = true; | ||||
} | } | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
phlog($ex); | phlog($ex); | ||||
} | } | ||||
} | } | ||||
if ($should_reload) { | if ($should_reload) { | ||||
$this->didReceiveReloadSignal(SIGHUP); | $this->didReceiveReloadSignal(SIGHUP); | ||||
$should_reload = false; | $should_reload = false; | ||||
} | } | ||||
$futures = array(); | $futures = array(); | ||||
foreach ($this->getDaemonHandles() as $daemon) { | foreach ($this->getDaemonHandles() as $daemon) { | ||||
$daemon->update(); | $daemon->update(); | ||||
▲ Show 20 Lines • Show All 288 Lines • ▼ Show 20 Lines | private function updatePidfile() { | ||||
if ($pidfile !== $this->lastPidfile) { | if ($pidfile !== $this->lastPidfile) { | ||||
$this->lastPidfile = $pidfile; | $this->lastPidfile = $pidfile; | ||||
$pidfile_path = $this->piddir.'/daemon.'.getmypid(); | $pidfile_path = $this->piddir.'/daemon.'.getmypid(); | ||||
Filesystem::writeFile($pidfile_path, json_encode($pidfile)); | Filesystem::writeFile($pidfile_path, json_encode($pidfile)); | ||||
} | } | ||||
} | } | ||||
public function logMessage($type, $message, $context = null) { | |||||
if ($this->traceMode || $this->verbose) { | |||||
error_log(date('Y-m-d g:i:s A').' ['.$type.'] '.$message); | |||||
} | |||||
} | |||||
} | } |