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();
     }
 }
    echo $argv[0] . " install  \t- Installs start scripts for daemon\n";
    echo $argv[0] . " file     \t- Starts sync daemon. file is sourced and can include for example path configuration\n";
    echo "\n";
    exit;
}
if ($argc == 2 && strcmp($argv[1], "install") != 0) {
    set_include_path(get_include_path() . PATH_SEPARATOR . $argv[1]);
}
require_once "System/Daemon.php";
$appname = "ykval-queue";
System_Daemon::setOption("appName", $appname);
System_Daemon::setOption("appDescription", "Yubico val-server sync daemon");
System_Daemon::setOption("authorName", "*****@*****.**");
System_Daemon::setOption("authorEmail", "*****@*****.**");
if ($argc == 2 && strcmp($argv[1], "install") == 0) {
    $autostart_path = System_Daemon::writeAutoRun();
    if ($autostart_path != 1) {
        echo "Successfully created start script at " . $autostart_path . "\n";
        echo "To start daemon use: /etc/init.d/" . $appname . " start\n";
    } else {
        echo "Start script already created\n";
        echo "To start daemon use: /etc/init.d/" . $appname . " start\n";
    }
    exit;
}
require_once 'ykval-synclib.php';
require_once 'ykval-config.php';
require_once 'ykval-log.php';
System_Daemon::start();
// Spawn Deamon!
/* Application start */
Example #3
0
$options = array("appName" => "mercury", "appDir" => dirname(__FILE__), "appDescription" => "Informs the user of their social interactions.", "authorName" => "Alastair Dewar", "authorEmail" => "*****@*****.**", "sysMaxExecutionTime" => "0", "sysMaxInputTime" => "0", "sysMemoryLimit" => "256M", "appRunAsGID" => 1000, "appRunAsUID" => 1000);
System_Daemon::setOptions($options);
// Overrule the signal handler with any function
System_Daemon::setSigHandler(SIGCONT, array("System_Daemon", "defaultSigHandler"));
// 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::log(System_Daemon::LOG_INFO, "not writing " . "an init.d script this time");
} else {
    if (($initd_location = System_Daemon::writeAutoRun()) === false) {
        System_Daemon::log(System_Daemon::LOG_NOTICE, "unable to write " . "init.d script");
    } else {
        System_Daemon::log(System_Daemon::LOG_INFO, "sucessfully written " . "startup script: " . $initd_location);
    }
}
// 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