Add a "--gently" flag to phd stop and phd restart

Summary:
In the cluster, the box has a ton of stuff that "looks like a daemon" beacuse it is some other instance's daemon.

Stop `phd restart` from complaining about this if given a "--gently" flag, which is like the opposite of "--force".

(I'll make it `stop --force` at the beginning of a whole-box restart to kill stragglers.)

Test Plan: Ran `bin/phd restart --gently`, etc.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D11784
This commit is contained in:
epriestley 2015-02-17 11:14:34 -08:00
parent 267ff7fbc9
commit e946e7cebc
3 changed files with 43 additions and 11 deletions

View file

@ -19,6 +19,12 @@ final class PhabricatorDaemonManagementRestartWorkflow
'seconds. Defaults to __15__ seconds.'), 'seconds. Defaults to __15__ seconds.'),
'default' => 15, 'default' => 15,
), ),
array(
'name' => 'gently',
'help' => pht(
'Ignore running processes that look like daemons but do not '.
'have corresponding PID files.'),
),
array( array(
'name' => 'force', 'name' => 'force',
'help' => pht( 'help' => pht(
@ -29,12 +35,17 @@ final class PhabricatorDaemonManagementRestartWorkflow
} }
public function execute(PhutilArgumentParser $args) { public function execute(PhutilArgumentParser $args) {
$graceful = $args->getArg('graceful'); $err = $this->executeStopCommand(
$force = $args->getArg('force'); array(),
$err = $this->executeStopCommand(array(), $graceful, $force); array(
'graceful' => $args->getArg('graceful'),
'force' => $args->getArg('force'),
'gently' => $args->getArg('gently'),
));
if ($err) { if ($err) {
return $err; return $err;
} }
return $this->executeStartCommand(); return $this->executeStartCommand();
} }

View file

@ -26,6 +26,12 @@ final class PhabricatorDaemonManagementStopWorkflow
'Also stop running processes that look like daemons but do '. 'Also stop running processes that look like daemons but do '.
'not have corresponding PID files.'), 'not have corresponding PID files.'),
), ),
array(
'name' => 'gently',
'help' => pht(
'Ignore running processes that look like daemons but do not '.
'have corresponding PID files.'),
),
array( array(
'name' => 'pids', 'name' => 'pids',
'wildcard' => true, 'wildcard' => true,
@ -34,10 +40,13 @@ final class PhabricatorDaemonManagementStopWorkflow
} }
public function execute(PhutilArgumentParser $args) { public function execute(PhutilArgumentParser $args) {
$pids = $args->getArg('pids'); return $this->executeStopCommand(
$graceful = $args->getArg('graceful'); $args->getArg('pids'),
$force = $args->getArg('force'); array(
return $this->executeStopCommand($pids, $graceful, $force); 'graceful' => $args->getArg('graceful'),
'force' => $args->getArg('force'),
'gently' => $args->getArg('gently'),
));
} }
} }

View file

@ -361,15 +361,25 @@ abstract class PhabricatorDaemonManagementWorkflow
protected final function executeStopCommand( protected final function executeStopCommand(
array $pids, array $pids,
$grace_period, array $options) {
$force) {
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
$grace_period = idx($options, 'graceful', 15);
$force = idx($options, 'force');
$gently = idx($options, 'gently');
if ($gently && $force) {
throw new PhutilArgumentUsageException(
pht(
'You can not specify conflicting options --gently and --force '.
'together.'));
}
$daemons = $this->loadRunningDaemons(); $daemons = $this->loadRunningDaemons();
if (!$daemons) { if (!$daemons) {
$survivors = array(); $survivors = array();
if (!$pids) { if (!$pids && !$gently) {
$survivors = $this->processRogueDaemons( $survivors = $this->processRogueDaemons(
$grace_period, $grace_period,
$warn = true, $warn = true,
@ -421,7 +431,9 @@ abstract class PhabricatorDaemonManagementWorkflow
} }
} }
$this->processRogueDaemons($grace_period, !$pids, $force); if (!$gently) {
$this->processRogueDaemons($grace_period, !$pids, $force);
}
return 0; return 0;
} }