Skip to content

Commit

Permalink
Config: Guess config files by FHS. v4.0.194 (#2711)
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Nov 7, 2021
1 parent b066615 commit 1f4dad0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
1 change: 1 addition & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The changelog for SRS.

## SRS 4.0 Changelog

* v4.0, 2021-11-07, Merge [#2711](https://github.com/ossrs/srs/pull/2711): Config: Guess config files by [FHS](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard). v4.0.194
* v4.0, 2021-11-07, Merge [#2714](https://github.com/ossrs/srs/pull/2714): DVR: copy req from publish. v4.0.193
* v4.0, 2021-11-04, Merge [#2707](https://github.com/ossrs/srs/pull/2707): Refuse edge request when state is stopping. v4.0.192
* v4.0, 2021-11-02, Auto create package by github actions. v4.0.191
Expand Down
52 changes: 38 additions & 14 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1956,8 +1956,8 @@ srs_error_t SrsConfig::parse_options(int argc, char** argv)
}
}

// config
show_help = true;
// Show help if has any argv
show_help = argc > 1;
for (int i = 1; i < argc; i++) {
if ((err = parse_argv(i, argv)) != srs_success) {
return srs_error_wrap(err, "parse argv");
Expand All @@ -1980,21 +1980,45 @@ srs_error_t SrsConfig::parse_options(int argc, char** argv)

// first hello message.
srs_trace(_srs_version);

if (config_file.empty()) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "no config, read help: %s -h", argv[0]);
}

// For docker, if config is not specified, try srs.conf instead.
string try_config = srs_string_replace(config_file, "docker.conf", "srs.conf");
if (!srs_path_exists(config_file) && try_config != config_file) {
if (!srs_path_exists(try_config)) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "no config file %s or %s", config_file.c_str(), try_config.c_str());
// Try config files as bellow:
// config_file Specified by user, like conf/srs.conf
// try_docker_config Guess by SRS, like conf/docker.conf
// try_fhs_config For FHS, try /etc/srs/srs.conf first, @see https://github.com/ossrs/srs/pull/2711
if (!srs_path_exists(config_file)) {
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);
if (srs_string_ends_with(SRS_CONF_DEFAULT_COFNIG_FILE, "docker.conf")) {
try_config_files.push_back(srs_string_replace(SRS_CONF_DEFAULT_COFNIG_FILE, "docker.conf", "srs.conf"));
}
try_config_files.push_back("/etc/srs/srs.conf");

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;
}
srs_warn("user config %s does not exists, use %s instead", config_file.c_str(), try_config.c_str());
config_file = try_config;
}


// Parse the matched config file.
err = parse_file(config_file.c_str());

if (test_conf) {
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 4
#define VERSION_MINOR 0
#define VERSION_REVISION 193
#define VERSION_REVISION 194

#endif

0 comments on commit 1f4dad0

Please sign in to comment.