1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-28 17:52:43 +01:00

Pass overseer configuration over stdin

Summary:
Ref T7352. This changes `phd` to pass configuration to overseers over stdin. We still run one overseer per daemon.

The "status" stuff needs some cleanup, but it's mostly just UI/cosmetic.

Test Plan:
  - Ran `phd debug`, `phd launch`, `phd start`, `phd status`, `phd stop`, etc.
  - Verified PID files write in a reasonable format.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7352

Differential Revision: https://secure.phabricator.com/D11855
This commit is contained in:
epriestley 2015-02-22 08:43:19 -08:00
parent 6771a70499
commit 09f3d0bb7e
3 changed files with 45 additions and 28 deletions

View file

@ -8,20 +8,11 @@
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
$flags = array();
$overseer = new PhutilDaemonOverseer($argv);
$bootloader = PhutilBootloader::getInstance();
foreach ($bootloader->getAllLibraries() as $library) {
if ($library == 'phutil') {
// No need to load libphutil, it's necessarily loaded implicitly by the
// daemon itself.
continue;
}
$flags[] = '--load-phutil-library='.phutil_get_library_root($library);
$overseer->addLibrary(phutil_get_library_root($library));
}
// Add more flags.
array_splice($argv, 2, 0, $flags);
$overseer = new PhutilDaemonOverseer($argv);
$overseer->run();

View file

@ -165,10 +165,6 @@ abstract class PhabricatorDaemonManagementWorkflow
}
}
foreach ($argv as $key => $arg) {
$argv[$key] = escapeshellarg($arg);
}
$flags = array();
if ($debug || PhabricatorEnv::getEnvConfig('phd.trace')) {
$flags[] = '--trace';
@ -178,13 +174,14 @@ abstract class PhabricatorDaemonManagementWorkflow
$flags[] = '--verbose';
}
$config = array();
if (!$debug) {
$flags[] = '--daemonize';
$config['daemonize'] = true;
}
if (!$debug) {
$log_file = $this->getLogDirectory().'/daemons.log';
$flags[] = csprintf('--log=%s', $log_file);
$config['log'] = $this->getLogDirectory().'/daemons.log';
}
$pid_dir = $this->getPIDDirectory();
@ -194,13 +191,16 @@ abstract class PhabricatorDaemonManagementWorkflow
Filesystem::assertIsDirectory($pid_dir);
Filesystem::assertWritable($pid_dir);
$flags[] = csprintf('--phd=%s', $pid_dir);
$config['piddir'] = $pid_dir;
$command = csprintf(
'./phd-daemon %s %C %C',
$daemon,
implode(' ', $flags),
implode(' ', $argv));
$config['daemons'] = array(
array(
'class' => $daemon,
'argv' => $argv,
),
);
$command = csprintf('./phd-daemon %Ls', $flags);
$phabricator_root = dirname(phutil_get_library_root('phabricator'));
$daemon_script_dir = $phabricator_root.'/scripts/daemon/';
@ -214,12 +214,20 @@ abstract class PhabricatorDaemonManagementWorkflow
echo "\n phabricator/scripts/daemon/ \$ {$command}\n\n";
phutil_passthru('(cd %s && exec %C)', $daemon_script_dir, $command);
$tempfile = new TempFile('daemon.config');
Filesystem::writeFile($tempfile, json_encode($config));
phutil_passthru(
'(cd %s && exec %C < %s)',
$daemon_script_dir,
$command,
$tempfile);
} else {
try {
$this->executeDaemonLaunchCommand(
$command,
$daemon_script_dir,
$config,
$this->runDaemonsAsUser);
} catch (Exception $e) {
// Retry without sudo
@ -227,7 +235,8 @@ abstract class PhabricatorDaemonManagementWorkflow
"sudo command failed. Starting daemon as current user\n"));
$this->executeDaemonLaunchCommand(
$command,
$daemon_script_dir);
$daemon_script_dir,
$config);
}
}
}
@ -235,6 +244,7 @@ abstract class PhabricatorDaemonManagementWorkflow
private function executeDaemonLaunchCommand(
$command,
$daemon_script_dir,
array $config,
$run_as_user = null) {
$is_sudo = false;
@ -250,6 +260,7 @@ abstract class PhabricatorDaemonManagementWorkflow
$future = new ExecFuture('exec %C', $command);
// Play games to keep 'ps' looking reasonable.
$future->setCWD($daemon_script_dir);
$future->write(json_encode($config));
list($stdout, $stderr) = $future->resolvex();
if ($is_sudo) {

View file

@ -27,8 +27,23 @@ final class PhabricatorDaemonReference {
public static function newFromDictionary(array $dict) {
$ref = new PhabricatorDaemonReference();
// TODO: This is a little rough during the transition from one-to-one
// overseers to one-to-many.
$config = idx($dict, 'config', array());
$daemon_list = null;
if ($config) {
$daemon_list = idx($config, 'daemons');
}
if ($daemon_list) {
$ref->name = pht('Overseer Daemon Group');
$ref->argv = array();
} else {
$ref->name = idx($dict, 'name', 'Unknown');
$ref->argv = idx($dict, 'argv', array());
}
$ref->pid = idx($dict, 'pid');
$ref->start = idx($dict, 'start');