update to build 407

change daemon command from system to Process::kill
add master_pid for motd information
add option --preview
delete server_event_handler_class and use process
go-cqhttp-down.sh script add arm64 support
add ./zhamao support
change build-runtime.sh to install-runtime.sh
add option --disable-safe-exit
adjust some Console output
set start script using /bin/sh for supporting auto searching php and framework
This commit is contained in:
2021-05-08 10:02:41 +08:00
parent a80ee902a9
commit 71585ed29d
19 changed files with 248 additions and 394 deletions

View File

@@ -10,6 +10,7 @@ use Swoole\Server;
use ZM\Annotation\Swoole\SwooleHandler;
use ZM\Console\Console;
use ZM\Event\SwooleEvent;
use ZM\Framework;
/**
* Class OnManagerStart
@@ -19,9 +20,11 @@ use ZM\Event\SwooleEvent;
class OnManagerStart implements SwooleEvent
{
public function onCall(Server $server) {
pcntl_signal(SIGINT, function () {
Console::verbose("Interrupted in manager!");
});
if (!Framework::$argv["disable-safe-exit"]) {
pcntl_signal(SIGINT, function () {
Console::verbose("Interrupted in manager!");
});
}
Console::verbose("进程 Manager 已启动");
}
}

View File

@@ -24,18 +24,20 @@ class OnStart implements SwooleEvent
{
public function onCall(Server $server) {
$r = null;
Process::signal(SIGINT, function () use ($r, $server) {
if (zm_atomic("_int_is_reload")->get() === 1) {
zm_atomic("_int_is_reload")->set(0);
$server->reload();
} else {
echo "\r";
Console::warning("Server interrupted(SIGINT) on Master.");
if ((Framework::$server->inotify ?? null) !== null)
/** @noinspection PhpUndefinedFieldInspection */ Event::del(Framework::$server->inotify);
Process::kill($server->master_pid, SIGTERM);
}
});
if (!Framework::$argv["disable-safe-exit"]) {
Process::signal(SIGINT, function () use ($r, $server) {
if (zm_atomic("_int_is_reload")->get() === 1) {
zm_atomic("_int_is_reload")->set(0);
$server->reload();
} else {
echo "\r";
Console::warning("Server interrupted(SIGINT) on Master.");
if ((Framework::$server->inotify ?? null) !== null)
/** @noinspection PhpUndefinedFieldInspection */ Event::del(Framework::$server->inotify);
Process::kill($server->master_pid, SIGTERM);
}
});
}
if (Framework::$argv["daemon"]) {
$daemon_data = json_encode([
"pid" => $server->master_pid,
@@ -45,13 +47,13 @@ class OnStart implements SwooleEvent
}
if (Framework::$argv["watch"]) {
if (extension_loaded('inotify')) {
Console::warning("Enabled File watcher, do not use in production.");
Console::info("Enabled File watcher, framework will reload automatically.");
/** @noinspection PhpUndefinedFieldInspection */
Framework::$server->inotify = $fd = inotify_init();
$this->addWatcher(DataProvider::getWorkingDir() . "/src", $fd);
Event::add($fd, function () use ($fd) {
$r = inotify_read($fd);
dump($r);
Console::verbose("File updated: ".$r[0]["name"]);
ZMUtil::reload();
});
} else {

View File

@@ -33,7 +33,6 @@ use ZM\Store\MySQL\SqlPoolStorage;
use ZM\Store\Redis\ZMRedisPool;
use ZM\Utils\DataProvider;
use ZM\Utils\ProcessManager;
use ZM\Utils\ZMUtil;
/**
* Class OnWorkerStart
@@ -43,15 +42,19 @@ use ZM\Utils\ZMUtil;
class OnWorkerStart implements SwooleEvent
{
public function onCall(Server $server, $worker_id) {
Process::signal(SIGINT, function () use ($worker_id, $server) {
if (!Framework::$argv["disable-safe-exit"]) {
Process::signal(SIGINT, function () use ($worker_id, $server) {
});
});
}
unset(Context::$context[Coroutine::getCid()]);
if ($server->taskworker === false) {
Process::signal(SIGUSR1, function () use ($worker_id) {
Timer::clearAll();
ProcessManager::resumeAllWorkerCoroutines();
});
if (!Framework::$argv["disable-safe-exit"]) {
Process::signal(SIGUSR1, function () use ($worker_id) {
Timer::clearAll();
ProcessManager::resumeAllWorkerCoroutines();
});
}
zm_atomic("_#worker_" . $worker_id)->set($server->worker_pid);
if (LightCacheInside::get("wait_api", "wait_api") !== null) {
LightCacheInside::unset("wait_api", "wait_api");
@@ -84,7 +87,7 @@ class OnWorkerStart implements SwooleEvent
}
Console::info("新建SQL连接池中");
ob_start();
phpinfo();
phpinfo(); //这个phpinfo是有用的不能删除
$str = ob_get_clean();
$str = explode("\n", $str);
foreach ($str as $k => $v) {
@@ -130,7 +133,7 @@ class OnWorkerStart implements SwooleEvent
$dispatcher->dispatchEvents($server, $worker_id);
if ($dispatcher->status === EventDispatcher::STATUS_NORMAL) Console::debug("@OnStart 执行完毕");
else Console::warning("@OnStart 执行异常!");
Console::success("Worker #" . $worker_id . " 已启动");
Console::success("Worker #" . $worker_id . " started");
} catch (Exception $e) {
Console::error("Worker加载出错停止服务");
Console::error($e->getMessage() . "\n" . $e->getTraceAsString());
@@ -147,7 +150,7 @@ class OnWorkerStart implements SwooleEvent
try {
Framework::$server = $server;
$this->loadAnnotations();
Console::success("TaskWorker #" . $server->worker_id . " 已启动");
Console::success("TaskWorker #" . $server->worker_id . " started");
} catch (Exception $e) {
Console::error("Worker加载出错停止服务");
Console::error($e->getMessage() . "\n" . $e->getTraceAsString());