function start($argv)
 {
     $appName = $this->appName;
     if (file_exists($this->command_file())) {
         unlink($this->command_file());
     }
     if (array_search("--background", $argv)) {
         System_Daemon::setOption("appName", $appName);
         System_Daemon::setOption("appRunAsUID", posix_getuid());
         System_Daemon::setOption("appRunAsGID", posix_getgid());
         System_Daemon::setOption("logLocation", getenv('WSETCDIR') . "/logs/{$appName}");
         System_Daemon::setOption("appPidLocation", getenv('WSETCDIR') . "/pushd/{$appName}/{$appName}.pid");
         System_Daemon::setOption('logPhpErrors', true);
         System_Daemon::setOption('logFilePosition', true);
         System_Daemon::setOption('logLinePosition', true);
         System_Daemon::start();
     }
 }
Пример #2
0
 public function runTaskAsDaemon($task_name, $options = array())
 {
     $this->_ensurePosixAndPcntlAreAvailable();
     require_once 'System/Daemon.php';
     $app_name = AkInflector::underscore($task_name);
     $pid_file = AK_BASE_DIR . DS . 'run' . DS . $app_name . DS . $app_name . '.pid';
     $log_file = AK_LOG_DIR . DS . 'daemons' . DS . $app_name . '.log';
     if (!file_exists($pid_file)) {
         if (empty($options['attributes']['kill'])) {
             AkFileSystem::file_put_contents($pid_file, '');
             AkFileSystem::file_delete($pid_file);
         } else {
             $this->error("Could not kill process for {$task_name}", true);
         }
     } else {
         $pid = (int) file_get_contents($pid_file);
         if ($pid > 0) {
             if (!empty($options['attributes']['kill'])) {
                 $this->message("Killing process {$pid}");
                 `kill {$pid}`;
                 AkFileSystem::file_delete($pid_file);
                 die;
             } elseif (!empty($options['attributes']['restart'])) {
                 $this->message("Restarting {$task_name}.");
                 $this->message(`kill {$pid}`);
             } else {
                 $this->error("Daemon for {$task_name} still running ({$pid_file}).\nTask aborted.", true);
             }
         }
     }
     if (!empty($options['attributes']['kill']) && empty($pid)) {
         $this->error("No daemon running for task {$task_name}", true);
     }
     unset($options['attributes']['restart']);
     if (!file_exists($log_file)) {
         AkFileSystem::file_put_contents($log_file, '');
     }
     System_Daemon::setOption('appName', $app_name);
     System_Daemon::setOption('appDir', AK_BASE_DIR);
     System_Daemon::setOption('logLocation', $log_file);
     System_Daemon::setOption('appRunAsUID', posix_geteuid());
     System_Daemon::setOption('appRunAsGID', posix_getgid());
     System_Daemon::setOption('appPidLocation', $pid_file);
     $this->message("Staring daemon. ({$log_file})");
     System_Daemon::start();
     $dsn = Ak::getStaticVar('dsn');
     defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ? null : Ak::db($dsn);
     $this->runTask($task_name, $options);
     System_Daemon::stop();
     AkFileSystem::file_delete($pid_file);
     die;
 }
if ($argc == 2 && strcmp($argv[1], "help") == 0) {
    echo "\nUsage:\n\n";
    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();
Пример #4
0
 *
 * @category  System
 * @package   System_Daemon
 * @author    Kevin <*****@*****.**>
 * @copyright 2009 Kevin van Zonneveld
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD Licence
 * @link      http://github.com/kvz/system_daemon
 */
/**
 * System_Daemon Example Code
 * 
 * If you run this code successfully, a daemon will be spawned
 * and stopped directly. You should find a log enty in 
 * /var/log/simple.log
 * 
 */
// Make it possible to test in source directory
// This is for PEAR developers only
ini_set('include_path', ini_get('include_path') . ':..');
// Include Class
error_reporting(E_ALL);
require_once "System/Daemon.php";
// Bare minimum setup
System_Daemon::setOption("appName", "mydaemon");
System_Daemon::setOption("appPidLocation", "/tmp/mydaemon.pid");
System_Daemon::setOption("logLocation", "/tmp/mydaemon.log");
// System_Daemon::setOption("appDir", dirname(__FILE__));
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon not yet started so " . "this will be written on-screen");
// Spawn Deamon!
System_Daemon::start();
System_Daemon::stop();
Пример #5
0
 * @copyright 2008 Kevin van Zonneveld
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD Licence
 * @link      http://github.com/kvz/system_daemon
 */
/**
 * System_Daemon Example Code
 * 
 * If you run this code successfully, a daemon will be spawned
 * and stopped directly. You should find a log enty in 
 * /var/log/simple.log
 * 
 */
// Make it possible to test in source directory
// This is for PEAR developers only
ini_set('include_path', ini_get('include_path') . ':..');
// Include Class
error_reporting(E_ALL);
require_once "System/Daemon.php";
// No PEAR, run standalone
System_Daemon::setOption("usePEAR", false);
// Bare minimum setup
System_Daemon::setOption("appName", "nopear");
System_Daemon::setOption("appDir", dirname(__FILE__));
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon not yet started so this " . "will be written on-screen");
// Spawn Deamon!
System_Daemon::start();
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon: '" . System_Daemon::getOption("appName") . "' spawned! This will be written to " . System_Daemon::getOption("logLocation"));
// Your normal PHP code goes here. Only the code will run in the background
// so you can close your terminal session, and the application will
// still run.
System_Daemon::stop();
Пример #6
0
<?php

$path = '/Applications/XAMPP/xamppfiles/lib/php/pear/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
$path = './libs/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'System/Daemon.php';
System_Daemon::setOption("appName", "FastAGI");
System_Daemon::setOption("authorEmail", "*****@*****.**");
System_Daemon::start();
ob_implicit_flush(true);
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
require_once 'Net/Server.php';
require_once 'libs/FastAGI.php';
$server = Net_Server::create('fork', '127.0.0.1', 10045);
$server->setEndCharacter("\n\n");
$server->setCallbackObject(new FastAGI());
$server->start();
System_Daemon::stop();
Пример #7
0
 * If you run this code successfully, a daemon will be spawned
 * and stopped directly. You should find a log enty in
 * /var/log/simple.log
 *
 */
// Make it possible to test in source directory
// This is for PEAR developers only
ini_set('include_path', ini_get('include_path') . ':..');
// Include Class
error_reporting(E_ALL);
require_once "System/Daemon.php";
// Bare minimum setup
System_Daemon::setOption("appName", "phperrtest");
System_Daemon::setOption("authorEmail", "*****@*****.**");
System_Daemon::setOption('logPhpErrors', true);
System_Daemon::setOption('logFilePosition', true);
System_Daemon::setOption('logLinePosition', true);
//System_Daemon::setOption("appDir", dirname(__FILE__));
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon not yet started so " . "this will be written on-screen");
// Spawn Deamon!
System_Daemon::start();
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon: '" . System_Daemon::getOption("appName") . "' spawned! This will be written to " . System_Daemon::getOption("logLocation"));
$x = 1;
System_Daemon::log(System_Daemon::LOG_WARNING, 'Test');
foreach ($x as $k => $v) {
    // should break and generate PHP warnings
}
// Your normal PHP code goes here. Only the code will run in the background
// so you can close your terminal session, and the application will
// still run.
System_Daemon::stop();
Пример #8
0
<?php

require_once "../System/Daemon.php";
System_Daemon::setOption("appName", "leakplugger");
System_Daemon::start();
$last = 0;
while (!System_Daemon::isDying()) {
    $mem = memory_get_peak_usage();
    $use = $mem - $last;
    if ($use >= 0) {
        $use = '+' . $use;
    }
    System_Daemon::info("test");
    echo "debug: memory_get_peak_usage: " . $use . "\n";
    $last = $mem;
    System_Daemon::iterate(1);
}
Пример #9
0
 * @author    Kevin <*****@*****.**>
 * @copyright 2008 Kevin van Zonneveld
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD Licence
 * @link      http://github.com/kvz/system_daemon
 */
/**
 * System_Daemon Example Code
 * 
 * If you run this code successfully, a daemon will be spawned
 * and stopped directly. You should find a log enty in 
 * /var/log/simple.log
 * 
 */
// Make it possible to test in source directory
// This is for PEAR developers only
ini_set('include_path', ini_get('include_path') . ':..');
// Include Class
error_reporting(E_ALL);
require_once "System/Daemon.php";
// Bare minimum setup
System_Daemon::setOption("appName", "simple");
System_Daemon::setOption("authorEmail", "*****@*****.**");
//System_Daemon::setOption("appDir", dirname(__FILE__));
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon not yet started so " . "this will be written on-screen");
// Spawn Deamon!
System_Daemon::start();
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon: '" . System_Daemon::getOption("appName") . "' spawned! This will be written to " . System_Daemon::getOption("logLocation"));
// Your normal PHP code goes here. Only the code will run in the background
// so you can close your terminal session, and the application will
// still run.
System_Daemon::stop();
Пример #10
0
 * @copyright 2008 Kevin van Zonneveld
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD Licence
 * @link      http://github.com/kvz/system_daemon
 */
/**
 * System_Daemon Example Code
 * 
 * If you run this code successfully, a daemon will be spawned
 * and stopped directly. You should find a log enty in 
 * /var/log/simple.log
 * 
 */
// Make it possible to test in source directory
// This is for PEAR developers only
ini_set('include_path', ini_get('include_path') . ':..');
// Include Class
error_reporting(E_ALL);
require_once "System/Daemon.php";
// No PEAR, run standalone
System_Daemon::setOption("usePEAR", false);
// Bare minimum setup
System_Daemon::setOption("appName", "FollowListener");
System_Daemon::setOption("appDir", '/var/lib/listener');
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon not yet started so this " . "will be written on-screen");
// Spawn Deamon!
System_Daemon::start();
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon: '" . System_Daemon::getOption("appName") . "' spawned! This will be written to " . System_Daemon::getOption("logLocation"));
// Your normal PHP code goes here. Only the code will run in the background
// so you can close your terminal session, and the application will
// still run.
System_Daemon::stop();
Пример #11
0
    $details = $os->getDetails();
    echo '\\n';
    print_r($details);
    echo '\\n';
}
die;
if (($res = $os->writeAutoRun($options, true)) === false) {
    print_r($os->errors);
} elseif ($res === true) {
    echo 'alread written\\n';
} else {
    echo 'written to ' . $res . '\\n';
}
/*if (!$os->setAutoRunProperties($options)) {
    print_r($os->errors);
}
*/
die;
// Bare minimum setup
System_Daemon::setOption('appName', 'optest');
System_Daemon::setOption('authorEmail', '*****@*****.**');
die;
//System_Daemon::setOption('appDir', dirname(__FILE__));
System_Daemon::log(System_Daemon::LOG_INFO, 'Daemon not yet started so ' . 'this will be written on-screen');
// Spawn Deamon!
System_Daemon::start();
System_Daemon::log(System_Daemon::LOG_INFO, 'Daemon: \'' . System_Daemon::getOption('appName') . '\' spawned! This will be written to ' . System_Daemon::getOption('logLocation'));
// Your normal PHP code goes here. Only the code will run in the background
// so you can close your terminal session, and the application will
// still run.
System_Daemon::stop();
Пример #12
0
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD Licence
 * @link      http://github.com/kvz/system_daemon
 */
/**
 * System_Daemon Example Code
 * 
 * If you run this code successfully, a daemon will be spawned
 * and stopped directly. You should find a log enty in 
 * /var/log/pearlog.log
 * 
 */
// Make it possible to test in source directory
// This is for PEAR developers only
ini_set('include_path', ini_get('include_path') . ':..');
// Include Class
error_reporting(E_ALL);
require_once "System/Daemon.php";
// Initialize PEAR_Log instance
$my_log_instance =& Log::factory('file', '/tmp/pearlog.log', 'pearlog');
// Bare minimum setup
System_Daemon::setOption("appName", "pearlog");
System_Daemon::setOption("appDir", dirname(__FILE__));
System_Daemon::setOption("usePEARLogInstance", $my_log_instance);
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon not yet started. " . "Every logline will end up in whatever usePEARLogInstance->log() says");
// Spawn Deamon!
System_Daemon::start();
System_Daemon::log(System_Daemon::LOG_INFO, "Daemon started. " . "Every logline will end up in whatever usePEARLogInstance->log() says");
// Your normal PHP code goes here. Only the code will run in the background
// so you can close your terminal session, and the application will
// still run.
System_Daemon::stop();