From dde6d2491cc667dc97be54c8d87c341a806d6053 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Tue, 17 Jun 2014 11:13:38 +1000 Subject: [PATCH] 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 --- ...bricatorDaemonManagementStatusWorkflow.php | 101 +++++++++++++++--- .../PhabricatorDaemonManagementWorkflow.php | 25 +++-- 2 files changed, 102 insertions(+), 24 deletions(-) diff --git a/src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php b/src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php index dbccce3dc5..9e3637cebc 100644 --- a/src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php +++ b/src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php @@ -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 = ' '.$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(); + } } diff --git a/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php b/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php index a0e1cf575e..4aa7fae5f4 100644 --- a/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php +++ b/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php @@ -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();