Example #1
0
 /**
  * Sets up OS instance
  *
  * @return boolean
  */
 protected static function _osObjSetup()
 {
     // Create Option Object if nescessary
     if (!self::$_osObj) {
         self::$_osObj = System_Daemon_OS::factory();
     }
     // Still false? This was an error!
     if (!self::$_osObj) {
         return self::emerg('Unable to setup OS object');
     }
     return true;
 }
Example #2
0
 /**
  * Sets up OS instance
  *
  * @return boolean
  */
 protected static function _osObjSetup()
 {
     // Create Option Object if nescessary
     if (self::$_osObj === false) {
         self::$_osObj = System_Daemon_OS::factory();
     }
     // Still false? This was an error!
     if (self::$_osObj === false) {
         self::log(self::LOG_EMERG, "Unable to setup OS object. ");
         return false;
     }
     return true;
 }
Example #3
0
 /**
  * Get the total parent count of a class
  *
  * @param string $class Full classname or instance
  *
  * @return integer
  */
 protected function _getAncestorCount($class)
 {
     return count(System_Daemon_OS::_getAncestors($class));
 }
<?php

require_once 'tests-config.php';
require_once 'System/Daemon.php';
require_once 'System/Daemon/OS.php';
$os = System_Daemon_OS::factory();
$details = $os->getDetails();
echo count($details);
Example #5
0
 /**
  * Loads all the drivers and returns the one for the most specifc OS
  *
  * @param mixed   $force_os boolean or string when you want to enforce an OS
  *                          for testing purposes. CAN BE VERY DANGEROUS IF WRONG OS IS SPECIFIED!
  *                          Will otherwise autodetect OS.
  * @param boolean $retried  used internally to find out wether we are retrying
  *
  * @return object
  */
 public function &factory($force_os = false, $retried = false)
 {
     $drivers = array();
     $driversValid = array();
     $class_prefix = "System_Daemon_OS_";
     // Load all drivers
     $driver_dir = realpath(dirname(__FILE__) . "/OS");
     foreach (glob($driver_dir . "/*.php") as $driver_path) {
         // Set names
         $driver = basename($driver_path, ".php");
         $class = $class_prefix . $driver;
         // Only do this for real drivers
         if ($driver == "Exception" || !is_file($driver_path)) {
             continue;
         }
         // Let SPL include & load the driver or Report errors
         if (!class_exists($class, true)) {
             $this->errors[] = "Class " . $class . " does not exist";
             return false;
         }
         // Save in drivers array
         $drivers[$class] = new $class();
     }
     // Determine which one to use
     if ($force_os !== false) {
         // Let's use the Forced OS. This could be dangerous
         $use_name = $class_prefix . $force_os;
     } else {
         // What OSes are valid for this system?
         // e.g. Debian makes Linux valid as well
         foreach ($drivers as $class => $obj) {
             // Save in Installed container
             if (call_user_func(array($obj, "isInstalled"))) {
                 $driversValid[$class] = $obj;
             }
         }
         // What's the most specific OS?
         // e.g. Ubuntu > Debian > Linux
         $use_name = \System_Daemon_OS::_mostSpecific($driversValid);
     }
     // If forced driver wasn't found, retry to autodetect it
     if (!isset($drivers[$use_name])) {
         // Make sure we don't build a loop
         if (!$retried) {
             $obj = \System_Daemon_OS::factory(false, true);
             $obj->errors[] = "Unable to use driver: " . $force_os . " falling " . "back to autodetection.";
         } else {
             $obj = false;
         }
     } else {
         $obj = $drivers[$use_name];
     }
     return $obj;
 }
// Bare minimum setup
System_Daemon::setOption('appName', 'optest');
System_Daemon::setOption('authorEmail', '*****@*****.**');
System_Daemon::setOption('logLocation', '/var/log/sysdaemon.devtest.log');
System_Daemon::setOption('logFilePosition', true);
System_Daemon::warning('{appName} daemon encountered an empty appPidLocation');
System_Daemon::err('{appName} daemon encountered an empty appPidLocation');
die;
$options = array();
$options['appName'] = 'devtest';
$options['appExecutable'] = 'devtest.php';
$options['appDir'] = realpath(dirname(__FILE__));
$options['appDescription'] = 'Developer test daemon';
$options['authorName'] = 'kevman';
$options['authorEmail'] = '*****@*****.**';
if (($os = System_Daemon_OS::factory('BSD')) === false) {
    echo 'Cannot create OS\\n';
} else {
    print_r($os->errors);
    echo '\\n';
    echo $os->getAutoRunTemplatePath();
    echo '\\n';
    $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) {