Skip to content

Commit

Permalink
For #1579, define signals for fast/grace quit and upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 18, 2020
1 parent 5be69d2 commit f4c7b88
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 5 additions & 5 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions trunk/src/app/srs_app_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions trunk/src/kernel/srs_kernel_consts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f4c7b88

Please sign in to comment.