mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-08 21:08:29 +01:00
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
This commit is contained in:
parent
08b9e70bea
commit
2498e373b9
2 changed files with 55 additions and 60 deletions
|
@ -10,16 +10,10 @@ final class PhabricatorDaemonManagementStatusWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(PhutilArgumentParser $args) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$query = id(new PhutilProcessQuery())
|
$process_refs = $this->getOverseerProcessRefs();
|
||||||
->withIsOverseer(true);
|
|
||||||
|
|
||||||
$instance = PhabricatorEnv::getEnvConfig('cluster.instance');
|
|
||||||
if ($instance !== null) {
|
|
||||||
$query->withInstances(array($instance));
|
|
||||||
}
|
|
||||||
|
|
||||||
$process_refs = $query->execute();
|
|
||||||
if (!$process_refs) {
|
if (!$process_refs) {
|
||||||
|
$instance = $this->getInstance();
|
||||||
if ($instance !== null) {
|
if ($instance !== null) {
|
||||||
$this->logInfo(
|
$this->logInfo(
|
||||||
pht('NO DAEMONS'),
|
pht('NO DAEMONS'),
|
||||||
|
|
|
@ -41,20 +41,6 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function loadRunningDaemons() {
|
|
||||||
$daemons = array();
|
|
||||||
|
|
||||||
$pid_dir = $this->getPIDDirectory();
|
|
||||||
$pid_files = Filesystem::listDirectory($pid_dir);
|
|
||||||
|
|
||||||
foreach ($pid_files as $pid_file) {
|
|
||||||
$path = $pid_dir.'/'.$pid_file;
|
|
||||||
$daemons[] = PhabricatorDaemonReference::loadReferencesFromFile($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_mergev($daemons);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function findDaemonClass($substring) {
|
private function findDaemonClass($substring) {
|
||||||
$symbols = $this->loadAvailableDaemonClasses();
|
$symbols = $this->loadAvailableDaemonClasses();
|
||||||
|
|
||||||
|
@ -144,7 +130,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
$flags[] = '--verbose';
|
$flags[] = '--verbose';
|
||||||
}
|
}
|
||||||
|
|
||||||
$instance = PhabricatorEnv::getEnvConfig('cluster.instance');
|
$instance = $this->getInstance();
|
||||||
if ($instance) {
|
if ($instance) {
|
||||||
$flags[] = '-l';
|
$flags[] = '-l';
|
||||||
$flags[] = $instance;
|
$flags[] = $instance;
|
||||||
|
@ -299,28 +285,31 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
$console = PhutilConsole::getConsole();
|
$console = PhutilConsole::getConsole();
|
||||||
|
|
||||||
if (!idx($options, 'force')) {
|
if (!idx($options, 'force')) {
|
||||||
$running = $this->loadRunningDaemons();
|
$process_refs = $this->getOverseerProcessRefs();
|
||||||
|
if ($process_refs) {
|
||||||
|
$this->logWarn(
|
||||||
|
pht('RUNNING DAEMONS'),
|
||||||
|
pht('Daemons are already running:'));
|
||||||
|
|
||||||
// This may include daemons which were launched but which are no longer
|
fprintf(STDERR, '%s', "\n");
|
||||||
// running; check that we actually have active daemons before failing.
|
foreach ($process_refs as $process_ref) {
|
||||||
foreach ($running as $daemon) {
|
fprintf(
|
||||||
if ($daemon->isRunning()) {
|
STDERR,
|
||||||
$message = pht(
|
'%s',
|
||||||
"phd start: Unable to start daemons because daemons are already ".
|
tsprintf(
|
||||||
"running.\n\n".
|
" %s %s\n",
|
||||||
"You can view running daemons with '%s'.\n".
|
$process_ref->getPID(),
|
||||||
"You can stop running daemons with '%s'.\n".
|
$process_ref->getCommand()));
|
||||||
"You can use '%s' to stop all daemons before starting ".
|
|
||||||
"new daemons.\n".
|
|
||||||
"You can force daemons to start anyway with %s.",
|
|
||||||
'phd status',
|
|
||||||
'phd stop',
|
|
||||||
'phd restart',
|
|
||||||
'--force');
|
|
||||||
|
|
||||||
$console->writeErr("%s\n", $message);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
fprintf(STDERR, '%s', "\n");
|
||||||
|
|
||||||
|
$this->logFail(
|
||||||
|
pht('RUNNING DAEMONS'),
|
||||||
|
pht(
|
||||||
|
'Use "phd stop" to stop daemons, "phd restart" to restart '.
|
||||||
|
'daemons, or "phd start --force" to ignore running processes.'));
|
||||||
|
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +357,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
$query = id(new PhutilProcessQuery())
|
$query = id(new PhutilProcessQuery())
|
||||||
->withIsOverseer(true);
|
->withIsOverseer(true);
|
||||||
|
|
||||||
$instance = PhabricatorEnv::getEnvConfig('cluster.instance');
|
$instance = $this->getInstance();
|
||||||
if ($instance !== null && !$force) {
|
if ($instance !== null && !$force) {
|
||||||
$query->withInstances(array($instance));
|
$query->withInstances(array($instance));
|
||||||
}
|
}
|
||||||
|
@ -447,28 +436,23 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function executeReloadCommand(array $pids) {
|
final protected function executeReloadCommand(array $pids) {
|
||||||
$console = PhutilConsole::getConsole();
|
$process_refs = $this->getOverseerProcessRefs();
|
||||||
|
|
||||||
|
if (!$process_refs) {
|
||||||
|
$this->logInfo(
|
||||||
|
pht('NO DAEMONS'),
|
||||||
|
pht('There are no running daemon processes to reload.'));
|
||||||
|
|
||||||
$daemons = $this->loadRunningDaemons();
|
|
||||||
if (!$daemons) {
|
|
||||||
$console->writeErr(
|
|
||||||
"%s\n",
|
|
||||||
pht('There are no running daemons to reload.'));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reload_pids = $this->selectDaemonPIDs($daemons, $pids);
|
foreach ($process_refs as $process_ref) {
|
||||||
if (!$reload_pids) {
|
$pid = $process_ref->getPID();
|
||||||
$console->writeErr(
|
|
||||||
"%s\n",
|
|
||||||
pht('No daemons to reload.'));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($reload_pids as $pid) {
|
$this->logInfo(
|
||||||
$console->writeOut(
|
pht('RELOAD'),
|
||||||
"%s\n",
|
|
||||||
pht('Reloading process %d...', $pid));
|
pht('Reloading process %d...', $pid));
|
||||||
|
|
||||||
posix_kill($pid, SIGHUP);
|
posix_kill($pid, SIGHUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,4 +605,21 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
return $select_pids;
|
return $select_pids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getOverseerProcessRefs() {
|
||||||
|
$query = id(new PhutilProcessQuery())
|
||||||
|
->withIsOverseer(true);
|
||||||
|
|
||||||
|
$instance = PhabricatorEnv::getEnvConfig('cluster.instance');
|
||||||
|
if ($instance !== null) {
|
||||||
|
$query->withInstances(array($instance));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getInstance() {
|
||||||
|
return PhabricatorEnv::getEnvConfig('cluster.instance');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue