For #1579, define signals for fast/grace quit and upgrade

pull/1620/head^2
winlin 5 years ago
parent 5be69d290f
commit f4c7b882c5

@ -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;
}

@ -260,12 +260,13 @@ public:
// 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);

@ -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.

Loading…
Cancel
Save