function sleep($seconds)
 {
     if (System_Daemon::isInBackground()) {
         // always run one loop;
         if (!$this->oneLoop(False)) {
             return false;
         }
         for ($i < 0; $i < $seconds; $i++) {
             if (!$this->oneLoop()) {
                 return false;
             }
         }
     } else {
         if ($seconds) {
             echo "Beginning process sleep for {$seconds} seconds\n";
             sleep($seconds);
         }
     }
     return true;
 }
Example #2
0
    }
}
// This variable gives your own code the ability to breakdown the daemon:
$runningOkay = true;
require "Mercury.class.php";
$core = new Mercury();
if (!$core->setup_account("twitter", "example", "example")) {
    $runningOkay = false;
    System_Daemon::log(System_Daemon::LOG_ERR, System_Daemon::getOption("appName") . " failed to set up Twitter account.");
}
// While checks on 2 things in this case:
// - That the Daemon Class hasn't reported it's dying
// - That your own code has been running Okay
while (!System_Daemon::isDying() && $runningOkay) {
    // What mode are we in?
    $mode = "'" . (System_Daemon::isInBackground() ? "" : "non-") . "daemon' mode";
    // Log something using the Daemon class's logging facility
    // Depending on runmode it will either end up:
    //  - In the /var/log/mercury.log
    //  - On screen (in case we're not a daemon yet)
    System_Daemon::log(System_Daemon::LOG_INFO, System_Daemon::getOption("appName") . " checking all protocols");
    $core->check_all_protocols();
    // In the actuall logparser program, You could replace 'true'
    // With e.g. a  parseLog('vsftpd') function, and have it return
    // either true on success, or false on failure.
    $runningOkay = true;
    //$runningOkay = parseLog('vsftpd');
    // Should your parseLog('vsftpd') return false, then
    // the daemon is automatically shut down.
    // An extra log entry would be nice, we're using level 3,
    // which is critical.
    }
}
// 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
while (!System_Daemon::isDying() && $runningOkay && $cnt <= 3) {
    // What mode are we in?
    $mode = '"' . (System_Daemon::isInBackground() ? '' : 'non-') . 'daemon" mode';
    // Log something using the Daemon class's logging facility
    // Depending on runmode it will either end up:
    //  - In the /var/log/logparser.log
    //  - On screen (in case we're not a daemon yet)
    System_Daemon::info('{appName} running in %s %s/3', $mode, $cnt);
    // In the actuall logparser program, You could replace 'true'
    // With e.g. a  parseLog('vsftpd') function, and have it return
    // either true on success, or false on failure.
    $runningOkay = true;
    //$runningOkay = parseLog('vsftpd');
    // Should your parseLog('vsftpd') return false, then
    // the daemon is automatically shut down.
    // An extra log entry would be nice, we're using level 3,
    // which is critical.
    // Level 4 would be fatal and shuts down the daemon immediately,