Example #1
0
 public function execute()
 {
     ob_start();
     if ($this->runmodes['help'] == true) {
         echo 'Usage: ' . $argv[0] . ' [runmodes]' . "\n";
         echo 'Available runmodes:' . "\n";
         foreach ($this->runmodes as $runmode) {
             echo ' --' . $runmode . "\n";
         }
         die;
     }
     System_Daemon::setOptions($this->options);
     if (!$this->runmodes['no-daemon']) {
         System_Daemon::start();
     }
     if (!$this->runmodes['write-initd']) {
         System_Daemon::info('not writing an init.d script this time');
     } else {
         if (($initd_location = System_Daemon::writeAutoRun()) === false) {
             System_Daemon::notice('unable to write init.d script');
         } else {
             System_Daemon::info('sucessfully written startup script: %s', $initd_location);
         }
     }
     $this->application->dataLink->disconnect();
     $this->application->dataLink->connect();
     while (!System_Daemon::isDying() && $this->status == self::RUN) {
         $this->process();
         System_Daemon::iterate($this->ownOptions['sleep']);
         $output = ob_get_contents();
         if ($output != '') {
             System_Daemon::info($output);
         }
         ob_clean();
     }
 }
Example #2
0
    // What mode are we in?
    // $mode = '"' . (System_Daemon::isInBackground() ? '' : 'non-' ) .
    //         'daemon" mode';
    // System_Daemon::info('{appName}  in %s %s/300', $a, $b);
    try {
        require_once 'lib/php/beanstalkd/ColaMensajes.php';
        $colaMensajes = new ColaMensajes("transformarvideos");
        $job = $colaMensajes->pop();
        if ($job == "") {
            //Time out
            //System_Daemon::info("Time out!");
        } else {
            $json = $job->getData();
            require_once 'modulos/videos/controladores/videoControlador.php';
            if (transformar($json)) {
                System_Daemon::notice('Video transformado correctamente');
            } else {
                System_Daemon::info("ERROR! el resultado de la transformación no es cero");
            }
            $colaMensajes->deleteJob($job);
        }
    } catch (Exception $e) {
        System_Daemon::info('ERROR! %s', $e->getMessage());
    }
    if (!$runningOkay) {
        System_Daemon::err('parseLog() produced an error, ' . 'so this will be my last run');
    }
    // Relax the system by sleeping for a little bit iterate also clears statcache
    System_Daemon::iterate(2);
}
// Shut down the daemon nicely
// Setup
$options = array('appName' => 'logparser', 'appDir' => dirname(__FILE__), 'appDescription' => 'Parses vsftpd logfiles and stores them in MySQL', 'authorName' => 'Kevin van Zonneveld', 'authorEmail' => '*****@*****.**', 'sysMaxExecutionTime' => '0', 'sysMaxInputTime' => '0', 'sysMemoryLimit' => '1024M', 'appRunAsGID' => 1000, 'appRunAsUID' => 1000);
System_Daemon::setOptions($options);
// This program can also be run in the forground with runmode --no-daemon
if (!$runmode['no-daemon']) {
    // Spawn Daemon
    System_Daemon::start();
}
// With the runmode --write-initd, this program can automatically write a
// system startup file called: 'init.d'
// This will make sure your daemon will be started on reboot
if (!$runmode['write-initd']) {
    System_Daemon::info('not writing an init.d script this time');
} else {
    if (($initd_location = System_Daemon::writeAutoRun()) === false) {
        System_Daemon::notice('unable to write init.d script');
    } else {
        System_Daemon::info('sucessfully written startup script: %s', $initd_location);
    }
}
// Run your code
// Here comes your own actual code
// This variable gives your own code the ability to breakdown the daemon:
$runningOkay = true;
// This variable keeps track of how many 'runs' or 'loops' your daemon has
// done so far. For example purposes, we're quitting on 3.
$cnt = 1;
// While checks on 3 things in this case:
// - That the Daemon Class hasn't reported it's dying
// - That your own code has been running Okay
// - That we're not executing more than 3 runs