protected function runFile() { // If job should run as another user, we must be on *nix and // must have sudo privileges. $isUnix = $this->helper->getPlatform() === Helper::UNIX; $useSudo = ''; if ($isUnix) { $runAs = $this->config['runAs']; $isRoot = posix_getuid() === 0; if (!empty($runAs) && $isRoot) { $useSudo = "sudo -u {$runAs}"; } } // Start execution. Run in foreground (will block). $command = $this->config['command']; $logfile = $this->getLogfile() ?: $this->helper->getSystemNullDevice(); exec("{$useSudo} {$command} 1>> \"{$logfile}\" 2>&1", $dummy, $retval); if ($retval !== 0) { throw new Exception("Job exited with status '{$retval}'."); } }