Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15416321
D14452.id34967.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D14452.id34967.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -147,6 +147,7 @@
'PhutilDaemon' => 'daemon/PhutilDaemon.php',
'PhutilDaemonHandle' => 'daemon/PhutilDaemonHandle.php',
'PhutilDaemonOverseer' => 'daemon/PhutilDaemonOverseer.php',
+ 'PhutilDaemonOverseerModule' => 'daemon/PhutilDaemonOverseerModule.php',
'PhutilDefaultSyntaxHighlighter' => 'markup/syntax/highlighter/PhutilDefaultSyntaxHighlighter.php',
'PhutilDefaultSyntaxHighlighterEngine' => 'markup/syntax/engine/PhutilDefaultSyntaxHighlighterEngine.php',
'PhutilDefaultSyntaxHighlighterEnginePygmentsFuture' => 'markup/syntax/highlighter/pygments/PhutilDefaultSyntaxHighlighterEnginePygmentsFuture.php',
@@ -668,6 +669,7 @@
'PhutilDaemon' => 'Phobject',
'PhutilDaemonHandle' => 'Phobject',
'PhutilDaemonOverseer' => 'Phobject',
+ 'PhutilDaemonOverseerModule' => 'Phobject',
'PhutilDefaultSyntaxHighlighter' => 'Phobject',
'PhutilDefaultSyntaxHighlighterEngine' => 'PhutilSyntaxHighlighterEngine',
'PhutilDefaultSyntaxHighlighterEnginePygmentsFuture' => 'FutureProxy',
diff --git a/src/daemon/PhutilDaemonHandle.php b/src/daemon/PhutilDaemonHandle.php
--- a/src/daemon/PhutilDaemonHandle.php
+++ b/src/daemon/PhutilDaemonHandle.php
@@ -252,22 +252,9 @@
$pid = $this->pid;
$pgid = posix_getpgid($pid);
if ($pid && $pgid) {
-
- // NOTE: On Ubuntu, 'kill' does not recognize the use of "--" to
- // explicitly delineate PID/PGIDs from signals. We don't actually need it,
- // so use the implicit "kill -TERM -pgid" form instead of the explicit
- // "kill -TERM -- -pgid" form.
- exec("kill -TERM -{$pgid}");
+ posix_kill(-$pgid, SIGTERM);
sleep($this->getKillDelay());
-
- // On OSX, we'll get a permission error on stderr if the SIGTERM was
- // successful in ending the life of the process group, presumably because
- // all that's left is the daemon itself as a zombie waiting for us to
- // reap it. However, we still need to issue this command for process
- // groups that resist SIGTERM. Rather than trying to figure out if the
- // process group is still around or not, just SIGKILL unconditionally and
- // ignore any error which may be raised.
- exec("kill -KILL -{$pgid} 2>/dev/null");
+ posix_kill(-$pgid, SIGKILL);
$this->pid = null;
}
}
@@ -370,8 +357,7 @@
// naturally be restarted after it exits, as though it had exited after an
// unhandled exception.
- $pid = $this->pid;
- exec("kill -INT {$pid}");
+ posix_kill($this->pid, SIGINT);
}
public function didReceiveGracefulSignal($signo) {
@@ -396,8 +382,7 @@
$this->logMessage('DONE', $sigmsg, $signo);
- $pid = $this->pid;
- exec("kill -INT {$pid}");
+ posix_kill($this->pid, SIGINT);
}
public function didReceiveTerminalSignal($signo) {
diff --git a/src/daemon/PhutilDaemonOverseer.php b/src/daemon/PhutilDaemonOverseer.php
--- a/src/daemon/PhutilDaemonOverseer.php
+++ b/src/daemon/PhutilDaemonOverseer.php
@@ -19,6 +19,7 @@
private $piddir;
private $log;
private $libraries = array();
+ private $modules = array();
private $verbose;
private $err = 0;
private $lastPidfile;
@@ -145,6 +146,8 @@
}
}
+ $this->modules = PhutilDaemonOverseerModule::getAllModules();
+
declare(ticks = 1);
pcntl_signal(SIGUSR2, array($this, 'didReceiveNotifySignal'));
@@ -184,7 +187,23 @@
$this->addDaemon($daemon, $config);
}
+ $should_reload = false;
+
while (true) {
+ foreach ($this->modules as $module) {
+ try {
+ if ($module->shouldReloadDaemons()) {
+ $should_reload = true;
+ }
+ } catch (Exception $ex) {
+ phlog($ex);
+ }
+ }
+ if ($should_reload) {
+ $this->didReceiveReloadSignal(SIGHUP);
+ $should_reload = false;
+ }
+
$futures = array();
foreach ($this->getDaemonHandles() as $daemon) {
$daemon->update();
diff --git a/src/daemon/PhutilDaemonOverseerModule.php b/src/daemon/PhutilDaemonOverseerModule.php
new file mode 100644
--- /dev/null
+++ b/src/daemon/PhutilDaemonOverseerModule.php
@@ -0,0 +1,24 @@
+<?php
+
+/**
+ * Overseer modules allow daemons to be externally influenced.
+ *
+ * See @{class:PhabricatorDaemonOverseerModule} for a concrete example.
+ */
+abstract class PhutilDaemonOverseerModule extends Phobject {
+
+ /**
+ * This method is used to indicate to the overseer that daemons should reload.
+ *
+ * @return bool True if the daemons should reload, otherwise false.
+ */
+ abstract public function shouldReloadDaemons();
+
+
+ public static function getAllModules() {
+ return id(new PhutilClassMapQuery())
+ ->setAncestorClass(__CLASS__)
+ ->execute();
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 21, 10:33 AM (1 h, 49 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7544230
Default Alt Text
D14452.id34967.diff (4 KB)
Attached To
Mode
D14452: Add daemon overseer modules to allow daemons to be externally reloaded
Attached
Detach File
Event Timeline
Log In to Comment