Exemple #1
0
 public function report()
 {
     /*{{{*/
     CronLogger::info(json_encode($this->last_execute_info));
     CronLogger::message(array('type' => 'task-run', 'id' => $this->id, 'user' => $this->user, 'time' => time(), 'result' => $this->last_execute_info));
 }
Exemple #2
0
 public function handleCommand($data)
 {
     /*{{{*/
     $ret = true;
     switch ($data['command']) {
         case 'stop':
             $pid = (int) file_get_contents($this->pid_file);
             if ($pid) {
                 $ret = posix_kill($pid, SIGTERM);
             }
             break;
         case 'exec':
             $command_list = $data['option'];
             foreach ($command_list as $command) {
                 $ret = CronShell::execute($command);
                 $message[] = array($command => $ret);
             }
             CronLogger::message(array('type' => 'host-cmd', 'host' => $data['host'], 'user' => $data['user'], 'time' => time(), 'message' => $message));
             break;
     }
 }
Exemple #3
0
 private function daemonize()
 {
     /*{{{*/
     global $daemon;
     $daemon = true;
     $pid = pcntl_fork();
     if ($pid) {
         exit(0);
     } else {
         if ($pid < 0) {
             CronLogger::err("Fork failed\n");
             exit(1);
         }
     }
     chdir(dirname(__FILE__));
     $sid = posix_setsid();
     if (!$sid) {
         CronLogger::err("Set sid failed\n");
         exit(1);
     }
     if (!$this->createPidFile()) {
         return false;
     }
     fclose(STDIN);
     fclose(STDOUT);
     fclose(STDERR);
     global $STDOUT;
     global $STDERR;
     $STDOUT = fopen('/dev/null', 'w');
     $STDERR = $STDOUT;
     return true;
 }