正在显示
9 个修改的文件
包含
61 行增加
和
23 行删除
| @@ -378,6 +378,7 @@ Remark: | @@ -378,6 +378,7 @@ Remark: | ||
| 378 | 378 | ||
| 379 | ### History | 379 | ### History |
| 380 | 380 | ||
| 381 | +* v3.0, 2016-12-08, support log rotate signal SIGUSR1. 3.0.8 | ||
| 381 | * v3.0, 2016-12-07, fix typo and refine grammar. 3.0.7 | 382 | * v3.0, 2016-12-07, fix typo and refine grammar. 3.0.7 |
| 382 | * v3.0, 2015-10-23, fix [#467][bug #467], support write log to kafka. 3.0.6 | 383 | * v3.0, 2015-10-23, fix [#467][bug #467], support write log to kafka. 3.0.6 |
| 383 | * v3.0, 2015-10-20, fix [#502][bug #502], support snapshot with http-callback or transcoder. 3.0.5 | 384 | * 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() | @@ -127,6 +127,19 @@ int SrsFastLog::initialize() | ||
| 127 | return ret; | 127 | return ret; |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | +void SrsFastLog::reopen() | ||
| 131 | +{ | ||
| 132 | + if (fd > 0) { | ||
| 133 | + ::close(fd); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + if (!log_to_file_tank) { | ||
| 137 | + return; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + open_log_file(); | ||
| 141 | +} | ||
| 142 | + | ||
| 130 | void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...) | 143 | void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...) |
| 131 | { | 144 | { |
| 132 | if (_level > SrsLogLevel::Verbose) { | 145 | if (_level > SrsLogLevel::Verbose) { |
| @@ -82,6 +82,7 @@ public: | @@ -82,6 +82,7 @@ public: | ||
| 82 | virtual ~SrsFastLog(); | 82 | virtual ~SrsFastLog(); |
| 83 | public: | 83 | public: |
| 84 | virtual int initialize(); | 84 | virtual int initialize(); |
| 85 | + virtual void reopen(); | ||
| 85 | virtual void verbose(const char* tag, int context_id, const char* fmt, ...); | 86 | virtual void verbose(const char* tag, int context_id, const char* fmt, ...); |
| 86 | virtual void info(const char* tag, int context_id, const char* fmt, ...); | 87 | virtual void info(const char* tag, int context_id, const char* fmt, ...); |
| 87 | virtual void trace(const char* tag, int context_id, const char* fmt, ...); | 88 | virtual void trace(const char* tag, int context_id, const char* fmt, ...); |
| @@ -408,10 +408,10 @@ int SrsSignalManager::initialize() | @@ -408,10 +408,10 @@ int SrsSignalManager::initialize() | ||
| 408 | int SrsSignalManager::start() | 408 | int SrsSignalManager::start() |
| 409 | { | 409 | { |
| 410 | /** | 410 | /** |
| 411 | - * Note that if multiple processes are used (see below), | ||
| 412 | - * the signal pipe should be initialized after the fork(2) call | ||
| 413 | - * so that each process has its own private pipe. | ||
| 414 | - */ | 411 | + * Note that if multiple processes are used (see below), |
| 412 | + * the signal pipe should be initialized after the fork(2) call | ||
| 413 | + * so that each process has its own private pipe. | ||
| 414 | + */ | ||
| 415 | struct sigaction sa; | 415 | struct sigaction sa; |
| 416 | 416 | ||
| 417 | /* Install sig_catcher() as a signal handler */ | 417 | /* Install sig_catcher() as a signal handler */ |
| @@ -433,15 +433,10 @@ int SrsSignalManager::start() | @@ -433,15 +433,10 @@ int SrsSignalManager::start() | ||
| 433 | sa.sa_handler = SrsSignalManager::sig_catcher; | 433 | sa.sa_handler = SrsSignalManager::sig_catcher; |
| 434 | sigemptyset(&sa.sa_mask); | 434 | sigemptyset(&sa.sa_mask); |
| 435 | sa.sa_flags = 0; | 435 | sa.sa_flags = 0; |
| 436 | - sigaction(SRS_SIGNAL_DISPOSE, &sa, NULL); | 436 | + sigaction(SRS_SIGNAL_REOPEN_LOG, &sa, NULL); |
| 437 | 437 | ||
| 438 | - sa.sa_handler = SrsSignalManager::sig_catcher; | ||
| 439 | - sigemptyset(&sa.sa_mask); | ||
| 440 | - sa.sa_flags = 0; | ||
| 441 | - sigaction(SRS_SIGNAL_PERSISTENCE_CONFIG, &sa, NULL); | ||
| 442 | - | ||
| 443 | - srs_trace("signal installed, reload=%d, dispose=%d, persistence=%d, grace_quit=%d", | ||
| 444 | - SRS_SIGNAL_RELOAD, SRS_SIGNAL_DISPOSE, SRS_SIGNAL_PERSISTENCE_CONFIG, SRS_SIGNAL_GRACEFULLY_QUIT); | 438 | + srs_trace("signal installed, reload=%d, reopen=%d, grace_quit=%d", |
| 439 | + SRS_SIGNAL_RELOAD, SRS_SIGNAL_REOPEN_LOG, SRS_SIGNAL_GRACEFULLY_QUIT); | ||
| 445 | 440 | ||
| 446 | return pthread->start(); | 441 | return pthread->start(); |
| 447 | } | 442 | } |
| @@ -906,19 +901,36 @@ int SrsServer::cycle() | @@ -906,19 +901,36 @@ int SrsServer::cycle() | ||
| 906 | return ret; | 901 | return ret; |
| 907 | } | 902 | } |
| 908 | 903 | ||
| 904 | + | ||
| 909 | void SrsServer::on_signal(int signo) | 905 | void SrsServer::on_signal(int signo) |
| 910 | -{ | 906 | +{ |
| 911 | if (signo == SRS_SIGNAL_RELOAD) { | 907 | if (signo == SRS_SIGNAL_RELOAD) { |
| 912 | signal_reload = true; | 908 | signal_reload = true; |
| 913 | return; | 909 | return; |
| 914 | } | 910 | } |
| 915 | 911 | ||
| 912 | +#ifndef SRS_AUTO_GPERF_MC | ||
| 913 | + if (signo == SRS_SIGNAL_REOPEN_LOG) { | ||
| 914 | + _srs_log->reopen(); | ||
| 915 | + srs_warn("reopen log file"); | ||
| 916 | + return; | ||
| 917 | + } | ||
| 918 | +#endif | ||
| 919 | + | ||
| 920 | +#ifdef SRS_AUTO_GPERF_MC | ||
| 921 | + if (signo == SRS_SIGNAL_REOPEN_LOG) { | ||
| 922 | + signal_gmc_stop = true; | ||
| 923 | + srs_warn("for gmc, the SIGUSR1 used as SIGINT"); | ||
| 924 | + return; | ||
| 925 | + } | ||
| 926 | +#endif | ||
| 927 | + | ||
| 916 | if (signo == SRS_SIGNAL_PERSISTENCE_CONFIG) { | 928 | if (signo == SRS_SIGNAL_PERSISTENCE_CONFIG) { |
| 917 | signal_persistence_config = true; | 929 | signal_persistence_config = true; |
| 918 | return; | 930 | return; |
| 919 | } | 931 | } |
| 920 | 932 | ||
| 921 | - if (signo == SIGINT || signo == SRS_SIGNAL_DISPOSE) { | 933 | + if (signo == SIGINT) { |
| 922 | #ifdef SRS_AUTO_GPERF_MC | 934 | #ifdef SRS_AUTO_GPERF_MC |
| 923 | srs_trace("gmc is on, main cycle will terminate normally."); | 935 | srs_trace("gmc is on, main cycle will terminate normally."); |
| 924 | signal_gmc_stop = true; | 936 | signal_gmc_stop = true; |
| @@ -325,10 +325,10 @@ public: | @@ -325,10 +325,10 @@ public: | ||
| 325 | * whatever, we will got the signo like the orignal signal(int signo) handler. | 325 | * whatever, we will got the signo like the orignal signal(int signo) handler. |
| 326 | * @param signo the signal number from user, where: | 326 | * @param signo the signal number from user, where: |
| 327 | * SRS_SIGNAL_GRACEFULLY_QUIT, the SIGTERM, dispose then quit. | 327 | * SRS_SIGNAL_GRACEFULLY_QUIT, the SIGTERM, dispose then quit. |
| 328 | - * SRS_SIGNAL_DISPOSE, the SIGUSR2, dispose for gmc. | ||
| 329 | - * SRS_SIGNAL_PERSISTENCE_CONFIG, the SIGUSR1, persistence config to file. | 328 | + * SRS_SIGNAL_REOPEN_LOG, the SIGUSR1, reopen the log file. |
| 330 | * SRS_SIGNAL_RELOAD, the SIGHUP, reload the config. | 329 | * SRS_SIGNAL_RELOAD, the SIGHUP, reload the config. |
| 331 | - * @remark, for SIGINT and SRS_SIGNAL_DISPOSE: | 330 | + * SRS_SIGNAL_PERSISTENCE_CONFIG, application level signal, persistence config to file. |
| 331 | + * @remark, for SIGINT: | ||
| 332 | * no gmc, directly exit. | 332 | * no gmc, directly exit. |
| 333 | * for gmc, set the variable signal_gmc_stop, the cycle will return and cleanup for gmc. | 333 | * for gmc, set the variable signal_gmc_stop, the cycle will return and cleanup for gmc. |
| 334 | * @remark, maybe the HTTP RAW API will trigger the on_signal() also. | 334 | * @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. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR 3 | 32 | #define VERSION_MAJOR 3 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 7 | 34 | +#define VERSION_REVISION 8 |
| 35 | 35 | ||
| 36 | // generated by configure, only macros. | 36 | // generated by configure, only macros. |
| 37 | #include <srs_auto_headers.hpp> | 37 | #include <srs_auto_headers.hpp> |
| @@ -133,14 +133,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -133,14 +133,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 133 | // signal defines. | 133 | // signal defines. |
| 134 | // reload the config file and apply new config. | 134 | // reload the config file and apply new config. |
| 135 | #define SRS_SIGNAL_RELOAD SIGHUP | 135 | #define SRS_SIGNAL_RELOAD SIGHUP |
| 136 | -// terminate the srs with dispose to detect memory leak for gmc. | ||
| 137 | -#define SRS_SIGNAL_DISPOSE SIGUSR2 | ||
| 138 | -// persistence the config in memory to config file. | ||
| 139 | -// @see https://github.com/ossrs/srs/issues/319#issuecomment-134993922 | ||
| 140 | -#define SRS_SIGNAL_PERSISTENCE_CONFIG SIGUSR1 | 136 | +// reopen the log file. |
| 137 | +#define SRS_SIGNAL_REOPEN_LOG SIGUSR1 | ||
| 141 | // srs should gracefully quit, do dispose then exit. | 138 | // srs should gracefully quit, do dispose then exit. |
| 142 | #define SRS_SIGNAL_GRACEFULLY_QUIT SIGTERM | 139 | #define SRS_SIGNAL_GRACEFULLY_QUIT SIGTERM |
| 143 | 140 | ||
| 141 | +// application level signals. | ||
| 142 | +// persistence the config in memory to config file. | ||
| 143 | +// @see https://github.com/ossrs/srs/issues/319#issuecomment-134993922 | ||
| 144 | +// @remark we actually don't handle the signal for it's not a valid os signal. | ||
| 145 | +#define SRS_SIGNAL_PERSISTENCE_CONFIG 1000 | ||
| 146 | + | ||
| 144 | /////////////////////////////////////////////////////////// | 147 | /////////////////////////////////////////////////////////// |
| 145 | /////////////////////////////////////////////////////////// | 148 | /////////////////////////////////////////////////////////// |
| 146 | /////////////////////////////////////////////////////////// | 149 | /////////////////////////////////////////////////////////// |
| @@ -38,6 +38,10 @@ int ISrsLog::initialize() | @@ -38,6 +38,10 @@ int ISrsLog::initialize() | ||
| 38 | return ERROR_SUCCESS; | 38 | return ERROR_SUCCESS; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | +void ISrsLog::reopen() | ||
| 42 | +{ | ||
| 43 | +} | ||
| 44 | + | ||
| 41 | void ISrsLog::verbose(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) | 45 | void ISrsLog::verbose(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) |
| 42 | { | 46 | { |
| 43 | } | 47 | } |
| @@ -71,6 +71,10 @@ public: | @@ -71,6 +71,10 @@ public: | ||
| 71 | * initialize log utilities. | 71 | * initialize log utilities. |
| 72 | */ | 72 | */ |
| 73 | virtual int initialize(); | 73 | virtual int initialize(); |
| 74 | + /** | ||
| 75 | + * reopen the log file for log rotate. | ||
| 76 | + */ | ||
| 77 | + virtual void reopen(); | ||
| 74 | public: | 78 | public: |
| 75 | /** | 79 | /** |
| 76 | * log for verbose, very verbose information. | 80 | * log for verbose, very verbose information. |
-
请 注册 或 登录 后发表评论