Differential D11041 Diff 26517 src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php
Show First 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | if ($debug) { | ||||
phutil_passthru('(cd %s && exec %C)', $daemon_script_dir, $command); | phutil_passthru('(cd %s && exec %C)', $daemon_script_dir, $command); | ||||
} else { | } else { | ||||
try { | try { | ||||
$this->executeDaemonLaunchCommand( | $this->executeDaemonLaunchCommand( | ||||
$command, | $command, | ||||
$daemon_script_dir, | $daemon_script_dir, | ||||
$this->runDaemonsAsUser); | $this->runDaemonsAsUser); | ||||
} catch (CommandException $e) { | } catch (Exception $e) { | ||||
// Retry without sudo | // Retry without sudo | ||||
$console->writeOut(pht( | $console->writeOut(pht( | ||||
"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); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
private function executeDaemonLaunchCommand( | private function executeDaemonLaunchCommand( | ||||
$command, | $command, | ||||
$daemon_script_dir, | $daemon_script_dir, | ||||
$run_as_user = null) { | $run_as_user = null) { | ||||
$is_sudo = false; | |||||
if ($run_as_user) { | if ($run_as_user) { | ||||
// If anything else besides sudo should be | // If anything else besides sudo should be | ||||
// supported then insert it here (runuser, su, ...) | // supported then insert it here (runuser, su, ...) | ||||
$command = csprintf( | $command = csprintf( | ||||
'sudo -En -u %s -- %C', | 'sudo -En -u %s -- %C', | ||||
$run_as_user, | $run_as_user, | ||||
$command); | $command); | ||||
$is_sudo = true; | |||||
} | } | ||||
$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->resolvex(); | list($stdout, $stderr) = $future->resolvex(); | ||||
if ($is_sudo) { | |||||
// On OSX, `sudo -n` exits 0 when the user does not have permission to | |||||
// switch accounts without a password. This is not consistent with | |||||
// sudo on Linux, and seems buggy/broken. Check for this by string | |||||
// matching the output. | |||||
if (preg_match('/sudo: a password is required/', $stderr)) { | |||||
throw new Exception( | |||||
pht( | |||||
'sudo exited with a zero exit code, but emitted output '. | |||||
'consistent with failure under OSX.')); | |||||
} | |||||
} | |||||
} | } | ||||
public static function ignoreSignal($signo) { | public static function ignoreSignal($signo) { | ||||
return; | return; | ||||
} | } | ||||
public static function requireExtensions() { | public static function requireExtensions() { | ||||
self::mustHaveExtension('pcntl'); | self::mustHaveExtension('pcntl'); | ||||
▲ Show 20 Lines • Show All 277 Lines • Show Last 20 Lines |