1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-09 06:11:01 +01:00

Daemons - better handle rogue daemons from phd

Summary: Ref T2374. While building D10367 I noticed that phd was finding rogue daemons way more than it should be. Re-jigger this code path so rogue daemons are checked for *after* we've dealt with known daemons. This keeps the logic pretty simple overall.

Test Plan: phd start; kill pid files; phd stop and get the right warning; phd stop --force and it kills the rogue demons. phd stop in normal conditions no longer reporting rogue daemons erroneously

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T2374

Differential Revision: https://secure.phabricator.com/D10368
This commit is contained in:
Bob Trahan 2014-08-27 12:24:06 -07:00
parent 85b767bbdc
commit 2fdd7f0f3d

View file

@ -294,31 +294,21 @@ abstract class PhabricatorDaemonManagementWorkflow
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
$daemons = $this->loadRunningDaemons(); $daemons = $this->loadRunningDaemons();
$rogue_daemons = PhutilDaemonOverseer::findRunningDaemons();
if (!$daemons) { if (!$daemons) {
$rogue_daemons = PhutilDaemonOverseer::findRunningDaemons();
if ($force && $rogue_daemons) { if ($force && $rogue_daemons) {
$stop_rogue_daemons = $this->buildRogueDaemons($rogue_daemons); $stop_rogue_daemons = $this->buildRogueDaemons($rogue_daemons);
$this->sendStopSignals($stop_rogue_daemons, $grace_period); $this->sendStopSignals($stop_rogue_daemons, $grace_period);
} else { } else {
$console->writeErr(pht( $console->writeErr(pht(
'There are no running Phabricator daemons.')."\n"); 'There are no running Phabricator daemons.')."\n");
if ($rogue_daemons) { if ($rogue_daemons && !$pids) {
$console->writeErr($this->getForceStopHint($rogue_daemons)."\n"); $console->writeErr($this->getForceStopHint($rogue_daemons)."\n");
} }
} }
return 0; return 0;
} }
if ($rogue_daemons) {
if ($force) {
$daemons = array_merge(
$daemons,
$this->buildRogueDaemons($rogue_daemons));
} else {
$console->writeErr($this->getForceStopHint($rogue_daemons)."\n");
}
}
$daemons = mpull($daemons, null, 'getPID'); $daemons = mpull($daemons, null, 'getPID');
$running = array(); $running = array();
@ -357,16 +347,30 @@ abstract class PhabricatorDaemonManagementWorkflow
} }
} }
$rogue_daemons = PhutilDaemonOverseer::findRunningDaemons();
if ($rogue_daemons) {
if ($force) {
$stop_rogue_daemons = $this->buildRogueDaemons($rogue_daemons);
$this->sendStopSignals($stop_rogue_daemons, $grace_period);
} else if (!$pids) {
$console->writeErr($this->getForceStopHint($rogue_daemons)."\n");
}
}
return 0; return 0;
} }
private function getForceStopHint($rogue_daemons) { private function getForceStopHint($rogue_daemons) {
$debug_output = '';
foreach ($rogue_daemons as $rogue) {
$debug_output .= $rogue['pid'].' '.$rogue['command']."\n";
}
return pht( return pht(
'There are processes running that look like Phabricator daemons but '. 'There are processes running that look like Phabricator daemons but '.
'have no corresponding PID files:'."\n\n".'%s'."\n\n". 'have no corresponding PID files:'."\n\n".'%s'."\n\n".
'Stop these processes by re-running this command with the --force '. 'Stop these processes by re-running this command with the --force '.
'parameter.', 'parameter.',
implode("\n", ipull($rogue_daemons, 'command'))); $debug_output);
} }
private function buildRogueDaemons(array $daemons) { private function buildRogueDaemons(array $daemons) {