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>'); } }
public static function configCheck() { if (!defined('DAEMON_FILE') || !DAEMON_FILE || !file_exists(DAEMON_FILE)) { throw new \RuntimeException('Not defined DAEMON_FILE'); } if (!defined('DAEMON_CWD') || !DAEMON_CWD) { throw new \RuntimeException('Not defined DAEMON_CWD'); } if (DaemonUtils::checkPidFile() !== false) { throw new \Exception('Daemon already running'); } //writable-test @file_put_contents(self::getPidFilename(), 'test'); if (@file_get_contents(self::getPidFilename()) != 'test') { throw new \RuntimeException('Pid file is not writable [' . self::getPidFilename() . ']'); } @unlink(self::getPidFilename()); }