2013-07-19 00:28:56 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorDaemonManagementStatusWorkflow
|
|
|
|
extends PhabricatorDaemonManagementWorkflow {
|
|
|
|
|
|
|
|
public function didConstruct() {
|
|
|
|
$this
|
|
|
|
->setName('status')
|
|
|
|
->setSynopsis(pht('Show status of running daemons.'))
|
2014-06-17 03:13:38 +02:00
|
|
|
->setArguments(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'all',
|
|
|
|
'help' => pht('Show the status of daemons across all hosts.'),
|
|
|
|
),
|
|
|
|
));
|
2013-07-19 00:28:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
2014-06-17 03:13:38 +02:00
|
|
|
if ($args->getArg('all')) {
|
|
|
|
return $this->executeGlobal();
|
|
|
|
} else {
|
|
|
|
return $this->executeLocal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function executeLocal() {
|
2013-07-19 00:28:56 +02:00
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
$daemons = $this->loadRunningDaemons();
|
|
|
|
|
|
|
|
if (!$daemons) {
|
|
|
|
$console->writeErr(
|
|
|
|
"%s\n",
|
2014-06-09 20:36:49 +02:00
|
|
|
pht('There are no running Phabricator daemons.'));
|
2013-07-19 00:28:56 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$status = 0;
|
2014-06-17 03:13:38 +02:00
|
|
|
$table = id(new PhutilConsoleTable())
|
|
|
|
->addColumns(array(
|
|
|
|
'pid' => array(
|
|
|
|
'title' => 'PID',
|
|
|
|
),
|
|
|
|
'started' => array(
|
|
|
|
'title' => 'Started',
|
|
|
|
),
|
|
|
|
'daemon' => array(
|
|
|
|
'title' => 'Daemon',
|
|
|
|
),
|
|
|
|
'argv' => array(
|
|
|
|
'title' => 'Arguments',
|
|
|
|
),
|
|
|
|
));
|
|
|
|
|
2013-07-19 00:28:56 +02:00
|
|
|
foreach ($daemons as $daemon) {
|
|
|
|
$name = $daemon->getName();
|
|
|
|
if (!$daemon->isRunning()) {
|
|
|
|
$daemon->updateStatus(PhabricatorDaemonLog::STATUS_DEAD);
|
|
|
|
$status = 2;
|
|
|
|
$name = '<DEAD> '.$name;
|
|
|
|
}
|
2014-06-17 03:13:38 +02:00
|
|
|
|
|
|
|
$table->addRow(array(
|
|
|
|
'pid' => $daemon->getPID(),
|
|
|
|
'started' => $daemon->getEpochStarted()
|
2013-07-19 00:28:56 +02:00
|
|
|
? date('M j Y, g:i:s A', $daemon->getEpochStarted())
|
|
|
|
: null,
|
2014-06-17 03:13:38 +02:00
|
|
|
'daemon' => $name,
|
|
|
|
'argv' => csprintf('%LR', $daemon->getArgv()),
|
|
|
|
));
|
2013-07-19 00:28:56 +02:00
|
|
|
}
|
|
|
|
|
2014-06-17 03:13:38 +02:00
|
|
|
$table->draw();
|
2013-07-19 00:28:56 +02:00
|
|
|
}
|
|
|
|
|
2014-06-17 03:13:38 +02:00
|
|
|
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();
|
|
|
|
}
|
2013-07-19 00:28:56 +02:00
|
|
|
|
|
|
|
}
|