/** * econtrol constructor * */ public function __construct() { // check if econtrol is running from cli if (Checks::cli() === false) { echo "Econtrol runs only in php-cli, exiting"; self::end(1); } if (defined('EXTENDER_TIMEZONE')) { date_default_timezone_set(EXTENDER_TIMEZONE); } $this->color = new Console_Color2(); $this->parser = new Console_CommandLine(array('description' => Version::getDescription(), 'version' => Version::getVersion())); // add verbose option $this->parser->addOption('verbose', array('short_name' => '-v', 'long_name' => '--verbose', 'description' => 'turn on verbose output', 'action' => 'StoreTrue')); // add debug option $this->parser->addOption('debug', array('short_name' => '-V', 'long_name' => '--debug', 'description' => 'turn on debug output', 'action' => 'StoreTrue')); try { $check_constants = Checks::constants(); if ($check_constants !== true) { throw new ShellException($check_constants); } if (array_key_exists('V', getopt("V"))) { $verbose = 'DEBUG'; echo $this->color->convert("\n%r(> Debug mode on <)%n\n"); } else { if (array_key_exists('v', getopt("v"))) { $verbose = 'NOTICE'; echo $this->color->convert("\n%y(> Verbose mode on <)%n\n"); } else { $verbose = false; } } $this->logger = EcontrolLogger::create($verbose); $this->tasks = TasksTable::load($this->logger); $this->controller = Controller::load($this->parser, $this->logger); } catch (Console_CommandLine_Exception $ce) { $this->parser->displayError($this->color->convert("\n\n%y" . $ce->getMessage() . "%n\n")); self::end(1); } catch (ShellException $se) { $this->parser->displayError($this->color->convert("\n\n%R" . $se->getMessage() . "%n\n")); self::end(1); } catch (Exception $e) { $this->parser->displayError($this->color->convert("\n\n%r" . $e->getMessage() . "%n\n")); self::end(1); } }
/** * Constructor method * * Prepare extender environment, do checks and fire extender.ready event */ public final function __construct() { // check if extender is running from cli if (Checks::cli() === false) { echo "Extender runs only in php-cli, exiting"; self::end(1); } // setup default timezone (in daemon mode, timezone warning may break extender) $default_timezone = ini_get('date.timezone'); if (empty($default_timezone)) { date_default_timezone_set(defined('EXTENDER_TIMEZONE') ? EXTENDER_TIMEZONE : 'Europe/Rome'); } $this->timestamp_absolute = microtime(true); $this->color = new Console_Color2(); // get command line options (vsdh) list($this->verbose_mode, $this->debug_mode, $this->summary_mode, $this->daemon_mode, $help_mode) = self::getCommandlineOptions(); if ($help_mode) { self::showHelp($this->color); self::end(0); } $this->logger = ExtenderLogger::create($this->verbose_mode, $this->debug_mode); // do checks $check_constants = Checks::constants(); if ($check_constants !== true) { $this->logger->critical($check_constants); self::end(1); } if (Checks::signals() === false and $this->daemon_mode) { $this->logger->critical("Extender cannot run in daemon mode without PHP Process Control Extensions"); self::end(1); } if (Checks::database() === false) { $this->logger->critical("Extender database not available, exiting"); self::end(1); } $this->tasks = TasksTable::load($this->logger); $this->events = Events::load($this->logger); // setup extender parameters $this->max_result_bytes_in_multithread = defined('EXTENDER_MAX_RESULT_BYTES') ? filter_var(EXTENDER_MAX_RESULT_BYTES, FILTER_VALIDATE_INT) : 2048; $this->max_childs_runtime = defined('EXTENDER_MAX_CHILDS_RUNTIME') ? filter_var(EXTENDER_MAX_CHILDS_RUNTIME, FILTER_VALIDATE_INT) : 600; $this->multithread_mode = defined('EXTENDER_MULTITHREAD_ENABLED') ? filter_var(EXTENDER_MULTITHREAD_ENABLED, FILTER_VALIDATE_BOOLEAN) : false; // if in daemon mode, remember parent pid, setup lock and register signal handlers if ($this->daemon_mode) { $this->parent_pid = posix_getpid(); Lock::register($this->parent_pid); $this->adjustNiceness(); if (Checks::signals()) { $this->registerSignals(); } } // init the runner $this->runner = new JobsRunner($this->logger, $this->getMultithreadMode(), $this->max_result_bytes_in_multithread, $this->max_childs_runtime); $this->logger->notice("Extender ready"); // store initial status and queue information Status::dump($this->timestamp_absolute, $this->parent_pid, $this->completed_processes, $this->failed_processes, $this->paused); Queue::dump(0, 0); // we are ready to go! }