@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.

Make "bin/phd status" report local daemons from the process list, not a mess of local/remote information

Summary:
Ref T13321. Fixes T11037. Realign "bin/phd status" to just mean "show daemon processes on this host".

The value of `bin/phd status` as a mixed remote/local command isn't clear, and the current output is a confusing mess (see T11037).

This also continues letting us move away from PID files.

Test Plan: Ran `bin/phd status`, saw sensible local process status.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13321, T11037

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

+36 -104
+36 -79
src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php
··· 6 6 protected function didConstruct() { 7 7 $this 8 8 ->setName('status') 9 - ->setSynopsis(pht('Show status of running daemons.')) 10 - ->setArguments( 11 - array( 12 - array( 13 - 'name' => 'local', 14 - 'help' => pht('Show only local daemons.'), 15 - ), 16 - )); 9 + ->setSynopsis(pht('Show daemon processes on this host.')); 17 10 } 18 11 19 12 public function execute(PhutilArgumentParser $args) { 20 - $console = PhutilConsole::getConsole(); 13 + $query = id(new PhutilProcessQuery()) 14 + ->withIsOverseer(true); 21 15 22 - if ($args->getArg('local')) { 23 - $daemons = $this->loadRunningDaemons(); 24 - } else { 25 - $daemons = $this->loadAllRunningDaemons(); 16 + $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); 17 + if ($instance !== null) { 18 + $query->withInstances(array($instance)); 26 19 } 27 20 28 - if (!$daemons) { 29 - $console->writeErr( 30 - "%s\n", 31 - pht('There are no running Phabricator daemons.')); 21 + $process_refs = $query->execute(); 22 + if (!$process_refs) { 23 + if ($instance !== null) { 24 + $this->logInfo( 25 + pht('NO DAEMONS'), 26 + pht( 27 + 'There are no running daemon processes for the current '. 28 + 'instance ("%s").', 29 + $instance)); 30 + } else { 31 + $this->writeInfo( 32 + pht('NO DAEMONS'), 33 + pht('There are no running daemon processes.')); 34 + } 35 + 32 36 return 1; 33 37 } 34 38 35 - $status = 0; 36 - 37 39 $table = id(new PhutilConsoleTable()) 38 - ->addColumns(array( 39 - 'id' => array( 40 - 'title' => pht('Log'), 41 - ), 42 - 'daemonID' => array( 43 - 'title' => pht('Daemon'), 44 - ), 45 - 'host' => array( 46 - 'title' => pht('Host'), 47 - ), 48 - 'pid' => array( 49 - 'title' => pht('Overseer'), 50 - ), 51 - 'started' => array( 52 - 'title' => pht('Started'), 53 - ), 54 - 'daemon' => array( 55 - 'title' => pht('Class'), 56 - ), 57 - 'argv' => array( 58 - 'title' => pht('Arguments'), 59 - ), 60 - )); 61 - 62 - foreach ($daemons as $daemon) { 63 - if ($daemon instanceof PhabricatorDaemonLog) { 64 - $table->addRow(array( 65 - 'id' => $daemon->getID(), 66 - 'daemonID' => $daemon->getDaemonID(), 67 - 'host' => $daemon->getHost(), 68 - 'pid' => $daemon->getPID(), 69 - 'started' => date('M j Y, g:i:s A', $daemon->getDateCreated()), 70 - 'daemon' => $daemon->getDaemon(), 71 - 'argv' => csprintf('%LR', $daemon->getExplicitArgv()), 40 + ->addColumns( 41 + array( 42 + 'pid' => array( 43 + 'title' => pht('PID'), 44 + ), 45 + 'command' => array( 46 + 'title' => pht('Command'), 47 + ), 72 48 )); 73 - } else if ($daemon instanceof PhabricatorDaemonReference) { 74 - $name = $daemon->getName(); 75 - if (!$daemon->isRunning()) { 76 - $daemon->updateStatus(PhabricatorDaemonLog::STATUS_DEAD); 77 - $status = 2; 78 - $name = pht('<DEAD> %s', $name); 79 - } 80 49 81 - $daemon_log = $daemon->getDaemonLog(); 82 - $id = null; 83 - $daemon_id = null; 84 - if ($daemon_log) { 85 - $id = $daemon_log->getID(); 86 - $daemon_id = $daemon_log->getDaemonID(); 87 - } 88 - 89 - $table->addRow(array( 90 - 'id' => $id, 91 - 'daemonID' => $daemon_id, 92 - 'host' => 'localhost', 93 - 'pid' => $daemon->getPID(), 94 - 'started' => $daemon->getEpochStarted() 95 - ? date('M j Y, g:i:s A', $daemon->getEpochStarted()) 96 - : null, 97 - 'daemon' => $name, 98 - 'argv' => csprintf('%LR', $daemon->getArgv()), 50 + foreach ($process_refs as $process_ref) { 51 + $table->addRow( 52 + array( 53 + 'pid' => $process_ref->getPID(), 54 + 'command' => $process_ref->getCommand(), 99 55 )); 100 - } 101 56 } 102 57 103 58 $table->draw(); 59 + 60 + return 0; 104 61 } 105 62 106 63 }
-25
src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php
··· 55 55 return array_mergev($daemons); 56 56 } 57 57 58 - final protected function loadAllRunningDaemons() { 59 - $local_daemons = $this->loadRunningDaemons(); 60 - 61 - $local_ids = array(); 62 - foreach ($local_daemons as $daemon) { 63 - $daemon_log = $daemon->getDaemonLog(); 64 - 65 - if ($daemon_log) { 66 - $local_ids[] = $daemon_log->getID(); 67 - } 68 - } 69 - 70 - $daemon_query = id(new PhabricatorDaemonLogQuery()) 71 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 72 - ->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE); 73 - 74 - if ($local_ids) { 75 - $daemon_query->withoutIDs($local_ids); 76 - } 77 - 78 - $remote_daemons = $daemon_query->execute(); 79 - 80 - return array_merge($local_daemons, $remote_daemons); 81 - } 82 - 83 58 private function findDaemonClass($substring) { 84 59 $symbols = $this->loadAvailableDaemonClasses(); 85 60