1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Query daemons across all hosts with ./bin/phd status --all.

Summary: This was previously submitted as D9497, but I had accidentally `arc land`ed some not-reviewed not-yet-complete changes in addition to the accepted diff.

Test Plan: Same as D9497.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Maniphest Tasks: T5388, T4209

Differential Revision: https://secure.phabricator.com/D9589
This commit is contained in:
Joshua Spence 2014-06-17 11:13:38 +10:00
parent a10f969919
commit dde6d2491c
2 changed files with 102 additions and 24 deletions

View file

@ -7,10 +7,24 @@ final class PhabricatorDaemonManagementStatusWorkflow
$this
->setName('status')
->setSynopsis(pht('Show status of running daemons.'))
->setArguments(array());
->setArguments(
array(
array(
'name' => 'all',
'help' => pht('Show the status of daemons across all hosts.'),
),
));
}
public function execute(PhutilArgumentParser $args) {
if ($args->getArg('all')) {
return $this->executeGlobal();
} else {
return $this->executeLocal();
}
}
protected function executeLocal() {
$console = PhutilConsole::getConsole();
$daemons = $this->loadRunningDaemons();
@ -22,12 +36,22 @@ final class PhabricatorDaemonManagementStatusWorkflow
}
$status = 0;
printf(
"%-5s\t%-24s\t%-50s%s\n",
'PID',
'Started',
'Daemon',
'Arguments');
$table = id(new PhutilConsoleTable())
->addColumns(array(
'pid' => array(
'title' => 'PID',
),
'started' => array(
'title' => 'Started',
),
'daemon' => array(
'title' => 'Daemon',
),
'argv' => array(
'title' => 'Arguments',
),
));
foreach ($daemons as $daemon) {
$name = $daemon->getName();
if (!$daemon->isRunning()) {
@ -35,18 +59,67 @@ final class PhabricatorDaemonManagementStatusWorkflow
$status = 2;
$name = '<DEAD> '.$name;
}
printf(
"%5s\t%-24s\t%-50s%s\n",
$daemon->getPID(),
$daemon->getEpochStarted()
$table->addRow(array(
'pid' => $daemon->getPID(),
'started' => $daemon->getEpochStarted()
? date('M j Y, g:i:s A', $daemon->getEpochStarted())
: null,
$name,
csprintf('%LR', $daemon->getArgv()));
'daemon' => $name,
'argv' => csprintf('%LR', $daemon->getArgv()),
));
}
return $status;
$table->draw();
}
protected function executeGlobal() {
$console = PhutilConsole::getConsole();
$daemons = $this->loadAllRunningDaemons();
if (!$daemons) {
$console->writeErr(
"%s\n",
pht('There are no running Phabricator daemons.'));
return 1;
}
$status = 0;
$table = id(new PhutilConsoleTable())
->addColumns(array(
'id' => array(
'title' => 'ID',
),
'host' => array(
'title' => 'Host',
),
'pid' => array(
'title' => 'PID',
),
'started' => array(
'title' => 'Started',
),
'daemon' => array(
'title' => 'Daemon',
),
'argv' => array(
'title' => 'Arguments',
),
));
foreach ($daemons as $daemon) {
$table->addRow(array(
'id' => $daemon->getID(),
'host' => $daemon->getHost(),
'pid' => $daemon->getPID(),
'started' => date('M j Y, g:i:s A', $daemon->getDateCreated()),
'daemon' => $daemon->getDaemon(),
'argv' => csprintf('%LR', array() /* $daemon->getArgv() */),
));
}
$table->draw();
}
}

View file

@ -3,7 +3,7 @@
abstract class PhabricatorDaemonManagementWorkflow
extends PhabricatorManagementWorkflow {
protected function loadAvailableDaemonClasses() {
protected final function loadAvailableDaemonClasses() {
$loader = new PhutilSymbolLoader();
return $loader
->setAncestorClass('PhutilDaemon')
@ -11,12 +11,12 @@ abstract class PhabricatorDaemonManagementWorkflow
->selectSymbolsWithoutLoading();
}
public function getPIDDirectory() {
protected final function getPIDDirectory() {
$path = PhabricatorEnv::getEnvConfig('phd.pid-directory');
return $this->getControlDirectory($path);
}
public function getLogDirectory() {
protected final function getLogDirectory() {
$path = PhabricatorEnv::getEnvConfig('phd.log-directory');
return $this->getControlDirectory($path);
}
@ -35,7 +35,7 @@ abstract class PhabricatorDaemonManagementWorkflow
return $path;
}
public function loadRunningDaemons() {
protected final function loadRunningDaemons() {
$results = array();
$pid_dir = $this->getPIDDirectory();
@ -60,6 +60,13 @@ abstract class PhabricatorDaemonManagementWorkflow
return $results;
}
protected final function loadAllRunningDaemons() {
return id(new PhabricatorDaemonLogQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE)
->execute();
}
private function findDaemonClass($substring) {
$symbols = $this->loadAvailableDaemonClasses();
@ -93,8 +100,7 @@ abstract class PhabricatorDaemonManagementWorkflow
return head($match);
}
protected function launchDaemon($class, array $argv, $debug) {
protected final function launchDaemon($class, array $argv, $debug) {
$daemon = $this->findDaemonClass($class);
$console = PhutilConsole::getConsole();
@ -212,7 +218,7 @@ abstract class PhabricatorDaemonManagementWorkflow
}
}
protected function willLaunchDaemons() {
protected final function willLaunchDaemons() {
$console = PhutilConsole::getConsole();
$console->writeErr(pht('Preparing to launch daemons.')."\n");
@ -224,7 +230,7 @@ abstract class PhabricatorDaemonManagementWorkflow
/* -( Commands )----------------------------------------------------------- */
protected function executeStartCommand($keep_leases = false) {
protected final function executeStartCommand($keep_leases = false) {
$console = PhutilConsole::getConsole();
$running = $this->loadRunningDaemons();
@ -278,8 +284,7 @@ abstract class PhabricatorDaemonManagementWorkflow
return 0;
}
protected function executeStopCommand(array $pids) {
protected final function executeStopCommand(array $pids) {
$console = PhutilConsole::getConsole();
$daemons = $this->loadRunningDaemons();