Skip to content

Commit

Permalink
for #319, add signal to write config to file.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 26, 2015
1 parent cdde293 commit 980e392
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
7 changes: 7 additions & 0 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,13 @@ int SrsConfig::parse_options(int argc, char** argv)
return ret;
}

int SrsConfig::persistence()
{
int ret = ERROR_SUCCESS;
// TODO: FIXME: implements it.
return ret;
}

string SrsConfig::config()
{
return config_file;
Expand Down
12 changes: 8 additions & 4 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,16 @@ class SrsConfig
// parse options and file
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);
/**
* get the config file path.
*/
* persistence current config to file.
*/
virtual int persistence();
/**
* get the config file path.
*/
virtual std::string config();
private:
/**
Expand Down
39 changes: 34 additions & 5 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ using namespace std;
#include <srs_core_mem_watch.hpp>

// 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,
// all resolution times should be times togother,
Expand Down Expand Up @@ -419,7 +425,7 @@ int SrsSignalManager::start()
sa.sa_handler = SrsSignalManager::sig_catcher;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGNAL_RELOAD, &sa, NULL);
sigaction(SRS_SIGNAL_RELOAD, &sa, NULL);

sa.sa_handler = SrsSignalManager::sig_catcher;
sigemptyset(&sa.sa_mask);
Expand All @@ -434,7 +440,12 @@ int SrsSignalManager::start()
sa.sa_handler = SrsSignalManager::sig_catcher;
sigemptyset(&sa.sa_mask);
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");

Expand Down Expand Up @@ -481,6 +492,7 @@ ISrsServerCycle::~ISrsServerCycle()
SrsServer::SrsServer()
{
signal_reload = false;
signal_persistence_config = false;
signal_gmc_stop = false;
signal_gracefully_quit = false;
pid_fd = -1;
Expand Down Expand Up @@ -905,11 +917,16 @@ void SrsServer::remove(SrsConnection* conn)

void SrsServer::on_signal(int signo)
{
if (signo == SIGNAL_RELOAD) {
if (signo == SRS_SIGNAL_RELOAD) {
signal_reload = true;
return;
}

if (signo == SRS_SIGNAL_PERSISTENCE_CONFIG) {
signal_persistence_config = true;
return;
}

if (signo == SIGINT || signo == SIGUSR2) {
#ifdef SRS_AUTO_GPERF_MC
srs_trace("gmc is on, main cycle will terminate normally.");
Expand Down Expand Up @@ -986,7 +1003,7 @@ int SrsServer::do_cycle()
// do reload the config.
if (signal_reload) {
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) {
srs_error("reload config failed. ret=%d", ret);
Expand All @@ -995,6 +1012,18 @@ int SrsServer::do_cycle()
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.
if ((ret = SrsSource::cycle_all()) != ERROR_SUCCESS) {
return ret;
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class SrsServer : virtual public ISrsReloadHandler
* user send the signal, convert to variable.
*/
bool signal_reload;
bool signal_persistence_config;
bool signal_gmc_stop;
bool signal_gracefully_quit;
public:
Expand Down

0 comments on commit 980e392

Please sign in to comment.