mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
support log rotate signal SIGUSR1. 3.0.8
This commit is contained in:
parent
9e9cad1826
commit
2955b1fd2d
9 changed files with 61 additions and 23 deletions
|
@ -378,6 +378,7 @@ Remark:
|
||||||
|
|
||||||
### History
|
### History
|
||||||
|
|
||||||
|
* v3.0, 2016-12-08, support log rotate signal SIGUSR1. 3.0.8
|
||||||
* v3.0, 2016-12-07, fix typo and refine grammar. 3.0.7
|
* v3.0, 2016-12-07, fix typo and refine grammar. 3.0.7
|
||||||
* v3.0, 2015-10-23, fix [#467][bug #467], support write log to kafka. 3.0.6
|
* v3.0, 2015-10-23, fix [#467][bug #467], support write log to kafka. 3.0.6
|
||||||
* v3.0, 2015-10-20, fix [#502][bug #502], support snapshot with http-callback or transcoder. 3.0.5
|
* v3.0, 2015-10-20, fix [#502][bug #502], support snapshot with http-callback or transcoder. 3.0.5
|
||||||
|
|
|
@ -127,6 +127,19 @@ int SrsFastLog::initialize()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SrsFastLog::reopen()
|
||||||
|
{
|
||||||
|
if (fd > 0) {
|
||||||
|
::close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!log_to_file_tank) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
open_log_file();
|
||||||
|
}
|
||||||
|
|
||||||
void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...)
|
void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
if (_level > SrsLogLevel::Verbose) {
|
if (_level > SrsLogLevel::Verbose) {
|
||||||
|
|
|
@ -82,6 +82,7 @@ public:
|
||||||
virtual ~SrsFastLog();
|
virtual ~SrsFastLog();
|
||||||
public:
|
public:
|
||||||
virtual int initialize();
|
virtual int initialize();
|
||||||
|
virtual void reopen();
|
||||||
virtual void verbose(const char* tag, int context_id, const char* fmt, ...);
|
virtual void verbose(const char* tag, int context_id, const char* fmt, ...);
|
||||||
virtual void info(const char* tag, int context_id, const char* fmt, ...);
|
virtual void info(const char* tag, int context_id, const char* fmt, ...);
|
||||||
virtual void trace(const char* tag, int context_id, const char* fmt, ...);
|
virtual void trace(const char* tag, int context_id, const char* fmt, ...);
|
||||||
|
|
|
@ -408,10 +408,10 @@ int SrsSignalManager::initialize()
|
||||||
int SrsSignalManager::start()
|
int SrsSignalManager::start()
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Note that if multiple processes are used (see below),
|
* Note that if multiple processes are used (see below),
|
||||||
* the signal pipe should be initialized after the fork(2) call
|
* the signal pipe should be initialized after the fork(2) call
|
||||||
* so that each process has its own private pipe.
|
* so that each process has its own private pipe.
|
||||||
*/
|
*/
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
|
|
||||||
/* Install sig_catcher() as a signal handler */
|
/* Install sig_catcher() as a signal handler */
|
||||||
|
@ -433,15 +433,10 @@ int SrsSignalManager::start()
|
||||||
sa.sa_handler = SrsSignalManager::sig_catcher;
|
sa.sa_handler = SrsSignalManager::sig_catcher;
|
||||||
sigemptyset(&sa.sa_mask);
|
sigemptyset(&sa.sa_mask);
|
||||||
sa.sa_flags = 0;
|
sa.sa_flags = 0;
|
||||||
sigaction(SRS_SIGNAL_DISPOSE, &sa, NULL);
|
sigaction(SRS_SIGNAL_REOPEN_LOG, &sa, NULL);
|
||||||
|
|
||||||
sa.sa_handler = SrsSignalManager::sig_catcher;
|
srs_trace("signal installed, reload=%d, reopen=%d, grace_quit=%d",
|
||||||
sigemptyset(&sa.sa_mask);
|
SRS_SIGNAL_RELOAD, SRS_SIGNAL_REOPEN_LOG, SRS_SIGNAL_GRACEFULLY_QUIT);
|
||||||
sa.sa_flags = 0;
|
|
||||||
sigaction(SRS_SIGNAL_PERSISTENCE_CONFIG, &sa, NULL);
|
|
||||||
|
|
||||||
srs_trace("signal installed, reload=%d, dispose=%d, persistence=%d, grace_quit=%d",
|
|
||||||
SRS_SIGNAL_RELOAD, SRS_SIGNAL_DISPOSE, SRS_SIGNAL_PERSISTENCE_CONFIG, SRS_SIGNAL_GRACEFULLY_QUIT);
|
|
||||||
|
|
||||||
return pthread->start();
|
return pthread->start();
|
||||||
}
|
}
|
||||||
|
@ -906,19 +901,36 @@ int SrsServer::cycle()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SrsServer::on_signal(int signo)
|
void SrsServer::on_signal(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SRS_SIGNAL_RELOAD) {
|
if (signo == SRS_SIGNAL_RELOAD) {
|
||||||
signal_reload = true;
|
signal_reload = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SRS_AUTO_GPERF_MC
|
||||||
|
if (signo == SRS_SIGNAL_REOPEN_LOG) {
|
||||||
|
_srs_log->reopen();
|
||||||
|
srs_warn("reopen log file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SRS_AUTO_GPERF_MC
|
||||||
|
if (signo == SRS_SIGNAL_REOPEN_LOG) {
|
||||||
|
signal_gmc_stop = true;
|
||||||
|
srs_warn("for gmc, the SIGUSR1 used as SIGINT");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (signo == SRS_SIGNAL_PERSISTENCE_CONFIG) {
|
if (signo == SRS_SIGNAL_PERSISTENCE_CONFIG) {
|
||||||
signal_persistence_config = true;
|
signal_persistence_config = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signo == SIGINT || signo == SRS_SIGNAL_DISPOSE) {
|
if (signo == SIGINT) {
|
||||||
#ifdef SRS_AUTO_GPERF_MC
|
#ifdef SRS_AUTO_GPERF_MC
|
||||||
srs_trace("gmc is on, main cycle will terminate normally.");
|
srs_trace("gmc is on, main cycle will terminate normally.");
|
||||||
signal_gmc_stop = true;
|
signal_gmc_stop = true;
|
||||||
|
|
|
@ -325,10 +325,10 @@ public:
|
||||||
* whatever, we will got the signo like the orignal signal(int signo) handler.
|
* whatever, we will got the signo like the orignal signal(int signo) handler.
|
||||||
* @param signo the signal number from user, where:
|
* @param signo the signal number from user, where:
|
||||||
* SRS_SIGNAL_GRACEFULLY_QUIT, the SIGTERM, dispose then quit.
|
* SRS_SIGNAL_GRACEFULLY_QUIT, the SIGTERM, dispose then quit.
|
||||||
* SRS_SIGNAL_DISPOSE, the SIGUSR2, dispose for gmc.
|
* SRS_SIGNAL_REOPEN_LOG, the SIGUSR1, reopen the log file.
|
||||||
* SRS_SIGNAL_PERSISTENCE_CONFIG, the SIGUSR1, persistence config to file.
|
|
||||||
* SRS_SIGNAL_RELOAD, the SIGHUP, reload the config.
|
* SRS_SIGNAL_RELOAD, the SIGHUP, reload the config.
|
||||||
* @remark, for SIGINT and SRS_SIGNAL_DISPOSE:
|
* SRS_SIGNAL_PERSISTENCE_CONFIG, application level signal, persistence config to file.
|
||||||
|
* @remark, for SIGINT:
|
||||||
* no gmc, directly exit.
|
* no gmc, directly exit.
|
||||||
* for gmc, set the variable signal_gmc_stop, the cycle will return and cleanup for gmc.
|
* 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.
|
* @remark, maybe the HTTP RAW API will trigger the on_signal() also.
|
||||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// current release version
|
// current release version
|
||||||
#define VERSION_MAJOR 3
|
#define VERSION_MAJOR 3
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 7
|
#define VERSION_REVISION 8
|
||||||
|
|
||||||
// generated by configure, only macros.
|
// generated by configure, only macros.
|
||||||
#include <srs_auto_headers.hpp>
|
#include <srs_auto_headers.hpp>
|
||||||
|
|
|
@ -133,14 +133,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// signal defines.
|
// signal defines.
|
||||||
// reload the config file and apply new config.
|
// reload the config file and apply new config.
|
||||||
#define SRS_SIGNAL_RELOAD SIGHUP
|
#define SRS_SIGNAL_RELOAD SIGHUP
|
||||||
// terminate the srs with dispose to detect memory leak for gmc.
|
// reopen the log file.
|
||||||
#define SRS_SIGNAL_DISPOSE SIGUSR2
|
#define SRS_SIGNAL_REOPEN_LOG SIGUSR1
|
||||||
// persistence the config in memory to config file.
|
|
||||||
// @see https://github.com/ossrs/srs/issues/319#issuecomment-134993922
|
|
||||||
#define SRS_SIGNAL_PERSISTENCE_CONFIG SIGUSR1
|
|
||||||
// srs should gracefully quit, do dispose then exit.
|
// srs should gracefully quit, do dispose then exit.
|
||||||
#define SRS_SIGNAL_GRACEFULLY_QUIT SIGTERM
|
#define SRS_SIGNAL_GRACEFULLY_QUIT SIGTERM
|
||||||
|
|
||||||
|
// application level signals.
|
||||||
|
// persistence the config in memory to config file.
|
||||||
|
// @see https://github.com/ossrs/srs/issues/319#issuecomment-134993922
|
||||||
|
// @remark we actually don't handle the signal for it's not a valid os signal.
|
||||||
|
#define SRS_SIGNAL_PERSISTENCE_CONFIG 1000
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -38,6 +38,10 @@ int ISrsLog::initialize()
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ISrsLog::reopen()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void ISrsLog::verbose(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...)
|
void ISrsLog::verbose(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,10 @@ public:
|
||||||
* initialize log utilities.
|
* initialize log utilities.
|
||||||
*/
|
*/
|
||||||
virtual int initialize();
|
virtual int initialize();
|
||||||
|
/**
|
||||||
|
* reopen the log file for log rotate.
|
||||||
|
*/
|
||||||
|
virtual void reopen();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* log for verbose, very verbose information.
|
* log for verbose, very verbose information.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue