mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-01 19:22:42 +01:00
ddd8c9c567
Summary: It is sometimes useful to use `./bin/phd status` as a means to determine if daemons //are// actually running on the current host. For example, a common practice in upstart scripts is something similar to `./bin/phd status || ./bin/phd status`. Test Plan: ``` > ./bin/phd status ID Host PID Started Daemon Arguments 1162 ip-10-127-58-93 4046 Jun 20 2014, 3:17:43 AM PhabricatorFactDaemon 1161 ip-10-127-58-93 3984 Jun 20 2014, 3:17:43 AM PhabricatorTaskmasterDaemon 1160 ip-10-127-58-93 3973 Jun 20 2014, 3:17:42 AM PhabricatorTaskmasterDaemon 1159 ip-10-127-58-93 3968 Jun 20 2014, 3:17:42 AM PhabricatorTaskmasterDaemon 1158 ip-10-127-58-93 3943 Jun 20 2014, 3:17:42 AM PhabricatorTaskmasterDaemon 1157 ip-10-127-58-93 3914 Jun 20 2014, 3:17:41 AM PhabricatorGarbageCollectorDaemon 1156 ip-10-127-58-93 3909 Jun 20 2014, 3:17:41 AM PhabricatorRepositoryPullLocalDaemon > ./bin/phd status --local There are no running Phabricator daemons. ``` Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9645
99 lines
2.5 KiB
PHP
99 lines
2.5 KiB
PHP
<?php
|
|
|
|
final class PhabricatorDaemonManagementStatusWorkflow
|
|
extends PhabricatorDaemonManagementWorkflow {
|
|
|
|
public function didConstruct() {
|
|
$this
|
|
->setName('status')
|
|
->setSynopsis(pht('Show status of running daemons.'))
|
|
->setArguments(
|
|
array(
|
|
array(
|
|
'name' => 'local',
|
|
'help' => pht('Show only local daemons.'),
|
|
),
|
|
));
|
|
}
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
if ($args->getArg('local')) {
|
|
$daemons = $this->loadRunningDaemons();
|
|
} else {
|
|
$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) {
|
|
if ($daemon instanceof PhabricatorDaemonLog) {
|
|
$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', $daemon->getExplicitArgv()),
|
|
));
|
|
} else if ($daemon instanceof PhabricatorDaemonReference) {
|
|
$name = $daemon->getName();
|
|
if (!$daemon->isRunning()) {
|
|
$daemon->updateStatus(PhabricatorDaemonLog::STATUS_DEAD);
|
|
$status = 2;
|
|
$name = '<DEAD> '.$name;
|
|
}
|
|
|
|
$daemon_log = $daemon->getDaemonLog();
|
|
$id = null;
|
|
if ($daemon_log) {
|
|
$id = $daemon_log->getID();
|
|
}
|
|
|
|
$table->addRow(array(
|
|
'id' => $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();
|
|
}
|
|
|
|
}
|