Example #1
0
 /**
  * Run all jobs.
  */
 public function run()
 {
     $isUnix = $this->helper->getPlatform() === Helper::UNIX;
     if ($isUnix && !extension_loaded('posix')) {
         throw new Exception('posix extension is required');
     }
     foreach ($this->jobs as $job => $config) {
         if ($isUnix) {
             $this->runUnix($job, $config);
         } else {
             $this->runWindows($job, $config);
         }
     }
 }
Example #2
0
 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() ?: '/dev/null';
     exec("{$useSudo} {$command} 1>> \"{$logfile}\" 2>&1", $dummy, $retval);
     if ($retval !== 0) {
         throw new Exception("Job exited with status '{$retval}'.");
     }
 }
Example #3
0
 /**
  * @covers ::getPlatform
  */
 public function testGetPlatform()
 {
     $actual = $this->helper->getPlatform();
     $this->assertContains($actual, [Helper::UNIX, Helper::WINDOWS]);
 }