Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
2771bc15
Unverified
Commit
2771bc15
authored
Jun 28, 2023
by
pedoc
Committed by
GitHub
Jun 28, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加on_server_exited webhook事件,当程序正常退出时触发 (#2591 #2585)
parent
c530f281
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
26 行增加
和
2 行删除
+26
-2
conf/config.ini
+2
-0
server/WebHook.cpp
+19
-0
server/WebHook.h
+1
-0
server/main.cpp
+4
-2
没有找到文件。
conf/config.ini
查看文件 @
2771bc15
...
@@ -168,6 +168,8 @@ on_stream_none_reader=https://127.0.0.1/index/hook/on_stream_none_reader
...
@@ -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_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_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保活上报
#server保活上报
on_server_keepalive
=
https://127.0.0.1/index/hook/on_server_keepalive
on_server_keepalive
=
https://127.0.0.1/index/hook/on_server_keepalive
#发送rtp(startSendRtp)被动关闭时回调
#发送rtp(startSendRtp)被动关闭时回调
...
...
server/WebHook.cpp
查看文件 @
2771bc15
...
@@ -44,6 +44,7 @@ const string kOnShellLogin = HOOK_FIELD "on_shell_login";
...
@@ -44,6 +44,7 @@ const string kOnShellLogin = HOOK_FIELD "on_shell_login";
const
string
kOnStreamNoneReader
=
HOOK_FIELD
"on_stream_none_reader"
;
const
string
kOnStreamNoneReader
=
HOOK_FIELD
"on_stream_none_reader"
;
const
string
kOnHttpAccess
=
HOOK_FIELD
"on_http_access"
;
const
string
kOnHttpAccess
=
HOOK_FIELD
"on_http_access"
;
const
string
kOnServerStarted
=
HOOK_FIELD
"on_server_started"
;
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
kOnServerKeepalive
=
HOOK_FIELD
"on_server_keepalive"
;
const
string
kOnSendRtpStopped
=
HOOK_FIELD
"on_send_rtp_stopped"
;
const
string
kOnSendRtpStopped
=
HOOK_FIELD
"on_send_rtp_stopped"
;
const
string
kOnRtpServerTimeout
=
HOOK_FIELD
"on_rtp_server_timeout"
;
const
string
kOnRtpServerTimeout
=
HOOK_FIELD
"on_rtp_server_timeout"
;
...
@@ -69,6 +70,7 @@ static onceToken token([]() {
...
@@ -69,6 +70,7 @@ static onceToken token([]() {
mINI
::
Instance
()[
kOnStreamNoneReader
]
=
""
;
mINI
::
Instance
()[
kOnStreamNoneReader
]
=
""
;
mINI
::
Instance
()[
kOnHttpAccess
]
=
""
;
mINI
::
Instance
()[
kOnHttpAccess
]
=
""
;
mINI
::
Instance
()[
kOnServerStarted
]
=
""
;
mINI
::
Instance
()[
kOnServerStarted
]
=
""
;
mINI
::
Instance
()[
kOnServerExited
]
=
""
;
mINI
::
Instance
()[
kOnServerKeepalive
]
=
""
;
mINI
::
Instance
()[
kOnServerKeepalive
]
=
""
;
mINI
::
Instance
()[
kOnSendRtpStopped
]
=
""
;
mINI
::
Instance
()[
kOnSendRtpStopped
]
=
""
;
mINI
::
Instance
()[
kOnRtpServerTimeout
]
=
""
;
mINI
::
Instance
()[
kOnRtpServerTimeout
]
=
""
;
...
@@ -238,6 +240,18 @@ static void reportServerStarted() {
...
@@ -238,6 +240,18 @@ static void reportServerStarted() {
do_http_hook
(
hook_server_started
,
body
,
nullptr
);
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
Timer
::
Ptr
g_keepalive_timer
;
static
void
reportServerKeepalive
()
{
static
void
reportServerKeepalive
()
{
...
@@ -668,3 +682,7 @@ void unInstallWebHook() {
...
@@ -668,3 +682,7 @@ void unInstallWebHook() {
g_keepalive_timer
.
reset
();
g_keepalive_timer
.
reset
();
NoticeCenter
::
Instance
().
delListener
(
&
web_hook_tag
);
NoticeCenter
::
Instance
().
delListener
(
&
web_hook_tag
);
}
}
void
onProcessExited
()
{
reportServerExited
();
}
\ No newline at end of file
server/WebHook.h
查看文件 @
2771bc15
...
@@ -31,6 +31,7 @@ extern const std::string kTimeoutSec;
...
@@ -31,6 +31,7 @@ extern const std::string kTimeoutSec;
void
installWebHook
();
void
installWebHook
();
void
unInstallWebHook
();
void
unInstallWebHook
();
void
onProcessExited
();
/**
/**
* 触发http hook请求
* 触发http hook请求
* @param url 请求地址
* @param url 请求地址
...
...
server/main.cpp
查看文件 @
2771bc15
...
@@ -409,9 +409,9 @@ int start_main(int argc,char *argv[]) {
...
@@ -409,9 +409,9 @@ int start_main(int argc,char *argv[]) {
static
semaphore
sem
;
static
semaphore
sem
;
signal
(
SIGINT
,
[](
int
)
{
signal
(
SIGINT
,
[](
int
)
{
InfoL
<<
"SIGINT:exit"
;
InfoL
<<
"SIGINT:exit"
;
signal
(
SIGINT
,
SIG_IGN
);
// 设置退出信号
signal
(
SIGINT
,
SIG_IGN
);
// 设置退出信号
sem
.
post
();
sem
.
post
();
});
// 设置退出信号
});
// 设置退出信号
#if !defined(_WIN32)
#if !defined(_WIN32)
signal
(
SIGHUP
,
[](
int
)
{
mediakit
::
loadIniConfig
(
g_ini_file
.
data
());
});
signal
(
SIGHUP
,
[](
int
)
{
mediakit
::
loadIniConfig
(
g_ini_file
.
data
());
});
...
@@ -420,6 +420,8 @@ int start_main(int argc,char *argv[]) {
...
@@ -420,6 +420,8 @@ int start_main(int argc,char *argv[]) {
}
}
unInstallWebApi
();
unInstallWebApi
();
unInstallWebHook
();
unInstallWebHook
();
onProcessExited
();
//休眠1秒再退出,防止资源释放顺序错误
//休眠1秒再退出,防止资源释放顺序错误
InfoL
<<
"程序退出中,请等待..."
;
InfoL
<<
"程序退出中,请等待..."
;
sleep
(
1
);
sleep
(
1
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论