From f4c7b882c59592675a040fa07aba628cef9d6711 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Feb 2020 09:53:40 +0800 Subject: [PATCH] For #1579, define signals for fast/grace quit and upgrade --- trunk/src/app/srs_app_server.cpp | 10 +++++----- trunk/src/app/srs_app_server.hpp | 5 +++-- trunk/src/kernel/srs_kernel_consts.hpp | 11 +++++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 8768ff6421..71af22927f 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -395,7 +395,7 @@ srs_error_t SrsSignalManager::start() sa.sa_handler = SrsSignalManager::sig_catcher; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; - sigaction(SRS_SIGNAL_GRACEFULLY_QUIT, &sa, NULL); + sigaction(SRS_SIGNAL_FAST_QUIT, &sa, NULL); sa.sa_handler = SrsSignalManager::sig_catcher; sigemptyset(&sa.sa_mask); @@ -407,8 +407,8 @@ srs_error_t SrsSignalManager::start() sa.sa_flags = 0; sigaction(SRS_SIGNAL_REOPEN_LOG, &sa, NULL); - srs_trace("signal installed, reload=%d, reopen=%d, grace_quit=%d", - SRS_SIGNAL_RELOAD, SRS_SIGNAL_REOPEN_LOG, SRS_SIGNAL_GRACEFULLY_QUIT); + srs_trace("signal installed, reload=%d, reopen=%d, fast_quit=%d", + SRS_SIGNAL_RELOAD, SRS_SIGNAL_REOPEN_LOG, SRS_SIGNAL_FAST_QUIT); if ((err = trd->start()) != srs_success) { return srs_error_wrap(err, "signal manager"); @@ -863,8 +863,8 @@ void SrsServer::on_signal(int signo) #endif } - if ((signo == SIGINT || signo == SRS_SIGNAL_GRACEFULLY_QUIT) && !signal_gracefully_quit) { - srs_trace("sig=%d, user terminate program, gracefully quit", signo); + if ((signo == SIGINT || signo == SRS_SIGNAL_FAST_QUIT) && !signal_gracefully_quit) { + srs_trace("sig=%d, user terminate program, fast quit", signo); signal_gracefully_quit = true; return; } diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index fd8cbe3ad7..5ab4f011f8 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -260,12 +260,13 @@ class SrsServer : virtual public ISrsReloadHandler, virtual public ISrsSourceHan // The signal manager convert signal to io message, // whatever, we will got the signo like the orignal signal(int signo) handler. // @param signo the signal number from user, where: - // SRS_SIGNAL_GRACEFULLY_QUIT, the SIGTERM, dispose then quit. + // SRS_SIGNAL_FAST_QUIT, the SIGTERM, do essential dispose then quit. + // SRS_SIGNAL_GRACEFULLY_QUIT, the SIGQUIT, do careful dispose then quit. // SRS_SIGNAL_REOPEN_LOG, the SIGUSR1, reopen the log file. // SRS_SIGNAL_RELOAD, the SIGHUP, reload the config. // SRS_SIGNAL_PERSISTENCE_CONFIG, application level signal, persistence config to file. // @remark, for SIGINT: - // no gmc, directly exit. + // no gmc, fast quit, do essential dispose then quit. // for gmc, set the variable signal_gmc_stop, the cycle will return and cleanup for gmc. // @remark, maybe the HTTP RAW API will trigger the on_signal() also. virtual void on_signal(int signo); diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index b470c644ef..aa2860f3ae 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -124,8 +124,15 @@ #define SRS_SIGNAL_RELOAD SIGHUP // Reopen the log file. #define SRS_SIGNAL_REOPEN_LOG SIGUSR1 -// The signal for srs to gracefully quit, do dispose then exit. -#define SRS_SIGNAL_GRACEFULLY_QUIT SIGTERM +// For gracefully upgrade, start new SRS and gracefully quit old one. +// @see https://github.com/ossrs/srs/issues/1579 +// TODO: Not implemented. +#define SRS_SIGNAL_UPGRADE SIGUSR2 +// The signal for srs to fast quit, do essential dispose then exit. +#define SRS_SIGNAL_FAST_QUIT SIGTERM +// The signal for srs to gracefully quit, do carefully dispose then exit. +// TODO: FIXME: Not implemented. +#define SRS_SIGNAL_GRACEFULLY_QUIT SIGQUIT // The application level signals. // Persistence the config in memory to config file.