Differential D20604 Diff 49170 src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php
<?php | <?php | ||||
final class PhabricatorDaemonManagementStatusWorkflow | final class PhabricatorDaemonManagementStatusWorkflow | ||||
extends PhabricatorDaemonManagementWorkflow { | extends PhabricatorDaemonManagementWorkflow { | ||||
protected function didConstruct() { | protected function didConstruct() { | ||||
$this | $this | ||||
->setName('status') | ->setName('status') | ||||
->setSynopsis(pht('Show status of running daemons.')) | ->setSynopsis(pht('Show daemon processes on this host.')); | ||||
->setArguments( | |||||
array( | |||||
array( | |||||
'name' => 'local', | |||||
'help' => pht('Show only local daemons.'), | |||||
), | |||||
)); | |||||
} | } | ||||
public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
$console = PhutilConsole::getConsole(); | $query = id(new PhutilProcessQuery()) | ||||
->withIsOverseer(true); | |||||
if ($args->getArg('local')) { | $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); | ||||
$daemons = $this->loadRunningDaemons(); | if ($instance !== null) { | ||||
$query->withInstances(array($instance)); | |||||
} | |||||
$process_refs = $query->execute(); | |||||
if (!$process_refs) { | |||||
if ($instance !== null) { | |||||
$this->logInfo( | |||||
pht('NO DAEMONS'), | |||||
pht( | |||||
'There are no running daemon processes for the current '. | |||||
'instance ("%s").', | |||||
$instance)); | |||||
} else { | } else { | ||||
$daemons = $this->loadAllRunningDaemons(); | $this->writeInfo( | ||||
pht('NO DAEMONS'), | |||||
pht('There are no running daemon processes.')); | |||||
} | } | ||||
if (!$daemons) { | |||||
$console->writeErr( | |||||
"%s\n", | |||||
pht('There are no running Phabricator daemons.')); | |||||
return 1; | return 1; | ||||
} | } | ||||
$status = 0; | |||||
$table = id(new PhutilConsoleTable()) | $table = id(new PhutilConsoleTable()) | ||||
->addColumns(array( | ->addColumns( | ||||
'id' => array( | array( | ||||
'title' => pht('Log'), | |||||
), | |||||
'daemonID' => array( | |||||
'title' => pht('Daemon'), | |||||
), | |||||
'host' => array( | |||||
'title' => pht('Host'), | |||||
), | |||||
'pid' => array( | 'pid' => array( | ||||
'title' => pht('Overseer'), | 'title' => pht('PID'), | ||||
), | |||||
'started' => array( | |||||
'title' => pht('Started'), | |||||
), | ), | ||||
'daemon' => array( | 'command' => array( | ||||
'title' => pht('Class'), | 'title' => pht('Command'), | ||||
), | |||||
'argv' => array( | |||||
'title' => pht('Arguments'), | |||||
), | ), | ||||
)); | )); | ||||
foreach ($daemons as $daemon) { | foreach ($process_refs as $process_ref) { | ||||
if ($daemon instanceof PhabricatorDaemonLog) { | $table->addRow( | ||||
$table->addRow(array( | array( | ||||
'id' => $daemon->getID(), | 'pid' => $process_ref->getPID(), | ||||
'daemonID' => $daemon->getDaemonID(), | 'command' => $process_ref->getCommand(), | ||||
'host' => $daemon->getHost(), | |||||
'pid' => $daemon->getPID(), | |||||
'started' => date('M j Y, g:i:s A', $daemon->getDateCreated()), | |||||
'daemon' => $daemon->getDaemon(), | |||||
'argv' => csprintf('%LR', $daemon->getExplicitArgv()), | |||||
)); | |||||
} else if ($daemon instanceof PhabricatorDaemonReference) { | |||||
$name = $daemon->getName(); | |||||
if (!$daemon->isRunning()) { | |||||
$daemon->updateStatus(PhabricatorDaemonLog::STATUS_DEAD); | |||||
$status = 2; | |||||
$name = pht('<DEAD> %s', $name); | |||||
} | |||||
$daemon_log = $daemon->getDaemonLog(); | |||||
$id = null; | |||||
$daemon_id = null; | |||||
if ($daemon_log) { | |||||
$id = $daemon_log->getID(); | |||||
$daemon_id = $daemon_log->getDaemonID(); | |||||
} | |||||
$table->addRow(array( | |||||
'id' => $id, | |||||
'daemonID' => $daemon_id, | |||||
'host' => 'localhost', | |||||
'pid' => $daemon->getPID(), | |||||
'started' => $daemon->getEpochStarted() | |||||
? date('M j Y, g:i:s A', $daemon->getEpochStarted()) | |||||
: null, | |||||
'daemon' => $name, | |||||
'argv' => csprintf('%LR', $daemon->getArgv()), | |||||
)); | )); | ||||
} | } | ||||
} | |||||
$table->draw(); | $table->draw(); | ||||
return 0; | |||||
} | } | ||||
} | } |