From a10f969919a90204a6f94262af70cdff687812af Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 16 Jun 2014 17:43:45 -0700 Subject: [PATCH] Revert "Query daemons across all hosts with `./bin/phd status --all`." This reverts commit 0ccebbe4b1ddd7b0e3e4b737e557570a3ced7dfa. --- ...bricatorDaemonManagementStatusWorkflow.php | 85 +++---------------- .../PhabricatorDaemonManagementWorkflow.php | 39 +++++---- .../control/PhabricatorDaemonReference.php | 28 ++---- 3 files changed, 39 insertions(+), 113 deletions(-) diff --git a/src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php b/src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php index 18132ab15e..dbccce3dc5 100644 --- a/src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php +++ b/src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php @@ -22,22 +22,12 @@ final class PhabricatorDaemonManagementStatusWorkflow } $status = 0; - $table = id(new PhutilConsoleTable()) - ->addColumns(array( - 'pid' => array( - 'title' => 'PID', - ), - 'started' => array( - 'title' => 'Started', - ), - 'daemon' => array( - 'title' => 'Daemon', - ), - 'argv' => array( - 'title' => 'Arguments', - ), - )); - + printf( + "%-5s\t%-24s\t%-50s%s\n", + 'PID', + 'Started', + 'Daemon', + 'Arguments'); foreach ($daemons as $daemon) { $name = $daemon->getName(); if (!$daemon->isRunning()) { @@ -45,67 +35,18 @@ final class PhabricatorDaemonManagementStatusWorkflow $status = 2; $name = ' '.$name; } - - $table->addRow(array( - 'pid' => $daemon->getPID(), - 'started' => $daemon->getEpochStarted() + printf( + "%5s\t%-24s\t%-50s%s\n", + $daemon->getPID(), + $daemon->getEpochStarted() ? date('M j Y, g:i:s A', $daemon->getEpochStarted()) : null, - 'daemon' => $name, - 'argv' => csprintf('%LR', $daemon->getArgv()), - )); + $name, + csprintf('%LR', $daemon->getArgv())); } - $table->draw(); + return $status; } - 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 6a7e3bd435..a0e1cf575e 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 final function loadAvailableDaemonClasses() { + protected function loadAvailableDaemonClasses() { $loader = new PhutilSymbolLoader(); return $loader ->setAncestorClass('PhutilDaemon') @@ -11,12 +11,12 @@ abstract class PhabricatorDaemonManagementWorkflow ->selectSymbolsWithoutLoading(); } - protected final function getPIDDirectory() { + public function getPIDDirectory() { $path = PhabricatorEnv::getEnvConfig('phd.pid-directory'); return $this->getControlDirectory($path); } - protected final function getLogDirectory() { + public function getLogDirectory() { $path = PhabricatorEnv::getEnvConfig('phd.log-directory'); return $this->getControlDirectory($path); } @@ -35,9 +35,8 @@ abstract class PhabricatorDaemonManagementWorkflow return $path; } - protected final function loadRunningDaemons() { + public function loadRunningDaemons() { $results = array(); - $ids = array(); $pid_dir = $this->getPIDDirectory(); $pid_files = Filesystem::listDirectory($pid_dir); @@ -46,17 +45,19 @@ abstract class PhabricatorDaemonManagementWorkflow } foreach ($pid_files as $pid_file) { - $results[] = PhabricatorDaemonReference::newFromDictionary( - $pid_dir.'/'.$pid_file); - $ids[] = $ref->getDaemonLog()->getID(); + $pid_data = Filesystem::readFile($pid_dir.'/'.$pid_file); + $dict = json_decode($pid_data, true); + if (!is_array($dict)) { + // Just return a hanging reference, since control code needs to be + // robust against unusual system states. + $dict = array(); + } + $ref = PhabricatorDaemonReference::newFromDictionary($dict); + $ref->setPIDFile($pid_dir.'/'.$pid_file); + $results[] = $ref; } - $other = id(new PhabricatorDaemonLogQuery()) - ->setViewer(PhabricatorUser::getOmnipotentUser()) - ->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE) - ->execute(); - - + return $results; } private function findDaemonClass($substring) { @@ -92,7 +93,8 @@ abstract class PhabricatorDaemonManagementWorkflow return head($match); } - protected final function launchDaemon($class, array $argv, $debug) { + + protected function launchDaemon($class, array $argv, $debug) { $daemon = $this->findDaemonClass($class); $console = PhutilConsole::getConsole(); @@ -210,7 +212,7 @@ abstract class PhabricatorDaemonManagementWorkflow } } - protected final function willLaunchDaemons() { + protected function willLaunchDaemons() { $console = PhutilConsole::getConsole(); $console->writeErr(pht('Preparing to launch daemons.')."\n"); @@ -222,7 +224,7 @@ abstract class PhabricatorDaemonManagementWorkflow /* -( Commands )----------------------------------------------------------- */ - protected final function executeStartCommand($keep_leases = false) { + protected function executeStartCommand($keep_leases = false) { $console = PhutilConsole::getConsole(); $running = $this->loadRunningDaemons(); @@ -276,7 +278,8 @@ abstract class PhabricatorDaemonManagementWorkflow return 0; } - protected final function executeStopCommand(array $pids) { + + protected function executeStopCommand(array $pids) { $console = PhutilConsole::getConsole(); $daemons = $this->loadRunningDaemons(); diff --git a/src/infrastructure/daemon/control/PhabricatorDaemonReference.php b/src/infrastructure/daemon/control/PhabricatorDaemonReference.php index a2a71228a7..679680a62e 100644 --- a/src/infrastructure/daemon/control/PhabricatorDaemonReference.php +++ b/src/infrastructure/daemon/control/PhabricatorDaemonReference.php @@ -10,19 +10,6 @@ final class PhabricatorDaemonReference { private $daemonLog; - public static function newFromFile($path) { - $pid_data = Filesystem::readFile($path); - $dict = json_decode($pid_data, true); - if (!is_array($dict)) { - // Just return a hanging reference, since control code needs to be - // robust against unusual system states. - $dict = array(); - } - $ref = self::newFromDictionary($dict); - $ref->pidFile = $path; - return $ref; - } - public static function newFromDictionary(array $dict) { $ref = new PhabricatorDaemonReference(); @@ -31,12 +18,6 @@ final class PhabricatorDaemonReference { $ref->pid = idx($dict, 'pid'); $ref->start = idx($dict, 'start'); - $this->daemonLog = id(new PhabricatorDaemonLog())->loadOneWhere( - 'daemon = %s AND pid = %d AND dateCreated = %d', - $this->name, - $this->pid, - $this->start); - return $ref; } @@ -85,12 +66,13 @@ final class PhabricatorDaemonReference { return $this->start; } - public function getPIDFile() { - return $this->pidFile; + public function setPIDFile($pid_file) { + $this->pidFile = $pid_file; + return $this; } - public function getDaemonLog() { - return $this->daemonLog; + public function getPIDFile() { + return $this->pidFile; } public function isRunning() {