Commit f69f3b30 by xiongguangjie Committed by GitHub

docker 优雅关闭(docker stop graceful) (#2827)

parent f26e2532
...@@ -128,4 +128,4 @@ WORKDIR /opt/zlm ...@@ -128,4 +128,4 @@ WORKDIR /opt/zlm
VOLUME [ "/opt/zlm/conf/","/opt/zlm/log/","opt/zlm/ffmpeg/"] VOLUME [ "/opt/zlm/conf/","/opt/zlm/log/","opt/zlm/ffmpeg/"]
COPY --from=build /opt/build / COPY --from=build /opt/build /
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH TZ=Asia/Shanghai ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH TZ=Asia/Shanghai
CMD ./MediaServer -c ./conf/config.ini CMD ["./MediaServer", "-c" , "./conf/config.ini"]
\ No newline at end of file \ No newline at end of file
...@@ -41,4 +41,4 @@ RUN cmake -DCMAKE_BUILD_TYPE=Release .. && \ ...@@ -41,4 +41,4 @@ RUN cmake -DCMAKE_BUILD_TYPE=Release .. && \
make make
ENV PATH /opt/media/ZLMediaKit/release/linux/Release/:$PATH ENV PATH /opt/media/ZLMediaKit/release/linux/Release/:$PATH
CMD MediaServer CMD ["MediaServer"]
...@@ -60,4 +60,4 @@ RUN apt-get update && \ ...@@ -60,4 +60,4 @@ RUN apt-get update && \
WORKDIR /opt/media/bin/ WORKDIR /opt/media/bin/
COPY --from=build /opt/media/ZLMediaKit/release/linux/Release/MediaServer /opt/media/bin/MediaServer COPY --from=build /opt/media/ZLMediaKit/release/linux/Release/MediaServer /opt/media/bin/MediaServer
ENV PATH /opt/media/bin:$PATH ENV PATH /opt/media/bin:$PATH
CMD MediaServer CMD ["MediaServer"]
...@@ -42,4 +42,4 @@ RUN cmake -DCMAKE_BUILD_TYPE=Release .. && \ ...@@ -42,4 +42,4 @@ RUN cmake -DCMAKE_BUILD_TYPE=Release .. && \
make make
ENV PATH /opt/media/ZLMediaKit/release/linux/Release:$PATH ENV PATH /opt/media/ZLMediaKit/release/linux/Release:$PATH
CMD MediaServer CMD ["MediaServer"]
...@@ -60,4 +60,4 @@ RUN apt-get update && \ ...@@ -60,4 +60,4 @@ RUN apt-get update && \
WORKDIR /opt/media/bin/ WORKDIR /opt/media/bin/
COPY --from=build /opt/media/ZLMediaKit/release/linux/Release/MediaServer /opt/media/bin/MediaServer COPY --from=build /opt/media/ZLMediaKit/release/linux/Release/MediaServer /opt/media/bin/MediaServer
ENV PATH /opt/media/bin:$PATH ENV PATH /opt/media/bin:$PATH
CMD MediaServer CMD ["MediaServer"]
...@@ -83,4 +83,4 @@ COPY --from=build /opt/media/ZLMediaKit/release/linux/${MODEL}/MediaServer /opt/ ...@@ -83,4 +83,4 @@ COPY --from=build /opt/media/ZLMediaKit/release/linux/${MODEL}/MediaServer /opt/
COPY --from=build /opt/media/ZLMediaKit/release/linux/${MODEL}/config.ini /opt/media/conf/ COPY --from=build /opt/media/ZLMediaKit/release/linux/${MODEL}/config.ini /opt/media/conf/
COPY --from=build /opt/media/ZLMediaKit/www/ /opt/media/bin/www/ COPY --from=build /opt/media/ZLMediaKit/www/ /opt/media/bin/www/
ENV PATH /opt/media/bin:$PATH ENV PATH /opt/media/bin:$PATH
CMD ["sh","-c","./MediaServer -s default.pem -c ../conf/config.ini -l 0"] CMD ["./MediaServer","-s", "default.pem", "-c", "../conf/config.ini", "-l","0"]
...@@ -126,6 +126,12 @@ void System::startDaemon(bool &kill_parent_if_failed) { ...@@ -126,6 +126,12 @@ void System::startDaemon(bool &kill_parent_if_failed) {
exit(0); exit(0);
}); });
signal(SIGTERM,[](int) {
WarnL << "收到主动退出信号,关闭父进程与子进程";
kill(pid, SIGINT);
exit(0);
});
do { do {
int status = 0; int status = 0;
if (waitpid(pid, &status, 0) >= 0) { if (waitpid(pid, &status, 0) >= 0) {
......
...@@ -420,6 +420,12 @@ int start_main(int argc,char *argv[]) { ...@@ -420,6 +420,12 @@ int start_main(int argc,char *argv[]) {
sem.post(); sem.post();
}); // 设置退出信号 }); // 设置退出信号
signal(SIGTERM,[](int) {
WarnL << "SIGTERM:exit";
signal(SIGTERM, SIG_IGN);
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()); });
#endif #endif
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论