diff --git a/.run/env.run.xml b/.run/env.run.xml
new file mode 100644
index 000000000..f12de1c68
--- /dev/null
+++ b/.run/env.run.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md
index 748ec9a7a..554044510 100644
--- a/trunk/doc/CHANGELOG.md
+++ b/trunk/doc/CHANGELOG.md
@@ -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
diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp
index e03377783..40e7ded08 100644
--- a/trunk/src/app/srs_app_config.cpp
+++ b/trunk/src/app/srs_app_config.cpp
@@ -1262,7 +1262,7 @@ srs_error_t SrsConfDirective::read_token(SrsConfigBuffer* buffer, vector
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::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 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.
- err = parse_file(config_file.c_str());
+ 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 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;
}
diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp
index 17d5c5e0a..24f9ddbb1 100644
--- a/trunk/src/app/srs_app_config.hpp
+++ b/trunk/src/app/srs_app_config.hpp
@@ -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,
diff --git a/trunk/src/core/srs_core_version5.hpp b/trunk/src/core/srs_core_version5.hpp
index 39b148fa6..0e523d1ec 100644
--- a/trunk/src/core/srs_core_version5.hpp
+++ b/trunk/src/core/srs_core_version5.hpp
@@ -9,6 +9,6 @@
#define VERSION_MAJOR 5
#define VERSION_MINOR 0
-#define VERSION_REVISION 84
+#define VERSION_REVISION 85
#endif