Beispiel #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $output->writeln("<info>Daemon stopped...</info>");
         $devNull = "> /dev/null 2>&1";
         list($iPid, $idKey) = DaemonUtils::checkPidFile();
         if ($iPid == 0) {
             throw new \Exception('Daemon not running');
         }
         shell_exec('kill -15 ' . $iPid . " {$devNull}");
         sleep(5);
         $aProcess = explode(PHP_EOL, shell_exec("ps -ef | grep " . escapeshellarg(DAEMON_FILE . " internal:master --id={$idKey}") . " | grep -v grep | awk '{print \$2}'"));
         foreach ($aProcess as $iProcessId) {
             if ($iProcessId = (int) $iProcessId) {
                 shell_exec('kill -9 ' . $iProcessId . " {$devNull}");
             }
         }
         sleep(5);
         shell_exec('kill -9 ' . $iPid . " {$devNull}");
         @unlink(DaemonUtils::getPidFilename());
         $output->writeln("<info>Daemon shutdown complete</info>");
     } catch (\Exception $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
     }
 }
Beispiel #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $id = $input->getOption('id');
         DaemonUtils::configCheck();
         $daemons = DaemonUtils::getDaemonsFromConfig();
         file_put_contents(DaemonUtils::getPidFilename(), getmypid() . ',' . $id);
         $loop = \React\EventLoop\Factory::create();
         $master = new MasterController($loop, new ChildController());
         foreach ($daemons as $daemon) {
             if (!$daemon instanceof DaemonizerInterface) {
                 throw new \Exception('Invalid [cli-daemonizer.php] file: file contain not-implementer ' . 'DaemonizerInterface class');
             }
             $master->attach($daemon);
         }
         $master->start();
         $loop->run();
     } catch (\Exception $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
     }
 }