mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +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:
parent
a10f969919
commit
dde6d2491c
2 changed files with 102 additions and 24 deletions
|
@ -7,10 +7,24 @@ final class PhabricatorDaemonManagementStatusWorkflow
|
||||||
$this
|
$this
|
||||||
->setName('status')
|
->setName('status')
|
||||||
->setSynopsis(pht('Show status of running daemons.'))
|
->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) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
|
if ($args->getArg('all')) {
|
||||||
|
return $this->executeGlobal();
|
||||||
|
} else {
|
||||||
|
return $this->executeLocal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function executeLocal() {
|
||||||
$console = PhutilConsole::getConsole();
|
$console = PhutilConsole::getConsole();
|
||||||
$daemons = $this->loadRunningDaemons();
|
$daemons = $this->loadRunningDaemons();
|
||||||
|
|
||||||
|
@ -22,12 +36,22 @@ final class PhabricatorDaemonManagementStatusWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = 0;
|
$status = 0;
|
||||||
printf(
|
$table = id(new PhutilConsoleTable())
|
||||||
"%-5s\t%-24s\t%-50s%s\n",
|
->addColumns(array(
|
||||||
'PID',
|
'pid' => array(
|
||||||
'Started',
|
'title' => 'PID',
|
||||||
'Daemon',
|
),
|
||||||
'Arguments');
|
'started' => array(
|
||||||
|
'title' => 'Started',
|
||||||
|
),
|
||||||
|
'daemon' => array(
|
||||||
|
'title' => 'Daemon',
|
||||||
|
),
|
||||||
|
'argv' => array(
|
||||||
|
'title' => 'Arguments',
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
foreach ($daemons as $daemon) {
|
foreach ($daemons as $daemon) {
|
||||||
$name = $daemon->getName();
|
$name = $daemon->getName();
|
||||||
if (!$daemon->isRunning()) {
|
if (!$daemon->isRunning()) {
|
||||||
|
@ -35,18 +59,67 @@ final class PhabricatorDaemonManagementStatusWorkflow
|
||||||
$status = 2;
|
$status = 2;
|
||||||
$name = '<DEAD> '.$name;
|
$name = '<DEAD> '.$name;
|
||||||
}
|
}
|
||||||
printf(
|
|
||||||
"%5s\t%-24s\t%-50s%s\n",
|
$table->addRow(array(
|
||||||
$daemon->getPID(),
|
'pid' => $daemon->getPID(),
|
||||||
$daemon->getEpochStarted()
|
'started' => $daemon->getEpochStarted()
|
||||||
? date('M j Y, g:i:s A', $daemon->getEpochStarted())
|
? date('M j Y, g:i:s A', $daemon->getEpochStarted())
|
||||||
: null,
|
: null,
|
||||||
$name,
|
'daemon' => $name,
|
||||||
csprintf('%LR', $daemon->getArgv()));
|
'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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
abstract class PhabricatorDaemonManagementWorkflow
|
abstract class PhabricatorDaemonManagementWorkflow
|
||||||
extends PhabricatorManagementWorkflow {
|
extends PhabricatorManagementWorkflow {
|
||||||
|
|
||||||
protected function loadAvailableDaemonClasses() {
|
protected final function loadAvailableDaemonClasses() {
|
||||||
$loader = new PhutilSymbolLoader();
|
$loader = new PhutilSymbolLoader();
|
||||||
return $loader
|
return $loader
|
||||||
->setAncestorClass('PhutilDaemon')
|
->setAncestorClass('PhutilDaemon')
|
||||||
|
@ -11,12 +11,12 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
->selectSymbolsWithoutLoading();
|
->selectSymbolsWithoutLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPIDDirectory() {
|
protected final function getPIDDirectory() {
|
||||||
$path = PhabricatorEnv::getEnvConfig('phd.pid-directory');
|
$path = PhabricatorEnv::getEnvConfig('phd.pid-directory');
|
||||||
return $this->getControlDirectory($path);
|
return $this->getControlDirectory($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogDirectory() {
|
protected final function getLogDirectory() {
|
||||||
$path = PhabricatorEnv::getEnvConfig('phd.log-directory');
|
$path = PhabricatorEnv::getEnvConfig('phd.log-directory');
|
||||||
return $this->getControlDirectory($path);
|
return $this->getControlDirectory($path);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadRunningDaemons() {
|
protected final function loadRunningDaemons() {
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
$pid_dir = $this->getPIDDirectory();
|
$pid_dir = $this->getPIDDirectory();
|
||||||
|
@ -60,6 +60,13 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final function loadAllRunningDaemons() {
|
||||||
|
return id(new PhabricatorDaemonLogQuery())
|
||||||
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
|
->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE)
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
private function findDaemonClass($substring) {
|
private function findDaemonClass($substring) {
|
||||||
$symbols = $this->loadAvailableDaemonClasses();
|
$symbols = $this->loadAvailableDaemonClasses();
|
||||||
|
|
||||||
|
@ -93,8 +100,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
return head($match);
|
return head($match);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final function launchDaemon($class, array $argv, $debug) {
|
||||||
protected function launchDaemon($class, array $argv, $debug) {
|
|
||||||
$daemon = $this->findDaemonClass($class);
|
$daemon = $this->findDaemonClass($class);
|
||||||
$console = PhutilConsole::getConsole();
|
$console = PhutilConsole::getConsole();
|
||||||
|
|
||||||
|
@ -212,7 +218,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function willLaunchDaemons() {
|
protected final function willLaunchDaemons() {
|
||||||
$console = PhutilConsole::getConsole();
|
$console = PhutilConsole::getConsole();
|
||||||
$console->writeErr(pht('Preparing to launch daemons.')."\n");
|
$console->writeErr(pht('Preparing to launch daemons.')."\n");
|
||||||
|
|
||||||
|
@ -224,7 +230,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
/* -( Commands )----------------------------------------------------------- */
|
/* -( Commands )----------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
protected function executeStartCommand($keep_leases = false) {
|
protected final function executeStartCommand($keep_leases = false) {
|
||||||
$console = PhutilConsole::getConsole();
|
$console = PhutilConsole::getConsole();
|
||||||
|
|
||||||
$running = $this->loadRunningDaemons();
|
$running = $this->loadRunningDaemons();
|
||||||
|
@ -278,8 +284,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final function executeStopCommand(array $pids) {
|
||||||
protected function executeStopCommand(array $pids) {
|
|
||||||
$console = PhutilConsole::getConsole();
|
$console = PhutilConsole::getConsole();
|
||||||
|
|
||||||
$daemons = $this->loadRunningDaemons();
|
$daemons = $this->loadRunningDaemons();
|
||||||
|
|
Loading…
Reference in a new issue