[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorDaemonLogViewController 4 extends PhabricatorDaemonController { 5 6 private $id; 7 8 public function willProcessRequest(array $data) { 9 $this->id = $data['id']; 10 } 11 12 public function processRequest() { 13 $request = $this->getRequest(); 14 $user = $request->getUser(); 15 16 $log = id(new PhabricatorDaemonLogQuery()) 17 ->setViewer($user) 18 ->withIDs(array($this->id)) 19 ->setAllowStatusWrites(true) 20 ->executeOne(); 21 if (!$log) { 22 return new Aphront404Response(); 23 } 24 25 $events = id(new PhabricatorDaemonLogEvent())->loadAllWhere( 26 'logID = %d ORDER BY id DESC LIMIT 1000', 27 $log->getID()); 28 29 $crumbs = $this->buildApplicationCrumbs(); 30 $crumbs->addTextCrumb(pht('Daemon %s', $log->getID())); 31 32 $header = id(new PHUIHeaderView()) 33 ->setHeader($log->getDaemon()); 34 35 $tag = id(new PHUITagView()) 36 ->setType(PHUITagView::TYPE_STATE); 37 38 $status = $log->getStatus(); 39 switch ($status) { 40 case PhabricatorDaemonLog::STATUS_UNKNOWN: 41 $tag->setBackgroundColor(PHUITagView::COLOR_ORANGE); 42 $tag->setName(pht('Unknown')); 43 break; 44 case PhabricatorDaemonLog::STATUS_RUNNING: 45 $tag->setBackgroundColor(PHUITagView::COLOR_GREEN); 46 $tag->setName(pht('Running')); 47 break; 48 case PhabricatorDaemonLog::STATUS_DEAD: 49 $tag->setBackgroundColor(PHUITagView::COLOR_RED); 50 $tag->setName(pht('Dead')); 51 break; 52 case PhabricatorDaemonLog::STATUS_WAIT: 53 $tag->setBackgroundColor(PHUITagView::COLOR_BLUE); 54 $tag->setName(pht('Waiting')); 55 break; 56 case PhabricatorDaemonLog::STATUS_EXITING: 57 $tag->setBackgroundColor(PHUITagView::COLOR_YELLOW); 58 $tag->setName(pht('Exiting')); 59 break; 60 case PhabricatorDaemonLog::STATUS_EXITED: 61 $tag->setBackgroundColor(PHUITagView::COLOR_GREY); 62 $tag->setName(pht('Exited')); 63 break; 64 } 65 66 $header->addTag($tag); 67 $env_hash = PhabricatorEnv::calculateEnvironmentHash(); 68 if ($log->getEnvHash() != $env_hash) { 69 $tag = id(new PHUITagView()) 70 ->setType(PHUITagView::TYPE_STATE) 71 ->setBackgroundColor(PHUITagView::COLOR_YELLOW) 72 ->setName(pht('Stale Config')); 73 $header->addTag($tag); 74 } 75 76 $properties = $this->buildPropertyListView($log); 77 78 $event_view = id(new PhabricatorDaemonLogEventsView()) 79 ->setUser($user) 80 ->setEvents($events); 81 82 $event_panel = new AphrontPanelView(); 83 $event_panel->setNoBackground(); 84 $event_panel->appendChild($event_view); 85 86 $object_box = id(new PHUIObjectBoxView()) 87 ->setHeader($header) 88 ->addPropertyList($properties); 89 90 return $this->buildApplicationPage( 91 array( 92 $crumbs, 93 $object_box, 94 $event_panel, 95 ), 96 array( 97 'title' => pht('Daemon Log'), 98 'device' => false, 99 )); 100 } 101 102 private function buildPropertyListView(PhabricatorDaemonLog $daemon) { 103 $request = $this->getRequest(); 104 $viewer = $request->getUser(); 105 106 $view = id(new PHUIPropertyListView()) 107 ->setUser($viewer); 108 109 $id = $daemon->getID(); 110 $c_epoch = $daemon->getDateCreated(); 111 $u_epoch = $daemon->getDateModified(); 112 113 $unknown_time = PhabricatorDaemonLogQuery::getTimeUntilUnknown(); 114 $dead_time = PhabricatorDaemonLogQuery::getTimeUntilDead(); 115 $wait_time = PhutilDaemonOverseer::RESTART_WAIT; 116 117 $details = null; 118 $status = $daemon->getStatus(); 119 switch ($status) { 120 case PhabricatorDaemonLog::STATUS_RUNNING: 121 $details = pht( 122 'This daemon is running normally and reported a status update '. 123 'recently (within %s).', 124 phutil_format_relative_time($unknown_time)); 125 break; 126 case PhabricatorDaemonLog::STATUS_UNKNOWN: 127 $details = pht( 128 'This daemon has not reported a status update recently (within %s). '. 129 'It may have exited abruptly. After %s, it will be presumed dead.', 130 phutil_format_relative_time($unknown_time), 131 phutil_format_relative_time($dead_time)); 132 break; 133 case PhabricatorDaemonLog::STATUS_DEAD: 134 $details = pht( 135 'This daemon did not report a status update for %s. It is '. 136 'presumed dead. Usually, this indicates that the daemon was '. 137 'killed or otherwise exited abruptly with an error. You may '. 138 'need to restart it.', 139 phutil_format_relative_time($dead_time)); 140 break; 141 case PhabricatorDaemonLog::STATUS_WAIT: 142 $details = pht( 143 'This daemon is running normally and reported a status update '. 144 'recently (within %s). However, it encountered an error while '. 145 'doing work and is waiting a little while (%s) to resume '. 146 'processing. After encountering an error, daemons wait before '. 147 'resuming work to avoid overloading services.', 148 phutil_format_relative_time($unknown_time), 149 phutil_format_relative_time($wait_time)); 150 break; 151 case PhabricatorDaemonLog::STATUS_EXITING: 152 $details = pht( 153 'This daemon is shutting down gracefully.'); 154 break; 155 case PhabricatorDaemonLog::STATUS_EXITED: 156 $details = pht( 157 'This daemon exited normally and is no longer running.'); 158 break; 159 } 160 161 $view->addProperty(pht('Status Details'), $details); 162 163 $view->addProperty(pht('Daemon Class'), $daemon->getDaemon()); 164 $view->addProperty(pht('Host'), $daemon->getHost()); 165 $view->addProperty(pht('PID'), $daemon->getPID()); 166 $view->addProperty(pht('Started'), phabricator_datetime($c_epoch, $viewer)); 167 $view->addProperty( 168 pht('Seen'), 169 pht( 170 '%s ago (%s)', 171 phutil_format_relative_time(time() - $u_epoch), 172 phabricator_datetime($u_epoch, $viewer))); 173 174 $argv = $daemon->getArgv(); 175 if (is_array($argv)) { 176 $argv = implode("\n", $argv); 177 } 178 179 $view->addProperty( 180 pht('Argv'), 181 phutil_tag( 182 'textarea', 183 array( 184 'style' => 'width: 100%; height: 12em;', 185 ), 186 $argv)); 187 188 $view->addProperty( 189 pht('View Full Logs'), 190 phutil_tag( 191 'tt', 192 array(), 193 "phabricator/ $ ./bin/phd log --id {$id}")); 194 195 196 return $view; 197 } 198 199 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |