diff --git a/README.md b/README.md index 8439b0d2..c1df4eaa 100755 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ define('IS_WORKER_SERVICE', 0); define('IS_CLI_SCRIPT', 0); define('IS_CRON_SERVICE', 0); define('PHP_BIN_FILE','/usr/bin/php'); +define('WORKER_START_SCRIPT_FILE', $_SERVER['PWD'].'/'.$_SERVER['SCRIPT_FILENAME']); date_default_timezone_set('Asia/Shanghai'); diff --git a/src/Cmd/RestartCmd.php b/src/Cmd/RestartCmd.php index 60de155c..59162e96 100644 --- a/src/Cmd/RestartCmd.php +++ b/src/Cmd/RestartCmd.php @@ -24,7 +24,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $appName = $input->getArgument('app_name'); - $force = $input->getOption('force'); + $force = $input->getOption('force'); $lineValue = ""; if (empty($force)) { if (SystemEnv::isWorkerService()) { @@ -49,17 +49,17 @@ protected function execute(InputInterface $input, OutputInterface $output) } } else { if (SystemEnv::isWorkerService()) { - fmtPrintInfo("\n你已放弃【重启】workerService【" . WORKER_SERVICE_NAME . "】,应用继续running中"); + fmtPrintInfo(PHP_EOL."你已放弃【重启】workerService【" . WORKER_SERVICE_NAME . "】,应用继续running中"); exit(0); } else { - fmtPrintInfo("\n你已放弃【重启】应用【{$appName}】,应用继续running中"); + fmtPrintInfo(PHP_EOL."你已放弃【重启】应用【{$appName}】,应用继续running中"); exit(0); } } fmtPrintInfo("-----------正在重启进程中,请等待-----------"); - if (SystemEnv::isWorkerService() || SystemEnv::isCronService()) { + if (SystemEnv::isWorkerService()) { while (true) { if ($masterPid > 0 && \Swoole\Process::kill($masterPid, 0)) { sleep(1); @@ -67,34 +67,27 @@ protected function execute(InputInterface $input, OutputInterface $output) break; } } + }else { + sleep(1); } // send restart command to main worker process - $binFile = SystemEnv::PhpBinFile(); - $waitTime = 10; + $phpBinFile = SystemEnv::PhpBinFile(); + $waitTime = 10; if (SystemEnv::isWorkerService()) { - $selfFile = WORKER_START_SCRIPT_FILE; - if (SystemEnv::isCronService()) { - $selfFile = 'cron.php'; - }else if (SystemEnv::isDaemonService()) { - $selfFile = 'daemon.php'; - } // sleep max 30s $waitTime = 30; - }else { - $selfFile = 'cli.php'; } - + $selfFile = WORKER_START_SCRIPT_FILE; $scriptFile = "$selfFile start {$appName} --daemon=1"; - \Swoole\Coroutine::create(function () use ($binFile, $scriptFile) { - $runner = CommandRunner::getInstance('restart'); + \Swoole\Coroutine::create(function () use ($phpBinFile, $scriptFile) { + $runner = CommandRunner::getInstance('restart-'.time()); $runner->isNextHandle(false); $runner->procOpen(function () { - }, $binFile, $scriptFile); + }, $phpBinFile, $scriptFile); }); - $phpBinFile = SystemEnv::PhpBinFile(); $time = time(); while (true) { sleep(1); diff --git a/src/Cmd/SendCmd.php b/src/Cmd/SendCmd.php index d6317e17..b006e5a0 100644 --- a/src/Cmd/SendCmd.php +++ b/src/Cmd/SendCmd.php @@ -81,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output) \Swoole\Event::exit(); }); - // 发送数据toWorker + // send msg to Worker $pipeMsg = serialize($pipeMsgDto); // mainWorker Process $workerPid = file_get_contents(WORKER_PID_FILE);