From 58b40478b67c956ab9accc016f18a45898692bac Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Feb 2020 22:15:12 +0800 Subject: [PATCH] For #1579, support force gracefully quit. 3.0.120 --- README.md | 1 + trunk/conf/full.conf | 9 ++++++++- trunk/src/app/srs_app_config.cpp | 14 +++++++++++++- trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_server.cpp | 9 ++++++++- trunk/src/core/srs_core_version3.hpp | 2 +- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c99ca714b5..9bb47c2083 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-18, For [#1579][bug #1579], support force gracefully quit. 3.0.120 * v3.0, 2020-02-18, For [#1579][bug #1579], support gracefully quit. 3.0.119 * v3.0, 2020-02-17, For [#1601][bug #1601], flush async on_dvr/on_hls events before stop. 3.0.118 * v3.0, 2020-02-14, [3.0 beta1(3.0.117)][r3.0b1] released. 121964 lines. diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 137d91884a..e535e84ce2 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -73,9 +73,16 @@ work_dir ./; # default: off asprocess off; -# for gracefully quit, final wait for cleanup in milliseconds. +# For gracefully quit, final wait for cleanup in milliseconds. +# @see https://github.com/ossrs/srs/issues/1579#issuecomment-587414898 # default: 3200 grace_final_wait 3200; +# Whether force gracefully quit, never fast quit. +# By default, SIGTERM which means fast quit, is sent by K8S, so we need to +# force SRS to treat SIGTERM as gracefully quit for gray release or canary. +# @see https://github.com/ossrs/srs/issues/1579#issuecomment-587475077 +# default: off +force_grace_quit off; ############################################################################################# # heartbeat/stats sections diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 363ad358b4..ea517ff7fc 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3487,7 +3487,7 @@ srs_error_t SrsConfig::check_normal_config() && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms" && n != "http_server" && n != "stream_caster" && n != "utc_time" && n != "work_dir" && n != "asprocess" - && n != "ff_log_level" && n != "grace_final_wait" + && n != "ff_log_level" && n != "grace_final_wait" && n != "force_grace_quit" ) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str()); } @@ -4062,6 +4062,18 @@ srs_utime_t SrsConfig::get_grace_final_wait() return (srs_utime_t)(::atol(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS); } +bool SrsConfig::is_force_grace_quit() +{ + static bool DEFAULT = false; + + SrsConfDirective* conf = root->get("force_grace_quit"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return SRS_CONF_PERFER_FALSE(conf->arg0()); +} + vector SrsConfig::get_stream_casters() { srs_assert(root); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 3c04c3bdb1..d835bf8469 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -470,6 +470,8 @@ class SrsConfig virtual bool get_asprocess(); // Get the final wait in ms for gracefully quit. virtual srs_utime_t get_grace_final_wait(); + // Whether force to gracefully quit, never fast quit. + virtual bool is_force_grace_quit(); // stream_caster section public: // Get all stream_caster in config file. diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 4c0a4b2fbf..22d0f857e5 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -920,7 +920,14 @@ void SrsServer::on_signal(int signo) #endif #endif } - + + // For K8S, force to gracefully quit for gray release or canary. + // @see https://github.com/ossrs/srs/issues/1595#issuecomment-587473037 + if (signo == SRS_SIGNAL_FAST_QUIT && _srs_config->is_force_grace_quit()) { + srs_trace("force gracefully quit, signo=%d", signo); + signo = SRS_SIGNAL_GRACEFULLY_QUIT; + } + if ((signo == SIGINT || signo == SRS_SIGNAL_FAST_QUIT) && !signal_fast_quit) { srs_trace("sig=%d, user terminate program, fast quit", signo); signal_fast_quit = true; diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index c276341237..4e9f290ae9 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 119 +#define SRS_VERSION3_REVISION 120 #endif