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
|
|
|
|
2015-08-10 18:07:40 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2011-03-15 21:38:14 +01:00
|
|
|
|
2013-07-23 21:30:58 +02:00
|
|
|
$log = id(new PhabricatorDaemonLogQuery())
|
2015-08-10 18:07:40 +02:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
2014-01-21 23:04:12 +01:00
|
|
|
->setAllowStatusWrites(true)
|
2013-07-23 21:30:58 +02:00
|
|
|
->executeOne();
|
2011-03-15 21:38:14 +01:00
|
|
|
if (!$log) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
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()));
|
2016-04-02 19:18:52 +02:00
|
|
|
$crumbs->setBorder(true);
|
2013-07-23 21:10:41 +02:00
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
2016-04-02 19:18:52 +02:00
|
|
|
->setHeader($log->getDaemon())
|
|
|
|
->setHeaderIcon('fa-pied-piper-alt');
|
2013-07-23 21:10:41 +02:00
|
|
|
|
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:
|
2016-04-02 19:18:52 +02:00
|
|
|
$color = 'orange';
|
|
|
|
$name = pht('Unknown');
|
|
|
|
$icon = 'fa-warning';
|
2013-07-23 21:10:41 +02:00
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_RUNNING:
|
2016-04-02 19:18:52 +02:00
|
|
|
$color = 'green';
|
|
|
|
$name = pht('Running');
|
|
|
|
$icon = 'fa-rocket';
|
2013-07-23 21:10:41 +02:00
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_DEAD:
|
2016-04-02 19:18:52 +02:00
|
|
|
$color = 'red';
|
|
|
|
$name = pht('Dead');
|
|
|
|
$icon = 'fa-times';
|
2013-07-23 21:10:41 +02:00
|
|
|
break;
|
|
|
|
case PhabricatorDaemonLog::STATUS_WAIT:
|
2016-04-02 19:18:52 +02:00
|
|
|
$color = 'blue';
|
|
|
|
$name = pht('Waiting');
|
|
|
|
$icon = 'fa-clock-o';
|
2013-07-23 21:10:41 +02:00
|
|
|
break;
|
Send graceful shutdown signals to daemons in Phabricator
Summary:
Fixes T5855. Adds a `--graceful N` flag to `phd stop` and `phd restart`.
`phd` will send SIGINT, wait `N` seconds, SIGTERM, wait 15 seconds, and SIGKILL. By default, `N` is 15.
Test Plan:
- Ran `bin/phd debug ...` and used `^C` to interrupt daemons. Saw graceful shutdown behavior, and abrupt termination on multiple `^C`.
- Ran `bin/phd start`, `bin/phd stop` and `bin/phd restart` with `--graceful` set to various things, notably `0`. Saw graceful shutdowns on the CLI and in the web UI. With `0`, abrupt shutdowns.
Reviewers: btrahan, hach-que
Reviewed By: hach-que
Subscribers: epriestley
Maniphest Tasks: T5855
Differential Revision: https://secure.phabricator.com/D10228
2014-08-12 05:18:31 +02:00
|
|
|
case PhabricatorDaemonLog::STATUS_EXITING:
|
2016-04-02 19:18:52 +02:00
|
|
|
$color = 'yellow';
|
|
|
|
$name = pht('Exiting');
|
|
|
|
$icon = 'fa-check';
|
Send graceful shutdown signals to daemons in Phabricator
Summary:
Fixes T5855. Adds a `--graceful N` flag to `phd stop` and `phd restart`.
`phd` will send SIGINT, wait `N` seconds, SIGTERM, wait 15 seconds, and SIGKILL. By default, `N` is 15.
Test Plan:
- Ran `bin/phd debug ...` and used `^C` to interrupt daemons. Saw graceful shutdown behavior, and abrupt termination on multiple `^C`.
- Ran `bin/phd start`, `bin/phd stop` and `bin/phd restart` with `--graceful` set to various things, notably `0`. Saw graceful shutdowns on the CLI and in the web UI. With `0`, abrupt shutdowns.
Reviewers: btrahan, hach-que
Reviewed By: hach-que
Subscribers: epriestley
Maniphest Tasks: T5855
Differential Revision: https://secure.phabricator.com/D10228
2014-08-12 05:18:31 +02:00
|
|
|
break;
|
2013-07-23 21:10:41 +02:00
|
|
|
case PhabricatorDaemonLog::STATUS_EXITED:
|
2016-04-02 19:18:52 +02:00
|
|
|
$color = 'bluegrey';
|
|
|
|
$name = pht('Exited');
|
|
|
|
$icon = 'fa-check';
|
2013-07-23 21:10:41 +02:00
|
|
|
break;
|
2012-10-05 01:50:12 +02:00
|
|
|
}
|
2011-03-27 07:55:18 +02:00
|
|
|
|
2016-04-02 19:18:52 +02:00
|
|
|
$header->setStatus($icon, $color, $name);
|
2013-07-23 21:10:41 +02:00
|
|
|
|
|
|
|
$properties = $this->buildPropertyListView($log);
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
2016-04-15 21:00:34 +02:00
|
|
|
->setHeaderText(pht('Daemon Details'))
|
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
2013-10-11 16:53:56 +02:00
|
|
|
->addPropertyList($properties);
|
|
|
|
|
2016-04-02 19:18:52 +02:00
|
|
|
$view = id(new PHUITwoColumnView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setFooter(array(
|
2013-10-11 16:53:56 +02:00
|
|
|
$object_box,
|
2011-03-15 21:38:14 +01:00
|
|
|
));
|
2016-04-02 19:18:52 +02:00
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle(pht('Daemon Log'))
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild($view);
|
|
|
|
|
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();
|
2015-02-22 16:11:43 +01:00
|
|
|
$wait_time = PhutilDaemonHandle::getWaitBeforeRestart();
|
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).',
|
2014-07-13 04:03:17 +02:00
|
|
|
phutil_format_relative_time($unknown_time));
|
2013-07-23 21:10:41 +02:00
|
|
|
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.',
|
2014-07-13 04:03:17 +02:00
|
|
|
phutil_format_relative_time($unknown_time),
|
|
|
|
phutil_format_relative_time($dead_time));
|
2013-07-23 21:10:41 +02:00
|
|
|
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.',
|
2014-07-13 04:03:17 +02:00
|
|
|
phutil_format_relative_time($dead_time));
|
2013-07-23 21:10:41 +02:00
|
|
|
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.',
|
2014-07-13 04:03:17 +02:00
|
|
|
phutil_format_relative_time($unknown_time),
|
|
|
|
phutil_format_relative_time($wait_time));
|
2013-07-23 21:10:41 +02:00
|
|
|
break;
|
Send graceful shutdown signals to daemons in Phabricator
Summary:
Fixes T5855. Adds a `--graceful N` flag to `phd stop` and `phd restart`.
`phd` will send SIGINT, wait `N` seconds, SIGTERM, wait 15 seconds, and SIGKILL. By default, `N` is 15.
Test Plan:
- Ran `bin/phd debug ...` and used `^C` to interrupt daemons. Saw graceful shutdown behavior, and abrupt termination on multiple `^C`.
- Ran `bin/phd start`, `bin/phd stop` and `bin/phd restart` with `--graceful` set to various things, notably `0`. Saw graceful shutdowns on the CLI and in the web UI. With `0`, abrupt shutdowns.
Reviewers: btrahan, hach-que
Reviewed By: hach-que
Subscribers: epriestley
Maniphest Tasks: T5855
Differential Revision: https://secure.phabricator.com/D10228
2014-08-12 05:18:31 +02:00
|
|
|
case PhabricatorDaemonLog::STATUS_EXITING:
|
2015-05-22 09:27:56 +02:00
|
|
|
$details = pht('This daemon is shutting down gracefully.');
|
Send graceful shutdown signals to daemons in Phabricator
Summary:
Fixes T5855. Adds a `--graceful N` flag to `phd stop` and `phd restart`.
`phd` will send SIGINT, wait `N` seconds, SIGTERM, wait 15 seconds, and SIGKILL. By default, `N` is 15.
Test Plan:
- Ran `bin/phd debug ...` and used `^C` to interrupt daemons. Saw graceful shutdown behavior, and abrupt termination on multiple `^C`.
- Ran `bin/phd start`, `bin/phd stop` and `bin/phd restart` with `--graceful` set to various things, notably `0`. Saw graceful shutdowns on the CLI and in the web UI. With `0`, abrupt shutdowns.
Reviewers: btrahan, hach-que
Reviewed By: hach-que
Subscribers: epriestley
Maniphest Tasks: T5855
Differential Revision: https://secure.phabricator.com/D10228
2014-08-12 05:18:31 +02:00
|
|
|
break;
|
2013-07-23 21:10:41 +02:00
|
|
|
case PhabricatorDaemonLog::STATUS_EXITED:
|
2015-05-22 09:27:56 +02:00
|
|
|
$details = pht('This daemon exited normally and is no longer running.');
|
2013-07-23 21:10:41 +02:00
|
|
|
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());
|
2014-12-23 17:11:44 +01:00
|
|
|
$view->addProperty(pht('Running as'), $daemon->getRunningAsUser());
|
2013-07-23 21:10:41 +02:00
|
|
|
$view->addProperty(pht('Started'), phabricator_datetime($c_epoch, $viewer));
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Seen'),
|
|
|
|
pht(
|
|
|
|
'%s ago (%s)',
|
2014-07-13 04:03:17 +02:00
|
|
|
phutil_format_relative_time(time() - $u_epoch),
|
2013-07-23 21:10:41 +02:00
|
|
|
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(),
|
2014-09-03 02:11:36 +02:00
|
|
|
"phabricator/ $ ./bin/phd log --id {$id}"));
|
2013-07-23 21:48:45 +02:00
|
|
|
|
2013-07-23 21:10:41 +02:00
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2011-03-15 21:38:14 +01:00
|
|
|
}
|