Skip to content

Commit

Permalink
update to 2.5.0-b4 (build 414)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazywhalecc committed Jul 8, 2021
1 parent 4810632 commit e57cc43
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion config/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/** 一些框架与Swoole运行时设置的调整 */
$config['runtime'] = [
'swoole_coroutine_hook_flags' => SWOOLE_HOOK_ALL & (~SWOOLE_HOOK_CURL),
'swoole_server_mode' => SWOOLE_BASE
'swoole_server_mode' => SWOOLE_PROCESS
];

/** 轻量字符串缓存,默认开启 */
Expand Down
2 changes: 1 addition & 1 deletion src/ZM/Command/Daemon/DaemonStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln("<comment>----- 以下是stdout内容 -----</comment>");
$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;
}
Expand Down
14 changes: 11 additions & 3 deletions src/ZM/Command/Daemon/DaemonStopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ protected function configure() {

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("<info>成功停止!</info>");
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("<error>停止失败,请检查进程pid #" . $this->daemon_file["pid"] . " 是否响应!</error>");
} else {
$output->writeln("<info>成功停止!</info>");
}
return 0;
}
}
4 changes: 2 additions & 2 deletions src/ZM/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/ZM/Event/SwooleEvent/OnManagerStop.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ZM\Annotation\Swoole\SwooleHandler;
use ZM\Console\Console;
use ZM\Event\SwooleEvent;
use ZM\Utils\DataProvider;

/**
* Class OnManagerStop
Expand All @@ -23,5 +24,8 @@ public function onCall() {
}
}
Console::verbose("进程 Manager 已停止!");
if (file_exists(DataProvider::getWorkingDir()."/.daemon_pid")) {
unlink(DataProvider::getWorkingDir()."/.daemon_pid");
}
}
}
14 changes: 8 additions & 6 deletions src/ZM/Event/SwooleEvent/OnStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +25,13 @@ public function onCall(Server $server) {
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);
}
}


Expand Down
3 changes: 0 additions & 3 deletions src/ZM/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ public function __construct($args = []) {
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"];
Expand Down
4 changes: 0 additions & 4 deletions src/ZM/Utils/ZMUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ public static function stop() {
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();
}

Expand Down

0 comments on commit e57cc43

Please sign in to comment.