mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine docker detect mechenism. v5.0.190 v6.0.90 (#3758)
When using Docker, logs are usually printed to console (stdout and stderr). However, since Docker detection occurs late, after log initialization, the default log output may be incorrect. In Docker, logs may still be written to a file instead of the console as expected. Additionally, the Dockerfile has been improved with a new environment variable `SRS_IN_DOCKER=on` to clearly indicate a Docker environment. If automatic Docker detection fails, the configuration will be read, and this variable will correctly inform SRS that it's in a Docker environment. Lastly, the default configuration values have been improved for Docker environments. By default, `SRS_LOG_TANK=console` and daemon mode is disabled. --------- Co-authored-by: john <hondaxiao@tencent.com>
This commit is contained in:
parent
c91e3a36c2
commit
a458c9c68d
6 changed files with 54 additions and 51 deletions
|
@ -56,6 +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
|
||||||
ENV SRS_DAEMON=off
|
ENV SRS_DAEMON=off SRS_IN_DOCKER=on
|
||||||
CMD ["./objs/srs", "-c", "conf/docker.conf"]
|
CMD ["./objs/srs", "-c", "conf/docker.conf"]
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ The changelog for SRS.
|
||||||
<a name="v6-changes"></a>
|
<a name="v6-changes"></a>
|
||||||
|
|
||||||
## SRS 6.0 Changelog
|
## SRS 6.0 Changelog
|
||||||
|
* v6.0, 2023-10-17, Merge [#3758](https://github.com/ossrs/srs/pull/3758): Refine docker detect mechenism. v6.0.90 (#3758)
|
||||||
* v6.0, 2023-10-11, Merge [#3827](https://github.com/ossrs/srs/pull/3827): Fix bug for upgrading to OpenSSL 3.0. v6.0.89 (#3827)
|
* v6.0, 2023-10-11, Merge [#3827](https://github.com/ossrs/srs/pull/3827): Fix bug for upgrading to OpenSSL 3.0. v6.0.89 (#3827)
|
||||||
* v6.0, 2023-10-10, Merge [#3825](https://github.com/ossrs/srs/pull/3825): SRT: Fix the missing config mss. v6.0.88 (#3825)
|
* v6.0, 2023-10-10, Merge [#3825](https://github.com/ossrs/srs/pull/3825): SRT: Fix the missing config mss. v6.0.88 (#3825)
|
||||||
* v6.0, 2023-10-08, Merge [#3824](https://github.com/ossrs/srs/pull/3824): Solve the problem of inaccurate HLS TS duration. v6.0.87 (#3824)
|
* v6.0, 2023-10-08, Merge [#3824](https://github.com/ossrs/srs/pull/3824): Solve the problem of inaccurate HLS TS duration. v6.0.87 (#3824)
|
||||||
|
@ -101,6 +102,7 @@ The changelog for SRS.
|
||||||
<a name="v5-changes"></a>
|
<a name="v5-changes"></a>
|
||||||
|
|
||||||
## SRS 5.0 Changelog
|
## SRS 5.0 Changelog
|
||||||
|
* v5.0, 2023-10-17, Merge [#3758](https://github.com/ossrs/srs/pull/3758): Refine docker detect mechenism. v5.0.190 (#3758)
|
||||||
* v5.0, 2023-10-11, Merge [#3827](https://github.com/ossrs/srs/pull/3827): Fix bug for upgrading to OpenSSL 3.0. v5.0.189 (#3827)
|
* v5.0, 2023-10-11, Merge [#3827](https://github.com/ossrs/srs/pull/3827): Fix bug for upgrading to OpenSSL 3.0. v5.0.189 (#3827)
|
||||||
* v5.0, 2023-10-10, Merge [#3825](https://github.com/ossrs/srs/pull/3825): SRT: Fix the missing config mss. v5.0.188 (#3825)
|
* v5.0, 2023-10-10, Merge [#3825](https://github.com/ossrs/srs/pull/3825): SRT: Fix the missing config mss. v5.0.188 (#3825)
|
||||||
* v5.0, 2023-10-08, Merge [#3824](https://github.com/ossrs/srs/pull/3824): Solve the problem of inaccurate HLS TS duration. v5.0.187 (#3824)
|
* v5.0, 2023-10-08, Merge [#3824](https://github.com/ossrs/srs/pull/3824): Solve the problem of inaccurate HLS TS duration. v5.0.187 (#3824)
|
||||||
|
|
|
@ -94,6 +94,38 @@ bool is_common_space(char ch)
|
||||||
return (ch == ' ' || ch == '\t' || ch == SRS_CR || ch == SRS_LF);
|
return (ch == ' ' || ch == '\t' || ch == SRS_CR || ch == SRS_LF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern bool _srs_in_docker;
|
||||||
|
|
||||||
|
// Detect docker by https://stackoverflow.com/a/41559867
|
||||||
|
srs_error_t srs_detect_docker()
|
||||||
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
_srs_in_docker = false;
|
||||||
|
|
||||||
|
SrsFileReader fr;
|
||||||
|
if ((err = fr.open("/proc/1/cgroup")) != srs_success) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t nn;
|
||||||
|
char buf[1024];
|
||||||
|
if ((err = fr.read(buf, sizeof(buf), &nn)) != srs_success) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nn <= 0) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
string s(buf, nn);
|
||||||
|
if (srs_string_contains(s, "/docker")) {
|
||||||
|
_srs_in_docker = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
namespace srs_internal
|
namespace srs_internal
|
||||||
{
|
{
|
||||||
SrsConfigBuffer::SrsConfigBuffer()
|
SrsConfigBuffer::SrsConfigBuffer()
|
||||||
|
@ -1934,6 +1966,19 @@ srs_error_t SrsConfig::parse_options(int argc, char** argv)
|
||||||
if (root->directives.empty()) root->get_or_create("vhost", "__defaultVhost__");
|
if (root->directives.empty()) root->get_or_create("vhost", "__defaultVhost__");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore any error while detecting docker.
|
||||||
|
if ((err = srs_detect_docker()) != srs_success) {
|
||||||
|
srs_error_reset(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to load the config if docker detect failed.
|
||||||
|
if (!_srs_in_docker) {
|
||||||
|
_srs_in_docker = _srs_config->get_in_docker();
|
||||||
|
if (_srs_in_docker) {
|
||||||
|
srs_trace("enable in_docker by config");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// check log name and level
|
// check log name and level
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -2856,7 +2901,7 @@ string SrsConfig::argv()
|
||||||
|
|
||||||
bool SrsConfig::get_daemon()
|
bool SrsConfig::get_daemon()
|
||||||
{
|
{
|
||||||
SRS_OVERWRITE_BY_ENV_BOOL2("srs.daemon");
|
SRS_OVERWRITE_BY_ENV_BOOL2("srs.daemon"); // SRS_DAEMON
|
||||||
|
|
||||||
SrsConfDirective* conf = root->get("daemon");
|
SrsConfDirective* conf = root->get("daemon");
|
||||||
if (!conf || conf->arg0().empty()) {
|
if (!conf || conf->arg0().empty()) {
|
||||||
|
@ -6520,8 +6565,6 @@ string SrsConfig::get_ingest_input_url(SrsConfDirective* conf)
|
||||||
return conf->arg0();
|
return conf->arg0();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern bool _srs_in_docker;
|
|
||||||
|
|
||||||
bool SrsConfig::get_log_tank_file()
|
bool SrsConfig::get_log_tank_file()
|
||||||
{
|
{
|
||||||
if (!srs_getenv("srs.srs_log_tank").empty()) { // SRS_SRS_LOG_TANK
|
if (!srs_getenv("srs.srs_log_tank").empty()) { // SRS_SRS_LOG_TANK
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 5
|
#define VERSION_MAJOR 5
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 189
|
#define VERSION_REVISION 190
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 6
|
#define VERSION_MAJOR 6
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 89
|
#define VERSION_REVISION 90
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -57,7 +57,6 @@ using namespace std;
|
||||||
// pre-declare
|
// pre-declare
|
||||||
srs_error_t run_directly_or_daemon();
|
srs_error_t run_directly_or_daemon();
|
||||||
srs_error_t run_in_thread_pool();
|
srs_error_t run_in_thread_pool();
|
||||||
srs_error_t srs_detect_docker();
|
|
||||||
void show_macro_features();
|
void show_macro_features();
|
||||||
|
|
||||||
// @global log and context.
|
// @global log and context.
|
||||||
|
@ -79,6 +78,9 @@ bool _srs_config_by_env = false;
|
||||||
// The binary name of SRS.
|
// The binary name of SRS.
|
||||||
const char* _srs_binary = NULL;
|
const char* _srs_binary = NULL;
|
||||||
|
|
||||||
|
// @global Other variables.
|
||||||
|
bool _srs_in_docker = false;
|
||||||
|
|
||||||
// Free global data, for address sanitizer.
|
// Free global data, for address sanitizer.
|
||||||
extern void srs_free_global_system_ips();
|
extern void srs_free_global_system_ips();
|
||||||
|
|
||||||
|
@ -131,11 +133,6 @@ srs_error_t do_main(int argc, char** argv, char** envp)
|
||||||
#ifdef SRS_GPERF_MP
|
#ifdef SRS_GPERF_MP
|
||||||
#warning "gmp is not used for memory leak, please use gmc instead."
|
#warning "gmp is not used for memory leak, please use gmc instead."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Ignore any error while detecting docker.
|
|
||||||
if ((err = srs_detect_docker()) != srs_success) {
|
|
||||||
srs_error_reset(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// never use srs log(srs_trace, srs_error, etc) before config parse the option,
|
// never use srs log(srs_trace, srs_error, etc) before config parse the option,
|
||||||
// which will load the log config and apply it.
|
// which will load the log config and apply it.
|
||||||
|
@ -400,49 +397,10 @@ void show_macro_features()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect docker by https://stackoverflow.com/a/41559867
|
|
||||||
bool _srs_in_docker = false;
|
|
||||||
srs_error_t srs_detect_docker()
|
|
||||||
{
|
|
||||||
srs_error_t err = srs_success;
|
|
||||||
|
|
||||||
_srs_in_docker = false;
|
|
||||||
|
|
||||||
SrsFileReader fr;
|
|
||||||
if ((err = fr.open("/proc/1/cgroup")) != srs_success) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t nn;
|
|
||||||
char buf[1024];
|
|
||||||
if ((err = fr.read(buf, sizeof(buf), &nn)) != srs_success) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nn <= 0) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
string s(buf, nn);
|
|
||||||
if (srs_string_contains(s, "/docker")) {
|
|
||||||
_srs_in_docker = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
srs_error_t run_directly_or_daemon()
|
srs_error_t run_directly_or_daemon()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
// Try to load the config if docker detect failed.
|
|
||||||
if (!_srs_in_docker) {
|
|
||||||
_srs_in_docker = _srs_config->get_in_docker();
|
|
||||||
if (_srs_in_docker) {
|
|
||||||
srs_trace("enable in_docker by config");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load daemon from config, disable it for docker.
|
// Load daemon from config, disable it for docker.
|
||||||
// @see https://github.com/ossrs/srs/issues/1594
|
// @see https://github.com/ossrs/srs/issues/1594
|
||||||
bool run_as_daemon = _srs_config->get_daemon();
|
bool run_as_daemon = _srs_config->get_daemon();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue