@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 "phd start" and "phd reload" use the process list, not PID files

Summary:
Ref T13321. This gets rid of the last pidfile readers in Phabricator; we just use the process list instead.

These commands always only work on the current instance since they don't make much sense otherwise.

Test Plan: Ran `bin/phd start` and `bin/phd reload` with and without daemons running.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13321

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

+55 -60
+2 -8
src/applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php
··· 10 10 } 11 11 12 12 public function execute(PhutilArgumentParser $args) { 13 - $query = id(new PhutilProcessQuery()) 14 - ->withIsOverseer(true); 15 - 16 - $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); 17 - if ($instance !== null) { 18 - $query->withInstances(array($instance)); 19 - } 13 + $process_refs = $this->getOverseerProcessRefs(); 20 14 21 - $process_refs = $query->execute(); 22 15 if (!$process_refs) { 16 + $instance = $this->getInstance(); 23 17 if ($instance !== null) { 24 18 $this->logInfo( 25 19 pht('NO DAEMONS'),
+53 -52
src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php
··· 41 41 return $path; 42 42 } 43 43 44 - final protected function loadRunningDaemons() { 45 - $daemons = array(); 46 - 47 - $pid_dir = $this->getPIDDirectory(); 48 - $pid_files = Filesystem::listDirectory($pid_dir); 49 - 50 - foreach ($pid_files as $pid_file) { 51 - $path = $pid_dir.'/'.$pid_file; 52 - $daemons[] = PhabricatorDaemonReference::loadReferencesFromFile($path); 53 - } 54 - 55 - return array_mergev($daemons); 56 - } 57 - 58 44 private function findDaemonClass($substring) { 59 45 $symbols = $this->loadAvailableDaemonClasses(); 60 46 ··· 144 130 $flags[] = '--verbose'; 145 131 } 146 132 147 - $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); 133 + $instance = $this->getInstance(); 148 134 if ($instance) { 149 135 $flags[] = '-l'; 150 136 $flags[] = $instance; ··· 299 285 $console = PhutilConsole::getConsole(); 300 286 301 287 if (!idx($options, 'force')) { 302 - $running = $this->loadRunningDaemons(); 288 + $process_refs = $this->getOverseerProcessRefs(); 289 + if ($process_refs) { 290 + $this->logWarn( 291 + pht('RUNNING DAEMONS'), 292 + pht('Daemons are already running:')); 293 + 294 + fprintf(STDERR, '%s', "\n"); 295 + foreach ($process_refs as $process_ref) { 296 + fprintf( 297 + STDERR, 298 + '%s', 299 + tsprintf( 300 + " %s %s\n", 301 + $process_ref->getPID(), 302 + $process_ref->getCommand())); 303 + } 304 + fprintf(STDERR, '%s', "\n"); 303 305 304 - // This may include daemons which were launched but which are no longer 305 - // running; check that we actually have active daemons before failing. 306 - foreach ($running as $daemon) { 307 - if ($daemon->isRunning()) { 308 - $message = pht( 309 - "phd start: Unable to start daemons because daemons are already ". 310 - "running.\n\n". 311 - "You can view running daemons with '%s'.\n". 312 - "You can stop running daemons with '%s'.\n". 313 - "You can use '%s' to stop all daemons before starting ". 314 - "new daemons.\n". 315 - "You can force daemons to start anyway with %s.", 316 - 'phd status', 317 - 'phd stop', 318 - 'phd restart', 319 - '--force'); 306 + $this->logFail( 307 + pht('RUNNING DAEMONS'), 308 + pht( 309 + 'Use "phd stop" to stop daemons, "phd restart" to restart '. 310 + 'daemons, or "phd start --force" to ignore running processes.')); 320 311 321 - $console->writeErr("%s\n", $message); 322 - exit(1); 323 - } 312 + exit(1); 324 313 } 325 314 } 326 315 ··· 368 357 $query = id(new PhutilProcessQuery()) 369 358 ->withIsOverseer(true); 370 359 371 - $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); 360 + $instance = $this->getInstance(); 372 361 if ($instance !== null && !$force) { 373 362 $query->withInstances(array($instance)); 374 363 } ··· 447 436 } 448 437 449 438 final protected function executeReloadCommand(array $pids) { 450 - $console = PhutilConsole::getConsole(); 439 + $process_refs = $this->getOverseerProcessRefs(); 451 440 452 - $daemons = $this->loadRunningDaemons(); 453 - if (!$daemons) { 454 - $console->writeErr( 455 - "%s\n", 456 - pht('There are no running daemons to reload.')); 457 - return 0; 458 - } 441 + if (!$process_refs) { 442 + $this->logInfo( 443 + pht('NO DAEMONS'), 444 + pht('There are no running daemon processes to reload.')); 459 445 460 - $reload_pids = $this->selectDaemonPIDs($daemons, $pids); 461 - if (!$reload_pids) { 462 - $console->writeErr( 463 - "%s\n", 464 - pht('No daemons to reload.')); 465 446 return 0; 466 447 } 467 448 468 - foreach ($reload_pids as $pid) { 469 - $console->writeOut( 470 - "%s\n", 449 + foreach ($process_refs as $process_ref) { 450 + $pid = $process_ref->getPID(); 451 + 452 + $this->logInfo( 453 + pht('RELOAD'), 471 454 pht('Reloading process %d...', $pid)); 455 + 472 456 posix_kill($pid, SIGHUP); 473 457 } 474 458 ··· 620 604 621 605 return $select_pids; 622 606 } 607 + 608 + protected function getOverseerProcessRefs() { 609 + $query = id(new PhutilProcessQuery()) 610 + ->withIsOverseer(true); 611 + 612 + $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); 613 + if ($instance !== null) { 614 + $query->withInstances(array($instance)); 615 + } 616 + 617 + return $query->execute(); 618 + } 619 + 620 + protected function getInstance() { 621 + return PhabricatorEnv::getEnvConfig('cluster.instance'); 622 + } 623 + 623 624 624 625 }