mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 00:02:41 +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:
parent
6771a70499
commit
09f3d0bb7e
3 changed files with 45 additions and 28 deletions
|
@ -8,20 +8,11 @@
|
||||||
$root = dirname(dirname(dirname(__FILE__)));
|
$root = dirname(dirname(dirname(__FILE__)));
|
||||||
require_once $root.'/scripts/__init_script__.php';
|
require_once $root.'/scripts/__init_script__.php';
|
||||||
|
|
||||||
$flags = array();
|
$overseer = new PhutilDaemonOverseer($argv);
|
||||||
|
|
||||||
$bootloader = PhutilBootloader::getInstance();
|
$bootloader = PhutilBootloader::getInstance();
|
||||||
foreach ($bootloader->getAllLibraries() as $library) {
|
foreach ($bootloader->getAllLibraries() as $library) {
|
||||||
if ($library == 'phutil') {
|
$overseer->addLibrary(phutil_get_library_root($library));
|
||||||
// No need to load libphutil, it's necessarily loaded implicitly by the
|
|
||||||
// daemon itself.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$flags[] = '--load-phutil-library='.phutil_get_library_root($library);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add more flags.
|
|
||||||
array_splice($argv, 2, 0, $flags);
|
|
||||||
|
|
||||||
$overseer = new PhutilDaemonOverseer($argv);
|
|
||||||
$overseer->run();
|
$overseer->run();
|
||||||
|
|
|
@ -165,10 +165,6 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($argv as $key => $arg) {
|
|
||||||
$argv[$key] = escapeshellarg($arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
$flags = array();
|
$flags = array();
|
||||||
if ($debug || PhabricatorEnv::getEnvConfig('phd.trace')) {
|
if ($debug || PhabricatorEnv::getEnvConfig('phd.trace')) {
|
||||||
$flags[] = '--trace';
|
$flags[] = '--trace';
|
||||||
|
@ -178,13 +174,14 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
$flags[] = '--verbose';
|
$flags[] = '--verbose';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$config = array();
|
||||||
|
|
||||||
if (!$debug) {
|
if (!$debug) {
|
||||||
$flags[] = '--daemonize';
|
$config['daemonize'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$debug) {
|
if (!$debug) {
|
||||||
$log_file = $this->getLogDirectory().'/daemons.log';
|
$config['log'] = $this->getLogDirectory().'/daemons.log';
|
||||||
$flags[] = csprintf('--log=%s', $log_file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$pid_dir = $this->getPIDDirectory();
|
$pid_dir = $this->getPIDDirectory();
|
||||||
|
@ -194,13 +191,16 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
Filesystem::assertIsDirectory($pid_dir);
|
Filesystem::assertIsDirectory($pid_dir);
|
||||||
Filesystem::assertWritable($pid_dir);
|
Filesystem::assertWritable($pid_dir);
|
||||||
|
|
||||||
$flags[] = csprintf('--phd=%s', $pid_dir);
|
$config['piddir'] = $pid_dir;
|
||||||
|
|
||||||
$command = csprintf(
|
$config['daemons'] = array(
|
||||||
'./phd-daemon %s %C %C',
|
array(
|
||||||
$daemon,
|
'class' => $daemon,
|
||||||
implode(' ', $flags),
|
'argv' => $argv,
|
||||||
implode(' ', $argv));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$command = csprintf('./phd-daemon %Ls', $flags);
|
||||||
|
|
||||||
$phabricator_root = dirname(phutil_get_library_root('phabricator'));
|
$phabricator_root = dirname(phutil_get_library_root('phabricator'));
|
||||||
$daemon_script_dir = $phabricator_root.'/scripts/daemon/';
|
$daemon_script_dir = $phabricator_root.'/scripts/daemon/';
|
||||||
|
@ -214,12 +214,20 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
|
|
||||||
echo "\n phabricator/scripts/daemon/ \$ {$command}\n\n";
|
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 {
|
} else {
|
||||||
try {
|
try {
|
||||||
$this->executeDaemonLaunchCommand(
|
$this->executeDaemonLaunchCommand(
|
||||||
$command,
|
$command,
|
||||||
$daemon_script_dir,
|
$daemon_script_dir,
|
||||||
|
$config,
|
||||||
$this->runDaemonsAsUser);
|
$this->runDaemonsAsUser);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// Retry without sudo
|
// Retry without sudo
|
||||||
|
@ -227,7 +235,8 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
"sudo command failed. Starting daemon as current user\n"));
|
"sudo command failed. Starting daemon as current user\n"));
|
||||||
$this->executeDaemonLaunchCommand(
|
$this->executeDaemonLaunchCommand(
|
||||||
$command,
|
$command,
|
||||||
$daemon_script_dir);
|
$daemon_script_dir,
|
||||||
|
$config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,6 +244,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
private function executeDaemonLaunchCommand(
|
private function executeDaemonLaunchCommand(
|
||||||
$command,
|
$command,
|
||||||
$daemon_script_dir,
|
$daemon_script_dir,
|
||||||
|
array $config,
|
||||||
$run_as_user = null) {
|
$run_as_user = null) {
|
||||||
|
|
||||||
$is_sudo = false;
|
$is_sudo = false;
|
||||||
|
@ -250,6 +260,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
||||||
$future = new ExecFuture('exec %C', $command);
|
$future = new ExecFuture('exec %C', $command);
|
||||||
// Play games to keep 'ps' looking reasonable.
|
// Play games to keep 'ps' looking reasonable.
|
||||||
$future->setCWD($daemon_script_dir);
|
$future->setCWD($daemon_script_dir);
|
||||||
|
$future->write(json_encode($config));
|
||||||
list($stdout, $stderr) = $future->resolvex();
|
list($stdout, $stderr) = $future->resolvex();
|
||||||
|
|
||||||
if ($is_sudo) {
|
if ($is_sudo) {
|
||||||
|
|
|
@ -27,8 +27,23 @@ final class PhabricatorDaemonReference {
|
||||||
public static function newFromDictionary(array $dict) {
|
public static function newFromDictionary(array $dict) {
|
||||||
$ref = new PhabricatorDaemonReference();
|
$ref = new PhabricatorDaemonReference();
|
||||||
|
|
||||||
$ref->name = idx($dict, 'name', 'Unknown');
|
// TODO: This is a little rough during the transition from one-to-one
|
||||||
$ref->argv = idx($dict, 'argv', array());
|
// 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->pid = idx($dict, 'pid');
|
||||||
$ref->start = idx($dict, 'start');
|
$ref->start = idx($dict, 'start');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue