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(); } }
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(); } }
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; }
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 */ $sl = new SyncLib('ykval-queue:synclib'); # Loop forever and resync $res == 0; while ($res == 0) { $sl->reSync($baseParams['__YKVAL_SYNC_OLD_LIMIT__'], $baseParams['__YKVAL_SYNC_RESYNC_TIMEOUT__']); $res = sleep($baseParams['__YKVAL_SYNC_INTERVAL__']); } System_Daemon::stop();
/** * start pcntl based daemon * * @return void */ private function _daemonStart() { $options = array('appName' => 'osclog', 'appDir' => dirname(__FILE__), 'appDescription' => 'logs osc messages', 'sysMaxExecutionTime' => '0', 'sysMaxInputTime' => '0', 'sysMemoryLimit' => '1024M'); System_Daemon::setOptions($options); System_Daemon::start(); }