Add phd reload to send SIGHUP to overseers
Summary: Ref T7384. This just sends SIGHUP to specified overseers in a nice package. Test Plan: See D11898. Reviewers: hach-que, btrahan Reviewed By: btrahan Subscribers: joshuaspence, epriestley Maniphest Tasks: T7384 Differential Revision: https://secure.phabricator.com/D11899
This commit is contained in:
@@ -1614,6 +1614,7 @@ phutil_register_library_map(array(
|
||||
'PhabricatorDaemonManagementLaunchWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementLaunchWorkflow.php',
|
||||
'PhabricatorDaemonManagementListWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementListWorkflow.php',
|
||||
'PhabricatorDaemonManagementLogWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementLogWorkflow.php',
|
||||
'PhabricatorDaemonManagementReloadWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementReloadWorkflow.php',
|
||||
'PhabricatorDaemonManagementRestartWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementRestartWorkflow.php',
|
||||
'PhabricatorDaemonManagementStartWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementStartWorkflow.php',
|
||||
'PhabricatorDaemonManagementStatusWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php',
|
||||
@@ -4877,6 +4878,7 @@ phutil_register_library_map(array(
|
||||
'PhabricatorDaemonManagementLaunchWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementListWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementLogWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementReloadWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementRestartWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementStartWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementStatusWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
final class PhabricatorDaemonManagementReloadWorkflow
|
||||
extends PhabricatorDaemonManagementWorkflow {
|
||||
|
||||
protected function didConstruct() {
|
||||
$this
|
||||
->setName('reload')
|
||||
->setSynopsis(
|
||||
pht(
|
||||
'Gracefully restart daemon processes in-place to pick up changes '.
|
||||
'to source. This will not disrupt running jobs. This is an '.
|
||||
'advanced workflow; most installs should use __phd restart__.'))
|
||||
->setArguments(
|
||||
array(
|
||||
array(
|
||||
'name' => 'pids',
|
||||
'wildcard' => true,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
return $this->executeReloadCommand($args->getArg('pids'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -389,28 +389,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||
return 0;
|
||||
}
|
||||
|
||||
$running_pids = array_fuse(mpull($daemons, 'getPID'));
|
||||
if (!$pids) {
|
||||
$stop_pids = $running_pids;
|
||||
} else {
|
||||
// We were given a PID or set of PIDs to kill.
|
||||
$stop_pids = array();
|
||||
foreach ($pids as $key => $pid) {
|
||||
if (!preg_match('/^\d+$/', $pid)) {
|
||||
$console->writeErr(pht("PID '%s' is not a valid PID.", $pid)."\n");
|
||||
continue;
|
||||
} else if (empty($running_pids[$pid])) {
|
||||
$console->writeErr(
|
||||
pht(
|
||||
'PID "%d" is not a known Phabricator daemon PID. It will not '.
|
||||
'be killed.',
|
||||
$pid)."\n");
|
||||
continue;
|
||||
} else {
|
||||
$stop_pids[$pid] = $pid;
|
||||
}
|
||||
}
|
||||
}
|
||||
$stop_pids = $this->selectDaemonPIDs($daemons, $pids);
|
||||
|
||||
if (!$stop_pids) {
|
||||
$console->writeErr(pht('No daemons to kill.')."\n");
|
||||
@@ -452,6 +431,35 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected final function executeReloadCommand(array $pids) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
$daemons = $this->loadRunningDaemons();
|
||||
if (!$daemons) {
|
||||
$console->writeErr(
|
||||
"%s\n",
|
||||
pht('There are no running daemons to reload.'));
|
||||
return 0;
|
||||
}
|
||||
|
||||
$reload_pids = $this->selectDaemonPIDs($daemons, $pids);
|
||||
if (!$reload_pids) {
|
||||
$console->writeErr(
|
||||
"%s\n",
|
||||
pht('No daemons to reload.'));
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($reload_pids as $pid) {
|
||||
$console->writeOut(
|
||||
"%s\n",
|
||||
pht('Reloading process %d...', $pid));
|
||||
posix_kill($pid, SIGHUP);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function processRogueDaemons($grace_period, $warn, $force_stop) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
@@ -615,4 +623,33 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||
);
|
||||
}
|
||||
|
||||
private function selectDaemonPIDs(array $daemons, array $pids) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
$running_pids = array_fuse(mpull($daemons, 'getPID'));
|
||||
if (!$pids) {
|
||||
$select_pids = $running_pids;
|
||||
} else {
|
||||
// We were given a PID or set of PIDs to kill.
|
||||
$select_pids = array();
|
||||
foreach ($pids as $key => $pid) {
|
||||
if (!preg_match('/^\d+$/', $pid)) {
|
||||
$console->writeErr(pht("PID '%s' is not a valid PID.", $pid)."\n");
|
||||
continue;
|
||||
} else if (empty($running_pids[$pid])) {
|
||||
$console->writeErr(
|
||||
"%s\n",
|
||||
pht(
|
||||
'PID "%d" is not a known Phabricator daemon PID.',
|
||||
$pid));
|
||||
continue;
|
||||
} else {
|
||||
$select_pids[$pid] = $pid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $select_pids;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user