1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 20:01:56 +00:00

for #319, add signal to write config to file.

This commit is contained in:
winlin 2015-08-26 21:11:28 +08:00
parent cdde293785
commit 980e3921e4
4 changed files with 50 additions and 9 deletions

View file

@ -1421,6 +1421,13 @@ int SrsConfig::parse_options(int argc, char** argv)
return ret; return ret;
} }
int SrsConfig::persistence()
{
int ret = ERROR_SUCCESS;
// TODO: FIXME: implements it.
return ret;
}
string SrsConfig::config() string SrsConfig::config()
{ {
return config_file; return config_file;

View file

@ -287,6 +287,10 @@ public:
* parse the cli, the main(argc,argv) function. * parse the cli, the main(argc,argv) function.
*/ */
virtual int parse_options(int argc, char** argv); virtual int parse_options(int argc, char** argv);
/**
* persistence current config to file.
*/
virtual int persistence();
/** /**
* get the config file path. * get the config file path.
*/ */

View file

@ -50,7 +50,13 @@ using namespace std;
#include <srs_core_mem_watch.hpp> #include <srs_core_mem_watch.hpp>
// signal defines. // signal defines.
#define SIGNAL_RELOAD SIGHUP // reload the config file and apply new config.
#define SRS_SIGNAL_RELOAD SIGHUP
// terminate the srs with dispose to detect memory leak for gmp.
#define SRS_SIGNAL_DISPOSE SIGUSR2
// persistence the config in memory to config file.
// @see https://github.com/simple-rtmp-server/srs/issues/319#issuecomment-134993922
#define SRS_SIGNAL_PERSISTENCE_CONFIG SIGUSR1
// system interval in ms, // system interval in ms,
// all resolution times should be times togother, // all resolution times should be times togother,
@ -419,7 +425,7 @@ 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(SIGNAL_RELOAD, &sa, NULL); sigaction(SRS_SIGNAL_RELOAD, &sa, NULL);
sa.sa_handler = SrsSignalManager::sig_catcher; sa.sa_handler = SrsSignalManager::sig_catcher;
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
@ -434,7 +440,12 @@ 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(SIGUSR2, &sa, NULL); sigaction(SRS_SIGNAL_DISPOSE, &sa, NULL);
sa.sa_handler = SrsSignalManager::sig_catcher;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SRS_SIGNAL_PERSISTENCE_CONFIG, &sa, NULL);
srs_trace("signal installed"); srs_trace("signal installed");
@ -481,6 +492,7 @@ ISrsServerCycle::~ISrsServerCycle()
SrsServer::SrsServer() SrsServer::SrsServer()
{ {
signal_reload = false; signal_reload = false;
signal_persistence_config = false;
signal_gmc_stop = false; signal_gmc_stop = false;
signal_gracefully_quit = false; signal_gracefully_quit = false;
pid_fd = -1; pid_fd = -1;
@ -905,11 +917,16 @@ void SrsServer::remove(SrsConnection* conn)
void SrsServer::on_signal(int signo) void SrsServer::on_signal(int signo)
{ {
if (signo == SIGNAL_RELOAD) { if (signo == SRS_SIGNAL_RELOAD) {
signal_reload = true; signal_reload = true;
return; return;
} }
if (signo == SRS_SIGNAL_PERSISTENCE_CONFIG) {
signal_persistence_config = true;
return;
}
if (signo == SIGINT || signo == SIGUSR2) { if (signo == SIGINT || signo == SIGUSR2) {
#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.");
@ -986,7 +1003,7 @@ int SrsServer::do_cycle()
// do reload the config. // do reload the config.
if (signal_reload) { if (signal_reload) {
signal_reload = false; signal_reload = false;
srs_info("get signal reload, to reload the config."); srs_info("get signal to reload the config.");
if ((ret = _srs_config->reload()) != ERROR_SUCCESS) { if ((ret = _srs_config->reload()) != ERROR_SUCCESS) {
srs_error("reload config failed. ret=%d", ret); srs_error("reload config failed. ret=%d", ret);
@ -995,6 +1012,18 @@ int SrsServer::do_cycle()
srs_trace("reload config success."); srs_trace("reload config success.");
} }
// do persistence config to file.
if (signal_persistence_config) {
signal_persistence_config = false;
srs_info("get signal to persistence config to file.");
if ((ret = _srs_config->persistence()) != ERROR_SUCCESS) {
srs_error("persistence config to file failed. ret=%d", ret);
return ret;
}
srs_trace("persistence config to file success.");
}
// notice the stream sources to cycle. // notice the stream sources to cycle.
if ((ret = SrsSource::cycle_all()) != ERROR_SUCCESS) { if ((ret = SrsSource::cycle_all()) != ERROR_SUCCESS) {
return ret; return ret;

View file

@ -275,6 +275,7 @@ private:
* user send the signal, convert to variable. * user send the signal, convert to variable.
*/ */
bool signal_reload; bool signal_reload;
bool signal_persistence_config;
bool signal_gmc_stop; bool signal_gmc_stop;
bool signal_gracefully_quit; bool signal_gracefully_quit;
public: public: