From 2771bc15a5c6f5f2bec265b2d0d0957eab52c229 Mon Sep 17 00:00:00 2001 From: pedoc Date: Wed, 28 Jun 2023 11:36:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0on=5Fserver=5Fexited=20webhoo?= =?UTF-8?q?k=E4=BA=8B=E4=BB=B6,=E5=BD=93=E7=A8=8B=E5=BA=8F=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E9=80=80=E5=87=BA=E6=97=B6=E8=A7=A6=E5=8F=91=20(#2591?= =?UTF-8?q?=20#2585)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/config.ini | 2 ++ server/WebHook.cpp | 18 ++++++++++++++++++ server/WebHook.h | 1 + server/main.cpp | 6 ++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index 5d1651ed..bd72cac6 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -168,6 +168,8 @@ on_stream_none_reader=https://127.0.0.1/index/hook/on_stream_none_reader on_stream_not_found=https://127.0.0.1/index/hook/on_stream_not_found #服务器启动报告,可以用于服务器的崩溃重启事件监听 on_server_started=https://127.0.0.1/index/hook/on_server_started +#服务器退出报告,当服务器正常退出时触发 +on_server_exited=https://127.0.0.1/index/hook/on_server_exited #server保活上报 on_server_keepalive=https://127.0.0.1/index/hook/on_server_keepalive #发送rtp(startSendRtp)被动关闭时回调 diff --git a/server/WebHook.cpp b/server/WebHook.cpp index 551d9c1d..424b8d1a 100755 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -44,6 +44,7 @@ const string kOnShellLogin = HOOK_FIELD "on_shell_login"; const string kOnStreamNoneReader = HOOK_FIELD "on_stream_none_reader"; const string kOnHttpAccess = HOOK_FIELD "on_http_access"; const string kOnServerStarted = HOOK_FIELD "on_server_started"; +const string kOnServerExited = HOOK_FIELD "on_server_exited"; const string kOnServerKeepalive = HOOK_FIELD "on_server_keepalive"; const string kOnSendRtpStopped = HOOK_FIELD "on_send_rtp_stopped"; const string kOnRtpServerTimeout = HOOK_FIELD "on_rtp_server_timeout"; @@ -69,6 +70,7 @@ static onceToken token([]() { mINI::Instance()[kOnStreamNoneReader] = ""; mINI::Instance()[kOnHttpAccess] = ""; mINI::Instance()[kOnServerStarted] = ""; + mINI::Instance()[kOnServerExited] = ""; mINI::Instance()[kOnServerKeepalive] = ""; mINI::Instance()[kOnSendRtpStopped] = ""; mINI::Instance()[kOnRtpServerTimeout] = ""; @@ -238,6 +240,18 @@ static void reportServerStarted() { do_http_hook(hook_server_started, body, nullptr); } +static void reportServerExited() { + GET_CONFIG(bool, hook_enable, Hook::kEnable); + GET_CONFIG(string, hook_server_exited, Hook::kOnServerExited); + if (!hook_enable || hook_server_exited.empty()) { + return; + } + + const ArgsType body; + // 执行hook + do_http_hook(hook_server_exited, body, nullptr); +} + // 服务器定时保活定时器 static Timer::Ptr g_keepalive_timer; static void reportServerKeepalive() { @@ -668,3 +682,7 @@ void unInstallWebHook() { g_keepalive_timer.reset(); NoticeCenter::Instance().delListener(&web_hook_tag); } + +void onProcessExited() { + reportServerExited(); +} \ No newline at end of file diff --git a/server/WebHook.h b/server/WebHook.h index ea99f736..c75d05c3 100755 --- a/server/WebHook.h +++ b/server/WebHook.h @@ -31,6 +31,7 @@ extern const std::string kTimeoutSec; void installWebHook(); void unInstallWebHook(); +void onProcessExited(); /** * 触发http hook请求 * @param url 请求地址 diff --git a/server/main.cpp b/server/main.cpp index 33696405..c43a9977 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -409,9 +409,9 @@ int start_main(int argc,char *argv[]) { static semaphore sem; signal(SIGINT, [](int) { InfoL << "SIGINT:exit"; - signal(SIGINT, SIG_IGN);// 设置退出信号 + signal(SIGINT, SIG_IGN); // 设置退出信号 sem.post(); - });// 设置退出信号 + }); // 设置退出信号 #if !defined(_WIN32) signal(SIGHUP, [](int) { mediakit::loadIniConfig(g_ini_file.data()); }); @@ -420,6 +420,8 @@ int start_main(int argc,char *argv[]) { } unInstallWebApi(); unInstallWebHook(); + onProcessExited(); + //休眠1秒再退出,防止资源释放顺序错误 InfoL << "程序退出中,请等待..."; sleep(1);