@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Query daemons across all hosts with `./bin/phd status --all`.

Summary: This was previously submitted as D9497, but I had accidentally `arc land`ed some not-reviewed not-yet-complete changes in addition to the accepted diff.

Test Plan: Same as D9497.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Maniphest Tasks: T5388, T4209

Differential Revision: https://secure.phabricator.com/D9589

+102 -24
+87 -14
src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php
··· 7 7 $this 8 8 ->setName('status') 9 9 ->setSynopsis(pht('Show status of running daemons.')) 10 - ->setArguments(array()); 10 + ->setArguments( 11 + array( 12 + array( 13 + 'name' => 'all', 14 + 'help' => pht('Show the status of daemons across all hosts.'), 15 + ), 16 + )); 11 17 } 12 18 13 19 public function execute(PhutilArgumentParser $args) { 20 + if ($args->getArg('all')) { 21 + return $this->executeGlobal(); 22 + } else { 23 + return $this->executeLocal(); 24 + } 25 + } 26 + 27 + protected function executeLocal() { 14 28 $console = PhutilConsole::getConsole(); 15 29 $daemons = $this->loadRunningDaemons(); 16 30 ··· 22 36 } 23 37 24 38 $status = 0; 25 - printf( 26 - "%-5s\t%-24s\t%-50s%s\n", 27 - 'PID', 28 - 'Started', 29 - 'Daemon', 30 - 'Arguments'); 39 + $table = id(new PhutilConsoleTable()) 40 + ->addColumns(array( 41 + 'pid' => array( 42 + 'title' => 'PID', 43 + ), 44 + 'started' => array( 45 + 'title' => 'Started', 46 + ), 47 + 'daemon' => array( 48 + 'title' => 'Daemon', 49 + ), 50 + 'argv' => array( 51 + 'title' => 'Arguments', 52 + ), 53 + )); 54 + 31 55 foreach ($daemons as $daemon) { 32 56 $name = $daemon->getName(); 33 57 if (!$daemon->isRunning()) { ··· 35 59 $status = 2; 36 60 $name = '<DEAD> '.$name; 37 61 } 38 - printf( 39 - "%5s\t%-24s\t%-50s%s\n", 40 - $daemon->getPID(), 41 - $daemon->getEpochStarted() 62 + 63 + $table->addRow(array( 64 + 'pid' => $daemon->getPID(), 65 + 'started' => $daemon->getEpochStarted() 42 66 ? date('M j Y, g:i:s A', $daemon->getEpochStarted()) 43 67 : null, 44 - $name, 45 - csprintf('%LR', $daemon->getArgv())); 68 + 'daemon' => $name, 69 + 'argv' => csprintf('%LR', $daemon->getArgv()), 70 + )); 46 71 } 47 72 48 - return $status; 73 + $table->draw(); 49 74 } 50 75 76 + protected function executeGlobal() { 77 + $console = PhutilConsole::getConsole(); 78 + $daemons = $this->loadAllRunningDaemons(); 79 + 80 + if (!$daemons) { 81 + $console->writeErr( 82 + "%s\n", 83 + pht('There are no running Phabricator daemons.')); 84 + return 1; 85 + } 86 + 87 + $status = 0; 88 + 89 + $table = id(new PhutilConsoleTable()) 90 + ->addColumns(array( 91 + 'id' => array( 92 + 'title' => 'ID', 93 + ), 94 + 'host' => array( 95 + 'title' => 'Host', 96 + ), 97 + 'pid' => array( 98 + 'title' => 'PID', 99 + ), 100 + 'started' => array( 101 + 'title' => 'Started', 102 + ), 103 + 'daemon' => array( 104 + 'title' => 'Daemon', 105 + ), 106 + 'argv' => array( 107 + 'title' => 'Arguments', 108 + ), 109 + )); 110 + 111 + foreach ($daemons as $daemon) { 112 + $table->addRow(array( 113 + 'id' => $daemon->getID(), 114 + 'host' => $daemon->getHost(), 115 + 'pid' => $daemon->getPID(), 116 + 'started' => date('M j Y, g:i:s A', $daemon->getDateCreated()), 117 + 'daemon' => $daemon->getDaemon(), 118 + 'argv' => csprintf('%LR', array() /* $daemon->getArgv() */), 119 + )); 120 + } 121 + 122 + $table->draw(); 123 + } 51 124 52 125 }
+15 -10
src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php
··· 3 3 abstract class PhabricatorDaemonManagementWorkflow 4 4 extends PhabricatorManagementWorkflow { 5 5 6 - protected function loadAvailableDaemonClasses() { 6 + protected final function loadAvailableDaemonClasses() { 7 7 $loader = new PhutilSymbolLoader(); 8 8 return $loader 9 9 ->setAncestorClass('PhutilDaemon') ··· 11 11 ->selectSymbolsWithoutLoading(); 12 12 } 13 13 14 - public function getPIDDirectory() { 14 + protected final function getPIDDirectory() { 15 15 $path = PhabricatorEnv::getEnvConfig('phd.pid-directory'); 16 16 return $this->getControlDirectory($path); 17 17 } 18 18 19 - public function getLogDirectory() { 19 + protected final function getLogDirectory() { 20 20 $path = PhabricatorEnv::getEnvConfig('phd.log-directory'); 21 21 return $this->getControlDirectory($path); 22 22 } ··· 35 35 return $path; 36 36 } 37 37 38 - public function loadRunningDaemons() { 38 + protected final function loadRunningDaemons() { 39 39 $results = array(); 40 40 41 41 $pid_dir = $this->getPIDDirectory(); ··· 60 60 return $results; 61 61 } 62 62 63 + protected final function loadAllRunningDaemons() { 64 + return id(new PhabricatorDaemonLogQuery()) 65 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 66 + ->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE) 67 + ->execute(); 68 + } 69 + 63 70 private function findDaemonClass($substring) { 64 71 $symbols = $this->loadAvailableDaemonClasses(); 65 72 ··· 93 100 return head($match); 94 101 } 95 102 96 - 97 - protected function launchDaemon($class, array $argv, $debug) { 103 + protected final function launchDaemon($class, array $argv, $debug) { 98 104 $daemon = $this->findDaemonClass($class); 99 105 $console = PhutilConsole::getConsole(); 100 106 ··· 212 218 } 213 219 } 214 220 215 - protected function willLaunchDaemons() { 221 + protected final function willLaunchDaemons() { 216 222 $console = PhutilConsole::getConsole(); 217 223 $console->writeErr(pht('Preparing to launch daemons.')."\n"); 218 224 ··· 224 230 /* -( Commands )----------------------------------------------------------- */ 225 231 226 232 227 - protected function executeStartCommand($keep_leases = false) { 233 + protected final function executeStartCommand($keep_leases = false) { 228 234 $console = PhutilConsole::getConsole(); 229 235 230 236 $running = $this->loadRunningDaemons(); ··· 278 284 return 0; 279 285 } 280 286 281 - 282 - protected function executeStopCommand(array $pids) { 287 + protected final function executeStopCommand(array $pids) { 283 288 $console = PhutilConsole::getConsole(); 284 289 285 290 $daemons = $this->loadRunningDaemons();