mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
for #319, add signal to write config to file.
This commit is contained in:
parent
cdde293785
commit
980e3921e4
4 changed files with 50 additions and 9 deletions
|
@ -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;
|
||||
|
|
|
@ -284,12 +284,16 @@ private:
|
|||
// 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:
|
||||
/**
|
||||
|
|
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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.");
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
|
|
@ -275,6 +275,7 @@ private:
|
|||
* user send the signal, convert to variable.
|
||||
*/
|
||||
bool signal_reload;
|
||||
bool signal_persistence_config;
|
||||
bool signal_gmc_stop;
|
||||
bool signal_gracefully_quit;
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue