示例#1
0
 public function __destruct()
 {
     if ($this->node == 0) {
         foreach ($this->pid as $child_pid) {
             if ($child_pid == getmypid()) {
                 continue;
             }
             Logger::notice(sprintf('TERM signal sent to child pid: %s', $child_pid));
             posix_kill($child_pid, SIGTERM);
         }
     }
     if (isset($this->projectName)) {
         Logger::notice(sprintf('%s : PROJECT TERMINATED', $this->projectName));
     } else {
         Logger::notice('TERMINATED');
     }
 }
示例#2
0
 /**
  * Daemonises the process
  */
 protected function fork_to_bg()
 {
     $daemon_pid = pcntl_fork();
     switch ($daemon_pid) {
         case -1:
             Logger::emergency('Unable to fork daemon process');
             exit(1);
             // fork failed
         // fork failed
         case 0:
             // this child is our daemon
             $this->process_pid = getmypid();
             break;
         default:
             // we are the parent - the one from the FG command line
             // return control to command line by exiting...
             \Cli\line('Daemon process running : pid=%y' . $daemon_pid . '%n');
             exit(0);
     }
     // promote the daemon process so it doesn't die because the parent has
     if (posix_setsid() === -1) {
         Logger::critical('Error creating daemon as session leader');
         exit(1);
     }
     fclose(STDIN);
     fclose(STDOUT);
     fclose(STDERR);
     $this->_stdIn = fopen('/dev/null', 'r');
     // set fd/0
     $this->_stdOut = fopen('/dev/null', 'w');
     // set fd/1
     $this->_stdErr = fopen('php://stdout', 'w');
     // a hack to duplicate fd/1 to 2
     // Silence any console output from the logger
     Logger::setSilentConsole(true);
     Logger::notice('Daemon process running : pid=' . getmypid());
 }
示例#3
0
 /**
  * Run our CLI Project
  *
  * @return void
  */
 protected function launch()
 {
     $this->loadBootstrap();
     $router = new CliRouter($this->request);
     $router->match();
     /**
      * Get the ControllerEntity
      */
     $this->controller = $router->getController();
     Logger::notice('Calling: ' . $this->controller->getClassName() . '::' . $this->controller->getMethodName());
     // pass the parameters
     $this->controller->setParameters($this->parameters);
     // Call the action
     $response = $this->controller->callControllerAction();
 }
示例#4
0
 /**
  * Checks everything is good with our project before we run it
  *
  * @throws \Synergy\Exception\SynergyException
  */
 protected function checkEnv()
 {
     if (!defined('SYNERGY_ROOT_DIR')) {
         $testroot = dirname(dirname($_SERVER['SCRIPT_FILENAME']));
         if ($this->isValidDirectory($testroot)) {
             define('SYNERGY_ROOT_DIR', dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
         } else {
             throw new CriticalLaunchException('Please define your project root directory as SYNERGY_ROOT_DIR');
         }
     } else {
         if (!is_dir(SYNERGY_ROOT_DIR)) {
             throw new CriticalLaunchException('SYNERGY_ROOT_DIR must point to a valid directory at the root of your project');
         }
     }
     if (!isset($this->app_dir) && !$this->searchAppDir()) {
         throw new CriticalLaunchException('Unable to init Synergy library without an app directory');
     }
     if (!isset($this->configFilename) && !$this->searchConfigFile()) {
         Logger::notice('No config file found - this may cause problems');
     }
     if (!isset($this->temp_dir) && $this->getOption('synergy:temp_dir')) {
         $this->setTempDir($this->getOption('synergy:temp_dir'));
     } else {
         if (!$this->searchTempDir()) {
             throw new CriticalLaunchException('Unable to init Synergy library without a temp (cache) directory');
         }
     }
     Logger::debug('Temp Dir: ' . $this->temp_dir);
 }