mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Config: Support startting with environment variable only. v5.0.85
This commit is contained in:
parent
ef0aefd546
commit
9f7a06bc9e
5 changed files with 35 additions and 60 deletions
11
.run/env.run.xml
Normal file
11
.run/env.run.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="env" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="-e" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" WORKING_DIR="file://$CMakeCurrentBuildDir$/../../../" PASS_PARENT_ENVS_2="true" PROJECT_NAME="srs" TARGET_NAME="srs" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="srs" RUN_TARGET_NAME="srs">
|
||||
<envs>
|
||||
<env name="SRS_LISTEN" value="1935" />
|
||||
<env name="SRS_EXPORTER_ENABLED" value="on" />
|
||||
</envs>
|
||||
<method v="2">
|
||||
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
|
@ -8,6 +8,7 @@ The changelog for SRS.
|
|||
|
||||
## SRS 5.0 Changelog
|
||||
|
||||
* v5.0, 2022-10-30, Config: Support startting with environment variable only. v5.0.85
|
||||
* v5.0, 2022-10-26, Fix [#3218](https://github.com/ossrs/srs/issues/3218): Log: Follow Java/log4j log level specs. v5.0.83
|
||||
* v5.0, 2022-10-25, Log: Refine the log interface. v5.0.82
|
||||
* v5.0, 2022-10-23, For [#3216](https://github.com/ossrs/srs/issues/3216): Support Google Address Sanitizer. v5.0.81
|
||||
|
|
|
@ -1262,7 +1262,7 @@ srs_error_t SrsConfDirective::read_token(SrsConfigBuffer* buffer, vector<string>
|
|||
|
||||
SrsConfig::SrsConfig()
|
||||
{
|
||||
dolphin = false;
|
||||
env_only_ = false;
|
||||
|
||||
show_help = false;
|
||||
show_version = false;
|
||||
|
@ -1279,11 +1279,6 @@ SrsConfig::~SrsConfig()
|
|||
srs_freep(root);
|
||||
}
|
||||
|
||||
bool SrsConfig::is_dolphin()
|
||||
{
|
||||
return dolphin;
|
||||
}
|
||||
|
||||
void SrsConfig::subscribe(ISrsReloadHandler* handler)
|
||||
{
|
||||
std::vector<ISrsReloadHandler*>::iterator it;
|
||||
|
@ -1858,7 +1853,7 @@ srs_error_t SrsConfig::parse_options(int argc, char** argv)
|
|||
// If user specified *docker.conf, try *srs.conf, like user/srs.conf
|
||||
// Try the default srs config, defined as SRS_CONF_DEFAULT_COFNIG_FILE, like conf/srs.conf
|
||||
// Try config for FHS, like /etc/srs/srs.conf @see https://github.com/ossrs/srs/pull/2711
|
||||
if (true) {
|
||||
if (!env_only_) {
|
||||
vector<string> try_config_files;
|
||||
if (!config_file.empty()) {
|
||||
try_config_files.push_back(config_file);
|
||||
|
@ -1897,7 +1892,9 @@ srs_error_t SrsConfig::parse_options(int argc, char** argv)
|
|||
}
|
||||
|
||||
// Parse the matched config file.
|
||||
if (!env_only_) {
|
||||
err = parse_file(config_file.c_str());
|
||||
}
|
||||
|
||||
if (test_conf) {
|
||||
// the parse_file never check the config,
|
||||
|
@ -1924,6 +1921,13 @@ srs_error_t SrsConfig::parse_options(int argc, char** argv)
|
|||
return srs_error_wrap(err, "transform");
|
||||
}
|
||||
|
||||
// If use env only, we set change to daemon(off) and console log.
|
||||
if (env_only_) {
|
||||
if (!getenv("SRS_DAEMON")) setenv("SRS_DAEMON", "off", 1);
|
||||
if (!getenv("SRS_SRS_LOG_TANK")) setenv("SRS_SRS_LOG_TANK", "console", 1);
|
||||
if (root->directives.empty()) root->get_or_create("vhost", "__defaultVhost__");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// check log name and level
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
@ -2127,28 +2131,10 @@ srs_error_t SrsConfig::parse_argv(int& i, char** argv)
|
|||
show_help = false;
|
||||
test_conf = true;
|
||||
break;
|
||||
case 'p':
|
||||
dolphin = true;
|
||||
if (*p) {
|
||||
dolphin_rtmp_port = p;
|
||||
continue;
|
||||
}
|
||||
if (argv[++i]) {
|
||||
dolphin_rtmp_port = argv[i];
|
||||
continue;
|
||||
}
|
||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "-p requires params");
|
||||
case 'x':
|
||||
dolphin = true;
|
||||
if (*p) {
|
||||
dolphin_http_port = p;
|
||||
continue;
|
||||
}
|
||||
if (argv[++i]) {
|
||||
dolphin_http_port = argv[i];
|
||||
continue;
|
||||
}
|
||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "-x requires params");
|
||||
case 'e':
|
||||
show_help = false;
|
||||
env_only_ = true;
|
||||
break;
|
||||
case 'v':
|
||||
case 'V':
|
||||
show_help = false;
|
||||
|
@ -2183,11 +2169,12 @@ void SrsConfig::print_help(char** argv)
|
|||
{
|
||||
printf(
|
||||
"%s, %s, %s, created by %sand %s\n\n"
|
||||
"Usage: %s <-h?vVgG>|<[-t] -c filename>\n"
|
||||
"Usage: %s <-h?vVgGe>|<[-t] -c filename>\n"
|
||||
"Options:\n"
|
||||
" -?, -h : Show this help and exit 0.\n"
|
||||
" -v, -V : Show version and exit 0.\n"
|
||||
" -g, -G : Show server signature and exit 0.\n"
|
||||
" -e : Use environment variable only, ignore config file.\n"
|
||||
" -t : Test configuration file, exit with error code(0 for success).\n"
|
||||
" -c filename : Use config file to start server.\n"
|
||||
"For example:\n"
|
||||
|
@ -2269,7 +2256,7 @@ srs_error_t SrsConfig::check_normal_config()
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// check empty
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
if (root->directives.size() == 0) {
|
||||
if (!env_only_ && root->directives.size() == 0) {
|
||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "conf is empty");
|
||||
}
|
||||
|
||||
|
@ -2383,7 +2370,7 @@ srs_error_t SrsConfig::check_normal_config()
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
if (true) {
|
||||
vector<string> listens = get_listens();
|
||||
if (listens.size() <= 0) {
|
||||
if (!env_only_ && listens.size() <= 0) {
|
||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "listen requires params");
|
||||
}
|
||||
for (int i = 0; i < (int)listens.size(); i++) {
|
||||
|
@ -2774,23 +2761,6 @@ srs_error_t SrsConfig::parse_buffer(SrsConfigBuffer* buffer)
|
|||
return srs_error_wrap(err, "root parse");
|
||||
}
|
||||
|
||||
// mock by dolphin mode.
|
||||
// for the dolphin will start srs with specified params.
|
||||
if (dolphin) {
|
||||
// for RTMP.
|
||||
set_config_directive(root, "listen", dolphin_rtmp_port);
|
||||
|
||||
// for HTTP
|
||||
set_config_directive(root, "http_server", "");
|
||||
SrsConfDirective* http_server = root->get("http_server");
|
||||
set_config_directive(http_server, "enabled", "on");
|
||||
set_config_directive(http_server, "listen", dolphin_http_port);
|
||||
|
||||
// others.
|
||||
set_config_directive(root, "daemon", "off");
|
||||
set_config_directive(root, "srs_log_tank", "console");
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
@ -266,11 +266,6 @@ class SrsConfig
|
|||
friend class SrsConfDirective;
|
||||
// user command
|
||||
private:
|
||||
// Whether srs is run in dolphin mode.
|
||||
// @see https://github.com/ossrs/srs-dolphin
|
||||
bool dolphin;
|
||||
std::string dolphin_rtmp_port;
|
||||
std::string dolphin_http_port;
|
||||
// Whether show help and exit.
|
||||
bool show_help;
|
||||
// Whether test config file and exit.
|
||||
|
@ -279,6 +274,8 @@ private:
|
|||
bool show_version;
|
||||
// Whether show SRS signature and exit.
|
||||
bool show_signature;
|
||||
// Whether only use environment variable, ignore config file.
|
||||
bool env_only_;
|
||||
// global env variables.
|
||||
private:
|
||||
// The user parameters, the argc and argv.
|
||||
|
@ -301,10 +298,6 @@ private:
|
|||
public:
|
||||
SrsConfig();
|
||||
virtual ~SrsConfig();
|
||||
// dolphin
|
||||
public:
|
||||
// Whether srs is in dolphin mode.
|
||||
virtual bool is_dolphin();
|
||||
// Reload
|
||||
public:
|
||||
// For reload handler to register itself,
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
|
||||
#define VERSION_MAJOR 5
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 84
|
||||
#define VERSION_REVISION 85
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue