@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: Ref T4209. Currently, `./bin/phd status` prints a table showing the daemons that are executing on the current host. It would be useful to be able to conventiently query the daemons running across all hosts. This would also (theoretically) make it possible to conditionally start daemons on a host depending upon the current state and on the daemons running on other hosts.

Test Plan:
```
> ./bin/phd status --all
ID Host PID Started Daemon Arguments
18 phabricator 6969 Jun 12 2014, 4:44:22 PM PhabricatorTaskmasterDaemon
17 phabricator 6961 Jun 12 2014, 4:44:19 PM PhabricatorTaskmasterDaemon
16 phabricator 6955 Jun 12 2014, 4:44:15 PM PhabricatorTaskmasterDaemon
15 phabricator 6950 Jun 12 2014, 4:44:14 PM PhabricatorTaskmasterDaemon
14 phabricator 6936 Jun 12 2014, 4:44:13 PM PhabricatorGarbageCollectorDaemon
13 phabricator 6931 Jun 12 2014, 4:44:12 PM PhabricatorRepositoryPullLocalDaemon
```

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T4209

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

+113 -39
+72 -13
src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php
··· 22 22 } 23 23 24 24 $status = 0; 25 - printf( 26 - "%-5s\t%-24s\t%-50s%s\n", 27 - 'PID', 28 - 'Started', 29 - 'Daemon', 30 - 'Arguments'); 25 + $table = id(new PhutilConsoleTable()) 26 + ->addColumns(array( 27 + 'pid' => array( 28 + 'title' => 'PID', 29 + ), 30 + 'started' => array( 31 + 'title' => 'Started', 32 + ), 33 + 'daemon' => array( 34 + 'title' => 'Daemon', 35 + ), 36 + 'argv' => array( 37 + 'title' => 'Arguments', 38 + ), 39 + )); 40 + 31 41 foreach ($daemons as $daemon) { 32 42 $name = $daemon->getName(); 33 43 if (!$daemon->isRunning()) { ··· 35 45 $status = 2; 36 46 $name = '<DEAD> '.$name; 37 47 } 38 - printf( 39 - "%5s\t%-24s\t%-50s%s\n", 40 - $daemon->getPID(), 41 - $daemon->getEpochStarted() 48 + 49 + $table->addRow(array( 50 + 'pid' => $daemon->getPID(), 51 + 'started' => $daemon->getEpochStarted() 42 52 ? date('M j Y, g:i:s A', $daemon->getEpochStarted()) 43 53 : null, 44 - $name, 45 - csprintf('%LR', $daemon->getArgv())); 54 + 'daemon' => $name, 55 + 'argv' => csprintf('%LR', $daemon->getArgv()), 56 + )); 46 57 } 47 58 48 - return $status; 59 + $table->draw(); 49 60 } 50 61 62 + protected function executeGlobal() { 63 + $console = PhutilConsole::getConsole(); 64 + $daemons = $this->loadAllRunningDaemons(); 65 + 66 + if (!$daemons) { 67 + $console->writeErr( 68 + "%s\n", 69 + pht('There are no running Phabricator daemons.')); 70 + return 1; 71 + } 72 + 73 + $status = 0; 74 + 75 + $table = id(new PhutilConsoleTable()) 76 + ->addColumns(array( 77 + 'id' => array( 78 + 'title' => 'ID', 79 + ), 80 + 'host' => array( 81 + 'title' => 'Host', 82 + ), 83 + 'pid' => array( 84 + 'title' => 'PID', 85 + ), 86 + 'started' => array( 87 + 'title' => 'Started', 88 + ), 89 + 'daemon' => array( 90 + 'title' => 'Daemon', 91 + ), 92 + 'argv' => array( 93 + 'title' => 'Arguments', 94 + ), 95 + )); 96 + 97 + foreach ($daemons as $daemon) { 98 + $table->addRow(array( 99 + 'id' => $daemon->getID(), 100 + 'host' => $daemon->getHost(), 101 + 'pid' => $daemon->getPID(), 102 + 'started' => date('M j Y, g:i:s A', $daemon->getDateCreated()), 103 + 'daemon' => $daemon->getDaemon(), 104 + 'argv' => csprintf('%LR', array() /* $daemon->getArgv() */), 105 + )); 106 + } 107 + 108 + $table->draw(); 109 + } 51 110 52 111 }
+18 -21
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 + $ids = array(); 40 41 41 42 $pid_dir = $this->getPIDDirectory(); 42 43 $pid_files = Filesystem::listDirectory($pid_dir); ··· 45 46 } 46 47 47 48 foreach ($pid_files as $pid_file) { 48 - $pid_data = Filesystem::readFile($pid_dir.'/'.$pid_file); 49 - $dict = json_decode($pid_data, true); 50 - if (!is_array($dict)) { 51 - // Just return a hanging reference, since control code needs to be 52 - // robust against unusual system states. 53 - $dict = array(); 54 - } 55 - $ref = PhabricatorDaemonReference::newFromDictionary($dict); 56 - $ref->setPIDFile($pid_dir.'/'.$pid_file); 57 - $results[] = $ref; 49 + $results[] = PhabricatorDaemonReference::newFromDictionary( 50 + $pid_dir.'/'.$pid_file); 51 + $ids[] = $ref->getDaemonLog()->getID(); 58 52 } 59 53 60 - return $results; 54 + $other = id(new PhabricatorDaemonLogQuery()) 55 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 56 + ->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE) 57 + ->execute(); 58 + 59 + 61 60 } 62 61 63 62 private function findDaemonClass($substring) { ··· 93 92 return head($match); 94 93 } 95 94 96 - 97 - protected function launchDaemon($class, array $argv, $debug) { 95 + protected final function launchDaemon($class, array $argv, $debug) { 98 96 $daemon = $this->findDaemonClass($class); 99 97 $console = PhutilConsole::getConsole(); 100 98 ··· 212 210 } 213 211 } 214 212 215 - protected function willLaunchDaemons() { 213 + protected final function willLaunchDaemons() { 216 214 $console = PhutilConsole::getConsole(); 217 215 $console->writeErr(pht('Preparing to launch daemons.')."\n"); 218 216 ··· 224 222 /* -( Commands )----------------------------------------------------------- */ 225 223 226 224 227 - protected function executeStartCommand($keep_leases = false) { 225 + protected final function executeStartCommand($keep_leases = false) { 228 226 $console = PhutilConsole::getConsole(); 229 227 230 228 $running = $this->loadRunningDaemons(); ··· 278 276 return 0; 279 277 } 280 278 281 - 282 - protected function executeStopCommand(array $pids) { 279 + protected final function executeStopCommand(array $pids) { 283 280 $console = PhutilConsole::getConsole(); 284 281 285 282 $daemons = $this->loadRunningDaemons();
+23 -5
src/infrastructure/daemon/control/PhabricatorDaemonReference.php
··· 10 10 11 11 private $daemonLog; 12 12 13 + public static function newFromFile($path) { 14 + $pid_data = Filesystem::readFile($path); 15 + $dict = json_decode($pid_data, true); 16 + if (!is_array($dict)) { 17 + // Just return a hanging reference, since control code needs to be 18 + // robust against unusual system states. 19 + $dict = array(); 20 + } 21 + $ref = self::newFromDictionary($dict); 22 + $ref->pidFile = $path; 23 + return $ref; 24 + } 25 + 13 26 public static function newFromDictionary(array $dict) { 14 27 $ref = new PhabricatorDaemonReference(); 15 28 ··· 17 30 $ref->argv = idx($dict, 'argv', array()); 18 31 $ref->pid = idx($dict, 'pid'); 19 32 $ref->start = idx($dict, 'start'); 33 + 34 + $this->daemonLog = id(new PhabricatorDaemonLog())->loadOneWhere( 35 + 'daemon = %s AND pid = %d AND dateCreated = %d', 36 + $this->name, 37 + $this->pid, 38 + $this->start); 20 39 21 40 return $ref; 22 41 } ··· 66 85 return $this->start; 67 86 } 68 87 69 - public function setPIDFile($pid_file) { 70 - $this->pidFile = $pid_file; 71 - return $this; 88 + public function getPIDFile() { 89 + return $this->pidFile; 72 90 } 73 91 74 - public function getPIDFile() { 75 - return $this->pidFile; 92 + public function getDaemonLog() { 93 + return $this->daemonLog; 76 94 } 77 95 78 96 public function isRunning() {