2011-03-15 21:38:14 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorDaemonLogViewController
|
|
|
|
extends PhabricatorDaemonController {
|
2011-03-15 21:38:14 +01:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
2011-03-27 07:55:18 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
2011-03-15 21:38:14 +01:00
|
|
|
|
2013-07-23 21:30:58 +02:00
|
|
|
$log = id(new PhabricatorDaemonLogQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
2011-03-15 21:38:14 +01:00
|
|
|
if (!$log) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$events = id(new PhabricatorDaemonLogEvent())->loadAllWhere(
|
2011-05-03 02:05:22 +02:00
|
|
|
'logID = %d ORDER BY id DESC LIMIT 1000',
|
2011-03-15 21:38:14 +01:00
|
|
|
$log->getID());
|
|
|
|
|
2013-07-23 21:10:41 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('Daemon %s', $log->getID()));
|
2013-07-23 21:10:41 +02:00
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
2013-07-23 21:10:41 +02:00
|
|
|
->setHeader($log->getDaemon());
|
|
|
|
|
2014-01-14 23:09:52 +01:00
|
|
|
$tag = id(new PHUITagView())
|
|
|
|
->setType(PHUITagView::TYPE_STATE);
|
2013-07-23 21:10:41 +02:00
|
|
|
|
|
|
|
$status = $log->getStatus();
|
|
|
|
switch ($status) {
|
|
|
|
case PhabricatorDaemonLog::STATUS_UNKNOWN:
|
2014-01-14 23:09:52 +01:00
|
|
|
$tag->setBackgroundColor(PHUITagView::COLOR_ORANGE);
|
2013-07-23 21:10:41 +02:00
|
|
|
$tag->setName(pht('Unknown'));
|
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_RUNNING:
|
2014-01-14 23:09:52 +01:00
|
|
|
$tag->setBackgroundColor(PHUITagView::COLOR_GREEN);
|
2013-07-23 21:10:41 +02:00
|
|
|
$tag->setName(pht('Running'));
|
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_DEAD:
|
2014-01-14 23:09:52 +01:00
|
|
|
$tag->setBackgroundColor(PHUITagView::COLOR_RED);
|
2013-07-23 21:10:41 +02:00
|
|
|
$tag->setName(pht('Dead'));
|
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_WAIT:
|
2014-01-14 23:09:52 +01:00
|
|
|
$tag->setBackgroundColor(PHUITagView::COLOR_BLUE);
|
2013-07-23 21:10:41 +02:00
|
|
|
$tag->setName(pht('Waiting'));
|
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_EXITED:
|
2014-01-14 23:09:52 +01:00
|
|
|
$tag->setBackgroundColor(PHUITagView::COLOR_GREY);
|
2013-07-23 21:10:41 +02:00
|
|
|
$tag->setName(pht('Exited'));
|
|
|
|
break;
|
2012-10-05 01:50:12 +02:00
|
|
|
}
|
2011-03-27 07:55:18 +02:00
|
|
|
|
2013-07-23 21:10:41 +02:00
|
|
|
$header->addTag($tag);
|
|
|
|
|
|
|
|
$properties = $this->buildPropertyListView($log);
|
|
|
|
|
|
|
|
$event_view = id(new PhabricatorDaemonLogEventsView())
|
2011-03-27 07:55:18 +02:00
|
|
|
->setUser($user)
|
2013-07-23 21:10:41 +02:00
|
|
|
->setEvents($events);
|
|
|
|
|
|
|
|
$event_panel = new AphrontPanelView();
|
|
|
|
$event_panel->setNoBackground();
|
|
|
|
$event_panel->appendChild($event_view);
|
2012-08-14 00:27:45 +02:00
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->addPropertyList($properties);
|
|
|
|
|
2012-08-14 00:27:45 +02:00
|
|
|
return $this->buildApplicationPage(
|
2013-07-23 21:10:41 +02:00
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-10-11 16:53:56 +02:00
|
|
|
$object_box,
|
2013-07-23 21:10:41 +02:00
|
|
|
$event_panel,
|
|
|
|
),
|
2011-03-15 21:38:14 +01:00
|
|
|
array(
|
2013-02-27 04:51:36 +01:00
|
|
|
'title' => pht('Daemon Log'),
|
2011-03-15 21:38:14 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2013-07-23 21:10:41 +02:00
|
|
|
private function buildPropertyListView(PhabricatorDaemonLog $daemon) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$view = id(new PHUIPropertyListView())
|
2013-07-23 21:10:41 +02:00
|
|
|
->setUser($viewer);
|
|
|
|
|
2013-07-23 21:48:45 +02:00
|
|
|
$id = $daemon->getID();
|
2013-07-23 21:10:41 +02:00
|
|
|
$c_epoch = $daemon->getDateCreated();
|
|
|
|
$u_epoch = $daemon->getDateModified();
|
|
|
|
|
|
|
|
$unknown_time = PhabricatorDaemonLogQuery::getTimeUntilUnknown();
|
|
|
|
$dead_time = PhabricatorDaemonLogQuery::getTimeUntilDead();
|
2013-07-23 21:11:20 +02:00
|
|
|
$wait_time = PhutilDaemonOverseer::RESTART_WAIT;
|
2013-07-23 21:10:41 +02:00
|
|
|
|
|
|
|
$details = null;
|
|
|
|
$status = $daemon->getStatus();
|
|
|
|
switch ($status) {
|
|
|
|
case PhabricatorDaemonLog::STATUS_RUNNING:
|
|
|
|
$details = pht(
|
|
|
|
'This daemon is running normally and reported a status update '.
|
|
|
|
'recently (within %s).',
|
|
|
|
phabricator_format_relative_time($unknown_time));
|
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_UNKNOWN:
|
|
|
|
$details = pht(
|
|
|
|
'This daemon has not reported a status update recently (within %s). '.
|
|
|
|
'It may have exited abruptly. After %s, it will be presumed dead.',
|
|
|
|
phabricator_format_relative_time($unknown_time),
|
|
|
|
phabricator_format_relative_time($dead_time));
|
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_DEAD:
|
|
|
|
$details = pht(
|
|
|
|
'This daemon did not report a status update for %s. It is '.
|
|
|
|
'presumed dead. Usually, this indicates that the daemon was '.
|
|
|
|
'killed or otherwise exited abruptly with an error. You may '.
|
|
|
|
'need to restart it.',
|
|
|
|
phabricator_format_relative_time($dead_time));
|
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_WAIT:
|
|
|
|
$details = pht(
|
|
|
|
'This daemon is running normally and reported a status update '.
|
|
|
|
'recently (within %s). However, it encountered an error while '.
|
2013-07-23 21:11:20 +02:00
|
|
|
'doing work and is waiting a little while (%s) to resume '.
|
|
|
|
'processing. After encountering an error, daemons wait before '.
|
|
|
|
'resuming work to avoid overloading services.',
|
|
|
|
phabricator_format_relative_time($unknown_time),
|
|
|
|
phabricator_format_relative_time($wait_time));
|
2013-07-23 21:10:41 +02:00
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_EXITED:
|
|
|
|
$details = pht(
|
|
|
|
'This daemon exited normally and is no longer running.');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->addProperty(pht('Status Details'), $details);
|
|
|
|
|
|
|
|
$view->addProperty(pht('Daemon Class'), $daemon->getDaemon());
|
|
|
|
$view->addProperty(pht('Host'), $daemon->getHost());
|
|
|
|
$view->addProperty(pht('PID'), $daemon->getPID());
|
|
|
|
$view->addProperty(pht('Started'), phabricator_datetime($c_epoch, $viewer));
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Seen'),
|
|
|
|
pht(
|
|
|
|
'%s ago (%s)',
|
|
|
|
phabricator_format_relative_time(time() - $u_epoch),
|
|
|
|
phabricator_datetime($u_epoch, $viewer)));
|
|
|
|
|
|
|
|
$argv = $daemon->getArgv();
|
|
|
|
if (is_array($argv)) {
|
|
|
|
$argv = implode("\n", $argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Argv'),
|
|
|
|
phutil_tag(
|
|
|
|
'textarea',
|
|
|
|
array(
|
|
|
|
'style' => 'width: 100%; height: 12em;',
|
|
|
|
),
|
|
|
|
$argv));
|
|
|
|
|
2013-07-23 21:48:45 +02:00
|
|
|
$view->addProperty(
|
|
|
|
pht('View Full Logs'),
|
|
|
|
phutil_tag(
|
|
|
|
'tt',
|
|
|
|
array(),
|
|
|
|
"phabricator/ $ ./bin/phd log {$id}"));
|
|
|
|
|
2013-07-23 21:10:41 +02:00
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2011-03-15 21:38:14 +01:00
|
|
|
}
|