1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-26 07:20:57 +01:00

Remove "phd.pid-directory" configuration and stop passing "piddir" to daemons

Summary: Ref T13321. The daemons no longer write PID files, so we no longer need to pass any of this stuff to them.

Test Plan: Grepped for affected symbols.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13321

Differential Revision: https://secure.phabricator.com/D20608
This commit is contained in:
epriestley 2019-06-20 15:09:39 -07:00
parent 2498e373b9
commit 65bc481c91
4 changed files with 7 additions and 151 deletions

View file

@ -536,6 +536,9 @@ final class PhabricatorExtraConfigSetupCheck extends PhabricatorSetupCheck {
'differential.whitespace-matters' => pht(
'Whitespace rendering is now handled automatically.'),
'phd.pid-directory' => pht(
'Phabricator daemons no longer use PID files.'),
);
return $ancient_config;

View file

@ -21,10 +21,6 @@ final class PhabricatorPHDConfigOptions
public function getOptions() {
return array(
$this->newOption('phd.pid-directory', 'string', '/var/tmp/phd/pid')
->setLocked(true)
->setDescription(
pht('Directory that phd should use to track running daemons.')),
$this->newOption('phd.log-directory', 'string', '/var/tmp/phd/log')
->setLocked(true)
->setDescription(

View file

@ -12,11 +12,6 @@ abstract class PhabricatorDaemonManagementWorkflow
->selectSymbolsWithoutLoading();
}
final protected function getPIDDirectory() {
$path = PhabricatorEnv::getEnvConfig('phd.pid-directory');
return $this->getControlDirectory($path);
}
final protected function getLogDirectory() {
$path = PhabricatorEnv::getEnvConfig('phd.log-directory');
return $this->getControlDirectory($path);
@ -30,11 +25,10 @@ abstract class PhabricatorDaemonManagementWorkflow
pht(
"%s requires the directory '%s' to exist, but it does not exist ".
"and could not be created. Create this directory or update ".
"'%s' / '%s' in your configuration to point to an existing ".
"'%s' in your configuration to point to an existing ".
"directory.",
'phd',
$path,
'phd.pid-directory',
'phd.log-directory'));
}
}
@ -146,14 +140,6 @@ abstract class PhabricatorDaemonManagementWorkflow
$config['log'] = $this->getLogDirectory().'/daemons.log';
}
$pid_dir = $this->getPIDDirectory();
// TODO: This should be a much better user experience.
Filesystem::assertExists($pid_dir);
Filesystem::assertIsDirectory($pid_dir);
Filesystem::assertWritable($pid_dir);
$config['piddir'] = $pid_dir;
$config['daemons'] = $daemons;
$command = csprintf('./phd-daemon %Ls', $flags);

View file

@ -1,128 +1,10 @@
<?php
// TODO: See T13321. After the removal of daemon PID files this class
// no longer makes as much sense as it once did.
final class PhabricatorDaemonReference extends Phobject {
private $name;
private $argv;
private $pid;
private $start;
private $pidFile;
private $daemonLog;
public static function loadReferencesFromFile($path) {
$pid_data = Filesystem::readFile($path);
try {
$dict = phutil_json_decode($pid_data);
} catch (PhutilJSONParserException $ex) {
$dict = array();
}
$refs = array();
$daemons = idx($dict, 'daemons', array());
$logs = array();
$daemon_ids = ipull($daemons, 'id');
if ($daemon_ids) {
try {
$logs = id(new PhabricatorDaemonLogQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withDaemonIDs($daemon_ids)
->execute();
} catch (AphrontQueryException $ex) {
// Ignore any issues here; getting this information only allows us
// to provide a more complete picture of daemon status, and we want
// these commands to work if the database is inaccessible.
}
$logs = mpull($logs, null, 'getDaemonID');
}
// Support PID files that use the old daemon format, where each overseer
// had exactly one daemon. We can eventually remove this; they will still
// be stopped by `phd stop --force` even if we don't identify them here.
if (!$daemons && idx($dict, 'name')) {
$daemons = array(
array(
'config' => array(
'class' => idx($dict, 'name'),
'argv' => idx($dict, 'argv', array()),
),
),
);
}
foreach ($daemons as $daemon) {
$ref = new PhabricatorDaemonReference();
// NOTE: This is the overseer PID, not the actual daemon process PID.
// This is correct for checking status and sending signals (the only
// things we do with it), but might be confusing. $daemon['pid'] has
// the daemon PID, and we could expose that if we had some use for it.
$ref->pid = idx($dict, 'pid');
$ref->start = idx($dict, 'start');
$config = idx($daemon, 'config', array());
$ref->name = idx($config, 'class');
$ref->argv = idx($config, 'argv', array());
$log = idx($logs, idx($daemon, 'id'));
if ($log) {
$ref->daemonLog = $log;
}
$ref->pidFile = $path;
$refs[] = $ref;
}
return $refs;
}
public function updateStatus($new_status) {
if (!$this->daemonLog) {
return;
}
try {
$this->daemonLog
->setStatus($new_status)
->save();
} catch (AphrontQueryException $ex) {
// Ignore anything that goes wrong here.
}
}
public function getPID() {
return $this->pid;
}
public function getName() {
return $this->name;
}
public function getArgv() {
return $this->argv;
}
public function getEpochStarted() {
return $this->start;
}
public function getPIDFile() {
return $this->pidFile;
}
public function getDaemonLog() {
return $this->daemonLog;
}
public function isRunning() {
return self::isProcessRunning($this->getPID());
}
public static function isProcessRunning($pid) {
if (!$pid) {
return false;
@ -148,15 +30,4 @@ final class PhabricatorDaemonReference extends Phobject {
return $is_running;
}
public function waitForExit($seconds) {
$start = time();
while (time() < $start + $seconds) {
usleep(100000);
if (!$this->isRunning()) {
return true;
}
}
return !$this->isRunning();
}
}