For #1594, detect and disable daemon for docker. 3.0.127

pull/1636/head^2^2
winlin 5 years ago
parent c1e07d6a96
commit ed41ca867b

@ -146,6 +146,7 @@ For previous versions, please read:
## V3 changes
* v3.0, 2020-03-12, For [#1594][bug #1594], detect and disable daemon for docker. 3.0.127
* v3.0, 2020-03-12, For [#1634][bug #1634], always check status in thread loop. 3.0.126
* v3.0, 2020-03-11, For [#1634][bug #1634], refactor output with datetime for ingest/encoder/exec. 3.0.125
* v3.0, 2020-03-11, For [#1634][bug #1634], fix quit by accident SIGTERM while killing FFMPEG. 3.0.124
@ -1664,6 +1665,7 @@ Winlin
[bug #1579]: https://github.com/ossrs/srs/issues/1579
[bug #1598]: https://github.com/ossrs/srs/issues/1598
[bug #1634]: https://github.com/ossrs/srs/issues/1634
[bug #1594]: https://github.com/ossrs/srs/issues/1594
[bug #yyyyyyyyyyyyy]: https://github.com/ossrs/srs/issues/yyyyyyyyyyyyy
[exo #828]: https://github.com/google/ExoPlayer/pull/828

@ -93,6 +93,10 @@ grace_final_wait 3200;
# @see https://github.com/ossrs/srs/issues/1579#issuecomment-587475077
# default: off
force_grace_quit off;
# Whether disable daemon for docker.
# If on, it will set daemon to off in docker, even daemon is on.
# default: on
disable_daemon_for_docker on;
#############################################################################################
# heartbeat/stats sections

@ -3488,7 +3488,7 @@ srs_error_t SrsConfig::check_normal_config()
&& n != "http_server" && n != "stream_caster"
&& n != "utc_time" && n != "work_dir" && n != "asprocess"
&& n != "ff_log_level" && n != "grace_final_wait" && n != "force_grace_quit"
&& n != "grace_start_wait" && n != "empty_ip_ok"
&& n != "grace_start_wait" && n != "empty_ip_ok" && n != "disable_daemon_for_docker"
) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str());
}
@ -4099,6 +4099,18 @@ bool SrsConfig::is_force_grace_quit()
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::disable_daemon_for_docker()
{
static bool DEFAULT = true;
SrsConfDirective* conf = root->get("disable_daemon_for_docker");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
vector<SrsConfDirective*> SrsConfig::get_stream_casters()
{
srs_assert(root);

@ -476,6 +476,8 @@ public:
virtual srs_utime_t get_grace_final_wait();
// Whether force to gracefully quit, never fast quit.
virtual bool is_force_grace_quit();
// Whether disable daemon for docker.
virtual bool disable_daemon_for_docker();
// stream_caster section
public:
// Get all stream_caster in config file.

@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION3_HPP
#define SRS_CORE_VERSION3_HPP
#define SRS_VERSION3_REVISION 126
#define SRS_VERSION3_REVISION 127
#endif

@ -48,6 +48,7 @@ using namespace std;
#include <srs_core_performance.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_file.hpp>
// pre-declare
srs_error_t run(SrsServer* svr);
@ -350,6 +351,36 @@ string srs_getenv(const char* name)
return "";
}
// Detect docker by https://stackoverflow.com/a/41559867
srs_error_t srs_detect_docker(bool* is_docker)
{
srs_error_t err = srs_success;
*is_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")) {
*is_docker = true;
}
return err;
}
srs_error_t run(SrsServer* svr)
{
srs_error_t err = srs_success;
@ -359,8 +390,22 @@ srs_error_t run(SrsServer* svr)
return srs_error_wrap(err, "server initialize");
}
// Load daemon from config, disable it for docker.
// @see https://github.com/ossrs/srs/issues/1594
bool in_daemon = _srs_config->get_daemon();
if (in_daemon && _srs_config->disable_daemon_for_docker()) {
bool is_docker = false;
err = srs_detect_docker(&is_docker);
srs_error_reset(err); // Ignore any error while detecting docker.
if (is_docker) {
srs_warn("disable daemon for docker");
in_daemon = false;
}
}
// If not daemon, directly run master.
if (!_srs_config->get_daemon()) {
if (!in_daemon) {
if ((err = run_master(svr)) != srs_success) {
return srs_error_wrap(err, "run master");
}

Loading…
Cancel
Save