[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class PhabricatorDaemon extends PhutilDaemon { 4 5 protected function willRun() { 6 parent::willRun(); 7 8 $phabricator = phutil_get_library_root('phabricator'); 9 $root = dirname($phabricator); 10 require_once $root.'/scripts/__init_script__.php'; 11 } 12 13 protected function willSleep($duration) { 14 LiskDAO::closeAllConnections(); 15 return; 16 } 17 18 public function getViewer() { 19 return PhabricatorUser::getOmnipotentUser(); 20 } 21 22 23 /** 24 * Format a command so it executes as the daemon user, if a daemon user is 25 * defined. This wraps the provided command in `sudo -u ...`, roughly. 26 * 27 * @param PhutilCommandString Command to execute. 28 * @return PhutilCommandString `sudo` version of the command. 29 */ 30 public static function sudoCommandAsDaemonUser($command) { 31 $user = PhabricatorEnv::getEnvConfig('phd.user'); 32 if (!$user) { 33 // No daemon user is set, so just run this as ourselves. 34 return $command; 35 } 36 37 // Get the absolute path so we're safe against the caller wiping out 38 // PATH. 39 $sudo = Filesystem::resolveBinary('sudo'); 40 if (!$sudo) { 41 throw new Exception(pht("Unable to find 'sudo'!")); 42 } 43 44 // Flags here are: 45 // 46 // -E: Preserve the environment. 47 // -n: Non-interactive. Exit with an error instead of prompting. 48 // -u: Which user to sudo to. 49 50 return csprintf('%s -E -n -u %s -- %C', $sudo, $user, $command); 51 } 52 53 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |