@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.

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

+45 -28
+2 -11
scripts/daemon/launch_daemon.php
··· 8 8 $root = dirname(dirname(dirname(__FILE__))); 9 9 require_once $root.'/scripts/__init_script__.php'; 10 10 11 - $flags = array(); 11 + $overseer = new PhutilDaemonOverseer($argv); 12 12 13 13 $bootloader = PhutilBootloader::getInstance(); 14 14 foreach ($bootloader->getAllLibraries() as $library) { 15 - if ($library == 'phutil') { 16 - // No need to load libphutil, it's necessarily loaded implicitly by the 17 - // daemon itself. 18 - continue; 19 - } 20 - $flags[] = '--load-phutil-library='.phutil_get_library_root($library); 15 + $overseer->addLibrary(phutil_get_library_root($library)); 21 16 } 22 17 23 - // Add more flags. 24 - array_splice($argv, 2, 0, $flags); 25 - 26 - $overseer = new PhutilDaemonOverseer($argv); 27 18 $overseer->run();
+26 -15
src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php
··· 165 165 } 166 166 } 167 167 168 - foreach ($argv as $key => $arg) { 169 - $argv[$key] = escapeshellarg($arg); 170 - } 171 - 172 168 $flags = array(); 173 169 if ($debug || PhabricatorEnv::getEnvConfig('phd.trace')) { 174 170 $flags[] = '--trace'; ··· 177 173 if ($debug || PhabricatorEnv::getEnvConfig('phd.verbose')) { 178 174 $flags[] = '--verbose'; 179 175 } 176 + 177 + $config = array(); 180 178 181 179 if (!$debug) { 182 - $flags[] = '--daemonize'; 180 + $config['daemonize'] = true; 183 181 } 184 182 185 183 if (!$debug) { 186 - $log_file = $this->getLogDirectory().'/daemons.log'; 187 - $flags[] = csprintf('--log=%s', $log_file); 184 + $config['log'] = $this->getLogDirectory().'/daemons.log'; 188 185 } 189 186 190 187 $pid_dir = $this->getPIDDirectory(); ··· 194 191 Filesystem::assertIsDirectory($pid_dir); 195 192 Filesystem::assertWritable($pid_dir); 196 193 197 - $flags[] = csprintf('--phd=%s', $pid_dir); 194 + $config['piddir'] = $pid_dir; 198 195 199 - $command = csprintf( 200 - './phd-daemon %s %C %C', 201 - $daemon, 202 - implode(' ', $flags), 203 - implode(' ', $argv)); 196 + $config['daemons'] = array( 197 + array( 198 + 'class' => $daemon, 199 + 'argv' => $argv, 200 + ), 201 + ); 202 + 203 + $command = csprintf('./phd-daemon %Ls', $flags); 204 204 205 205 $phabricator_root = dirname(phutil_get_library_root('phabricator')); 206 206 $daemon_script_dir = $phabricator_root.'/scripts/daemon/'; ··· 214 214 215 215 echo "\n phabricator/scripts/daemon/ \$ {$command}\n\n"; 216 216 217 - phutil_passthru('(cd %s && exec %C)', $daemon_script_dir, $command); 217 + $tempfile = new TempFile('daemon.config'); 218 + Filesystem::writeFile($tempfile, json_encode($config)); 219 + 220 + phutil_passthru( 221 + '(cd %s && exec %C < %s)', 222 + $daemon_script_dir, 223 + $command, 224 + $tempfile); 218 225 } else { 219 226 try { 220 227 $this->executeDaemonLaunchCommand( 221 228 $command, 222 229 $daemon_script_dir, 230 + $config, 223 231 $this->runDaemonsAsUser); 224 232 } catch (Exception $e) { 225 233 // Retry without sudo ··· 227 235 "sudo command failed. Starting daemon as current user\n")); 228 236 $this->executeDaemonLaunchCommand( 229 237 $command, 230 - $daemon_script_dir); 238 + $daemon_script_dir, 239 + $config); 231 240 } 232 241 } 233 242 } ··· 235 244 private function executeDaemonLaunchCommand( 236 245 $command, 237 246 $daemon_script_dir, 247 + array $config, 238 248 $run_as_user = null) { 239 249 240 250 $is_sudo = false; ··· 250 260 $future = new ExecFuture('exec %C', $command); 251 261 // Play games to keep 'ps' looking reasonable. 252 262 $future->setCWD($daemon_script_dir); 263 + $future->write(json_encode($config)); 253 264 list($stdout, $stderr) = $future->resolvex(); 254 265 255 266 if ($is_sudo) {
+17 -2
src/infrastructure/daemon/control/PhabricatorDaemonReference.php
··· 27 27 public static function newFromDictionary(array $dict) { 28 28 $ref = new PhabricatorDaemonReference(); 29 29 30 - $ref->name = idx($dict, 'name', 'Unknown'); 31 - $ref->argv = idx($dict, 'argv', array()); 30 + // TODO: This is a little rough during the transition from one-to-one 31 + // overseers to one-to-many. 32 + $config = idx($dict, 'config', array()); 33 + 34 + $daemon_list = null; 35 + if ($config) { 36 + $daemon_list = idx($config, 'daemons'); 37 + } 38 + 39 + if ($daemon_list) { 40 + $ref->name = pht('Overseer Daemon Group'); 41 + $ref->argv = array(); 42 + } else { 43 + $ref->name = idx($dict, 'name', 'Unknown'); 44 + $ref->argv = idx($dict, 'argv', array()); 45 + } 46 + 32 47 $ref->pid = idx($dict, 'pid'); 33 48 $ref->start = idx($dict, 'start'); 34 49