1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-04-04 08:28:22 +02:00

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

This reverts commit 0ccebbe4b1.
This commit is contained in:
epriestley 2014-06-16 17:43:45 -07:00
parent 0ccebbe4b1
commit a10f969919
3 changed files with 39 additions and 113 deletions

View file

@ -22,22 +22,12 @@ final class PhabricatorDaemonManagementStatusWorkflow
} }
$status = 0; $status = 0;
$table = id(new PhutilConsoleTable()) printf(
->addColumns(array( "%-5s\t%-24s\t%-50s%s\n",
'pid' => array( 'PID',
'title' => 'PID', 'Started',
), 'Daemon',
'started' => array( 'Arguments');
'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()) {
@ -45,67 +35,18 @@ final class PhabricatorDaemonManagementStatusWorkflow
$status = 2; $status = 2;
$name = '<DEAD> '.$name; $name = '<DEAD> '.$name;
} }
printf(
$table->addRow(array( "%5s\t%-24s\t%-50s%s\n",
'pid' => $daemon->getPID(), $daemon->getPID(),
'started' => $daemon->getEpochStarted() $daemon->getEpochStarted()
? date('M j Y, g:i:s A', $daemon->getEpochStarted()) ? date('M j Y, g:i:s A', $daemon->getEpochStarted())
: null, : null,
'daemon' => $name, $name,
'argv' => csprintf('%LR', $daemon->getArgv()), 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();
}
} }

View file

@ -3,7 +3,7 @@
abstract class PhabricatorDaemonManagementWorkflow abstract class PhabricatorDaemonManagementWorkflow
extends PhabricatorManagementWorkflow { extends PhabricatorManagementWorkflow {
protected final function loadAvailableDaemonClasses() { protected 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();
} }
protected final function getPIDDirectory() { public function getPIDDirectory() {
$path = PhabricatorEnv::getEnvConfig('phd.pid-directory'); $path = PhabricatorEnv::getEnvConfig('phd.pid-directory');
return $this->getControlDirectory($path); return $this->getControlDirectory($path);
} }
protected final function getLogDirectory() { public function getLogDirectory() {
$path = PhabricatorEnv::getEnvConfig('phd.log-directory'); $path = PhabricatorEnv::getEnvConfig('phd.log-directory');
return $this->getControlDirectory($path); return $this->getControlDirectory($path);
} }
@ -35,9 +35,8 @@ abstract class PhabricatorDaemonManagementWorkflow
return $path; return $path;
} }
protected final function loadRunningDaemons() { public function loadRunningDaemons() {
$results = array(); $results = array();
$ids = array();
$pid_dir = $this->getPIDDirectory(); $pid_dir = $this->getPIDDirectory();
$pid_files = Filesystem::listDirectory($pid_dir); $pid_files = Filesystem::listDirectory($pid_dir);
@ -46,17 +45,19 @@ abstract class PhabricatorDaemonManagementWorkflow
} }
foreach ($pid_files as $pid_file) { foreach ($pid_files as $pid_file) {
$results[] = PhabricatorDaemonReference::newFromDictionary( $pid_data = Filesystem::readFile($pid_dir.'/'.$pid_file);
$pid_dir.'/'.$pid_file); $dict = json_decode($pid_data, true);
$ids[] = $ref->getDaemonLog()->getID(); 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()) return $results;
->setViewer(PhabricatorUser::getOmnipotentUser())
->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE)
->execute();
} }
private function findDaemonClass($substring) { private function findDaemonClass($substring) {
@ -92,7 +93,8 @@ 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();
@ -210,7 +212,7 @@ abstract class PhabricatorDaemonManagementWorkflow
} }
} }
protected final function willLaunchDaemons() { protected function willLaunchDaemons() {
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
$console->writeErr(pht('Preparing to launch daemons.')."\n"); $console->writeErr(pht('Preparing to launch daemons.')."\n");
@ -222,7 +224,7 @@ abstract class PhabricatorDaemonManagementWorkflow
/* -( Commands )----------------------------------------------------------- */ /* -( Commands )----------------------------------------------------------- */
protected final function executeStartCommand($keep_leases = false) { protected function executeStartCommand($keep_leases = false) {
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
$running = $this->loadRunningDaemons(); $running = $this->loadRunningDaemons();
@ -276,7 +278,8 @@ 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();

View file

@ -10,19 +10,6 @@ final class PhabricatorDaemonReference {
private $daemonLog; 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) { public static function newFromDictionary(array $dict) {
$ref = new PhabricatorDaemonReference(); $ref = new PhabricatorDaemonReference();
@ -31,12 +18,6 @@ final class PhabricatorDaemonReference {
$ref->pid = idx($dict, 'pid'); $ref->pid = idx($dict, 'pid');
$ref->start = idx($dict, 'start'); $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; return $ref;
} }
@ -85,12 +66,13 @@ final class PhabricatorDaemonReference {
return $this->start; return $this->start;
} }
public function getPIDFile() { public function setPIDFile($pid_file) {
return $this->pidFile; $this->pidFile = $pid_file;
return $this;
} }
public function getDaemonLog() { public function getPIDFile() {
return $this->daemonLog; return $this->pidFile;
} }
public function isRunning() { public function isRunning() {