From e57cc43500a32df944d47d8109f0796e63392737 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 9 Jul 2021 02:15:04 +0800 Subject: [PATCH] update to 2.5.0-b4 (build 414) --- config/global.php | 2 +- src/ZM/Command/Daemon/DaemonStatusCommand.php | 2 +- src/ZM/Command/Daemon/DaemonStopCommand.php | 14 +++++++++++--- src/ZM/ConsoleApplication.php | 4 ++-- src/ZM/Event/SwooleEvent/OnManagerStop.php | 4 ++++ src/ZM/Event/SwooleEvent/OnStart.php | 14 ++++++++------ src/ZM/Framework.php | 3 --- src/ZM/Utils/ZMUtil.php | 4 ---- 8 files changed, 27 insertions(+), 20 deletions(-) diff --git a/config/global.php b/config/global.php index 496c727b..146c630f 100644 --- a/config/global.php +++ b/config/global.php @@ -37,7 +37,7 @@ $config['swoole'] = [ /** 一些框架与Swoole运行时设置的调整 */ $config['runtime'] = [ 'swoole_coroutine_hook_flags' => SWOOLE_HOOK_ALL & (~SWOOLE_HOOK_CURL), - 'swoole_server_mode' => SWOOLE_BASE + 'swoole_server_mode' => SWOOLE_PROCESS ]; /** 轻量字符串缓存,默认开启 */ diff --git a/src/ZM/Command/Daemon/DaemonStatusCommand.php b/src/ZM/Command/Daemon/DaemonStatusCommand.php index ebe3ba30..68d77239 100644 --- a/src/ZM/Command/Daemon/DaemonStatusCommand.php +++ b/src/ZM/Command/Daemon/DaemonStatusCommand.php @@ -20,7 +20,7 @@ class DaemonStatusCommand extends DaemonCommand $output->writeln("----- 以下是stdout内容 -----"); $stdout = file_get_contents($this->daemon_file["stdout"]); $stdout = explode("\n", $stdout); - for ($i = 10; $i > 0; --$i) { + for ($i = 15; $i > 0; --$i) { if (isset($stdout[count($stdout) - $i])) echo $stdout[count($stdout) - $i] . PHP_EOL; } diff --git a/src/ZM/Command/Daemon/DaemonStopCommand.php b/src/ZM/Command/Daemon/DaemonStopCommand.php index fb090396..1cac85b3 100644 --- a/src/ZM/Command/Daemon/DaemonStopCommand.php +++ b/src/ZM/Command/Daemon/DaemonStopCommand.php @@ -18,9 +18,17 @@ class DaemonStopCommand extends DaemonCommand protected function execute(InputInterface $input, OutputInterface $output): int { parent::execute($input, $output); - Process::kill(intval($this->daemon_file["pid"]), SIGINT); - unlink(DataProvider::getWorkingDir() . "/.daemon_pid"); - $output->writeln("成功停止!"); + Process::kill(intval($this->daemon_file["pid"]), SIGTERM); + $i = 10; + while (file_exists(DataProvider::getWorkingDir() . "/.daemon_pid") && $i > 0) { + sleep(1); + --$i; + } + if ($i === 0) { + $output->writeln("停止失败,请检查进程pid #" . $this->daemon_file["pid"] . " 是否响应!"); + } else { + $output->writeln("成功停止!"); + } return 0; } } diff --git a/src/ZM/ConsoleApplication.php b/src/ZM/ConsoleApplication.php index 93c89406..9e689a97 100644 --- a/src/ZM/ConsoleApplication.php +++ b/src/ZM/ConsoleApplication.php @@ -28,8 +28,8 @@ class ConsoleApplication extends Application { private static $obj = null; - const VERSION_ID = 413; - const VERSION = "2.5.0-b3"; + const VERSION_ID = 414; + const VERSION = "2.5.0-b4"; /** * @throws InitException diff --git a/src/ZM/Event/SwooleEvent/OnManagerStop.php b/src/ZM/Event/SwooleEvent/OnManagerStop.php index 47b3b79d..e79b3bdc 100644 --- a/src/ZM/Event/SwooleEvent/OnManagerStop.php +++ b/src/ZM/Event/SwooleEvent/OnManagerStop.php @@ -8,6 +8,7 @@ use Swoole\Process; use ZM\Annotation\Swoole\SwooleHandler; use ZM\Console\Console; use ZM\Event\SwooleEvent; +use ZM\Utils\DataProvider; /** * Class OnManagerStop @@ -23,5 +24,8 @@ class OnManagerStop implements SwooleEvent } } Console::verbose("进程 Manager 已停止!"); + if (file_exists(DataProvider::getWorkingDir()."/.daemon_pid")) { + unlink(DataProvider::getWorkingDir()."/.daemon_pid"); + } } } \ No newline at end of file diff --git a/src/ZM/Event/SwooleEvent/OnStart.php b/src/ZM/Event/SwooleEvent/OnStart.php index f713a659..84865ba9 100644 --- a/src/ZM/Event/SwooleEvent/OnStart.php +++ b/src/ZM/Event/SwooleEvent/OnStart.php @@ -4,19 +4,14 @@ namespace ZM\Event\SwooleEvent; -use Error; -use Exception; -use Swoole\Event; use Swoole\Server; use ZM\Annotation\Swoole\SwooleHandler; +use ZM\Config\ZMConfig; use ZM\Console\Console; use ZM\Event\SwooleEvent; use ZM\Framework; -use ZM\Store\ZMBuf; use ZM\Utils\DataProvider; use ZM\Utils\SignalListener; -use ZM\Utils\Terminal; -use ZM\Utils\ZMUtil; /** * Class OnStart @@ -30,6 +25,13 @@ class OnStart implements SwooleEvent if (!Framework::$argv["disable-safe-exit"]) { SignalListener::signalMaster($server); } + if (Framework::$argv["daemon"]) { + $daemon_data = json_encode([ + "pid" => $server->master_pid, + "stdout" => ZMConfig::get("global")["swoole"]["log_file"] + ], 128 | 256); + file_put_contents(DataProvider::getWorkingDir() . "/.daemon_pid", $daemon_data); + } } diff --git a/src/ZM/Framework.php b/src/ZM/Framework.php index f6a5c1f6..822a151f 100644 --- a/src/ZM/Framework.php +++ b/src/ZM/Framework.php @@ -129,9 +129,6 @@ class Framework if (isset($this->server_set["task_worker_num"])) { $out["task_worker"] = $this->server_set["task_worker_num"]; } - if (!isset($this->server_set["pid_file"])) { - $this->server_set["pid_file"] = ZMConfig::get("crash_dir") . ".zm.pid"; - } if (ZMConfig::get("global", "sql_config")["sql_host"] !== "") { $conf = ZMConfig::get("global", "sql_config"); $out["mysql_pool"] = $conf["sql_database"] . "@" . $conf["sql_host"] . ":" . $conf["sql_port"]; diff --git a/src/ZM/Utils/ZMUtil.php b/src/ZM/Utils/ZMUtil.php index c7cf97e0..471dcdc1 100644 --- a/src/ZM/Utils/ZMUtil.php +++ b/src/ZM/Utils/ZMUtil.php @@ -22,10 +22,6 @@ class ZMUtil Console::warning(Console::setColor('Stopping server...', 'red')); if (Console::getLevel() >= 4) Console::trace(); ZMAtomic::get('stop_signal')->set(1); - for ($i = 0; $i < ZM_WORKER_NUM; ++$i) { - if (Process::kill(zm_atomic('_#worker_' . $i)->get(), 0)) - Process::kill(zm_atomic('_#worker_' . $i)->get(), SIGUSR1); - } server()->shutdown(); }