1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 03:41:55 +00:00

Refine default config file for SRS. v5.0.120

1. Docker use srs.conf and env variables.
2. Show help if run SRS without any options.
3. Do not guess config file, use whatever from user.
This commit is contained in:
winlin 2022-12-31 09:38:59 +08:00
parent ae3b367487
commit 07a9a005d5
5 changed files with 17 additions and 46 deletions

View file

@ -56,4 +56,6 @@ RUN ldd /usr/local/srs/objs/ffmpeg/bin/ffmpeg && \
# Default workdir and command. # Default workdir and command.
WORKDIR /usr/local/srs WORKDIR /usr/local/srs
CMD ["./objs/srs", "-c", "conf/docker.conf"] ENV SRS_SRS_LOG_TANK=console SRS_DAEMON=off
CMD ["./objs/srs", "-c", "conf/srs.conf"]

View file

@ -193,10 +193,10 @@ http_api {
# default: off # default: off
enabled off; enabled off;
# whether enable rpc reload. # whether enable rpc reload.
# Overwrite by env SRS_HTTP_API_RAW_API_ALLOW_RELOAD
# default: off # default: off
allow_reload off; allow_reload off;
# whether enable rpc query. # whether enable rpc query.
# Overwrite by env SRS_HTTP_API_RAW_API_ALLOW_RELOAD
# Always off by https://github.com/ossrs/srs/issues/2653 # Always off by https://github.com/ossrs/srs/issues/2653
#allow_query off; #allow_query off;
# whether enable rpc update. # whether enable rpc update.

View file

@ -8,6 +8,7 @@ The changelog for SRS.
## SRS 5.0 Changelog ## SRS 5.0 Changelog
* v5.0, 2022-12-31, Refine default config file for SRS. v5.0.120
* v5.0, 2022-12-26, For [#939](https://github.com/ossrs/srs/issues/939): FLV: Fix bug for header flag gussing. v5.0.119 * v5.0, 2022-12-26, For [#939](https://github.com/ossrs/srs/issues/939): FLV: Fix bug for header flag gussing. v5.0.119
* v5.0, 2022-12-26, For [#296](https://github.com/ossrs/srs/issues/296): MP3: Convert RTMP(MP3) to WebRTC(OPUS). v5.0.118 * v5.0, 2022-12-26, For [#296](https://github.com/ossrs/srs/issues/296): MP3: Convert RTMP(MP3) to WebRTC(OPUS). v5.0.118
* v5.0, 2022-12-25, For [#296](https://github.com/ossrs/srs/issues/296): MP3: Support dump stream information. v5.0.117 * v5.0, 2022-12-25, For [#296](https://github.com/ossrs/srs/issues/296): MP3: Support dump stream information. v5.0.117

View file

@ -1837,8 +1837,8 @@ srs_error_t SrsConfig::parse_options(int argc, char** argv)
} }
} }
// Show help if has any argv // Show help if it has no argv
show_help = argc > 1; show_help = argc == 1;
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if ((err = parse_argv(i, argv)) != srs_success) { if ((err = parse_argv(i, argv)) != srs_success) {
return srs_error_wrap(err, "parse argv"); return srs_error_wrap(err, "parse argv");
@ -1859,55 +1859,23 @@ srs_error_t SrsConfig::parse_options(int argc, char** argv)
exit(0); exit(0);
} }
// first hello message. // The first hello message.
srs_trace(_srs_version); srs_trace(_srs_version);
// Config the env_only_ by env. // Config the env_only_ by env.
if (getenv("SRS_ENV_ONLY")) env_only_ = true; if (getenv("SRS_ENV_ONLY")) env_only_ = true;
// Try config files as bellow:
// User specified config(not empty), like user/docker.conf
// 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 (!env_only_) {
vector<string> try_config_files;
if (!config_file.empty()) {
try_config_files.push_back(config_file);
}
if (srs_string_ends_with(config_file, "docker.conf")) {
try_config_files.push_back(srs_string_replace(config_file, "docker.conf", "srs.conf"));
}
try_config_files.push_back(SRS_CONF_DEFAULT_COFNIG_FILE);
try_config_files.push_back("/etc/srs/srs.conf");
// Match the first exists file.
string exists_config_file;
for (int i = 0; i < (int) try_config_files.size(); i++) {
string try_config_file = try_config_files.at(i);
if (srs_path_exists(try_config_file)) {
exists_config_file = try_config_file;
break;
}
}
if (exists_config_file.empty()) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "no config file at %s", srs_join_vector_string(try_config_files, ", ").c_str());
}
if (config_file != exists_config_file) {
srs_warn("user config %s does not exists, use %s instead", config_file.c_str(), exists_config_file.c_str());
config_file = exists_config_file;
}
}
// Overwrite the config by env SRS_CONFIG_FILE. // Overwrite the config by env SRS_CONFIG_FILE.
if (!srs_getenv("srs.config.file").empty()) { if (!env_only_ && !srs_getenv("srs.config.file").empty()) { // SRS_CONFIG_FILE
string ov = config_file; string ov = config_file; config_file = srs_getenv("srs.config.file");
config_file = srs_getenv("srs.config.file");
srs_trace("ENV: Overwrite config %s to %s", ov.c_str(), config_file.c_str()); srs_trace("ENV: Overwrite config %s to %s", ov.c_str(), config_file.c_str());
} }
// Make sure config file exists.
if (!env_only_ && !srs_path_exists(config_file)) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "no config file at %s", config_file.c_str());
}
// Parse the matched config file. // Parse the matched config file.
if (!env_only_) { if (!env_only_) {
err = parse_file(config_file.c_str()); err = parse_file(config_file.c_str());

View file

@ -9,6 +9,6 @@
#define VERSION_MAJOR 5 #define VERSION_MAJOR 5
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 119 #define VERSION_REVISION 120
#endif #endif