From 2a01540433ebd4f65968cf4d7c4ab644c8563ffa Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 23 Sep 2016 14:53:58 +0800 Subject: [PATCH 1/3] support change work_dir for oryx. --- README.md | 1 + trunk/conf/full.conf | 6 ++++++ trunk/src/app/srs_app_config.cpp | 13 ++++++++++++- trunk/src/app/srs_app_config.hpp | 5 +++++ trunk/src/main/srs_main_server.cpp | 7 +++++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1c8aaf8c9..fd97f3f07 100755 --- a/README.md +++ b/README.md @@ -343,6 +343,7 @@ Remark: ## History +* v2.0, 2016-09-23, support change work_dir for oryx. * v2.0, 2016-09-15, fix #640, typo for rtmp type. 2.0.217 * v2.0, 2016-09-12, fix fast stream error bug. 2.0.216 * v2.0, 2016-09-09, [2.0 beta1(2.0.215)][r2.0b1] released. 89941 lines. diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index f6488e3ea..a52fd7b4c 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -50,6 +50,12 @@ daemon on; # default: off utc_time off; +# the work dir for server, to chdir(work_dir) when not empty or "./" +# user can config this directory to change the dir. +# @reamrk do not support reload. +# default: ./ +work_dir ./; + ############################################################################################# # heartbeat/stats sections ############################################################################################# diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 3b65254c8..f0b28fbc4 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -1567,7 +1567,7 @@ int SrsConfig::check_config() && n != "max_connections" && n != "daemon" && n != "heartbeat" && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms" && n != "http_stream" && n != "http_server" && n != "stream_caster" - && n != "utc_time" + && n != "utc_time" && n != "work_dir" ) { ret = ERROR_SYSTEM_CONFIG_INVALID; srs_error("unsupported directive %s, ret=%d", n.c_str(), ret); @@ -2172,6 +2172,17 @@ bool SrsConfig::get_utc_time() return SRS_CONF_PERFER_FALSE(conf->arg0()); } +string SrsConfig::get_work_dir() { + static string DEFAULT = "./"; + + SrsConfDirective* conf = root->get("work_dir"); + if( !conf || conf->arg0().empty()) { + return DEFAULT; + } + + return 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 79c1d9c25..ef0e1ff79 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -374,6 +374,11 @@ public: * whether use utc-time to format the time. */ virtual bool get_utc_time(); + /** + * get the configed work dir. + * ignore if empty string. + */ + virtual std::string get_work_dir(); // stream_caster section public: /** diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index c0bf43fd6..21a10077e 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -282,6 +282,13 @@ int main(int argc, char** argv) return ret; } + // change the work dir and set cwd. + std::string cwd = _srs_config->get_work_dir(); + if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) { + srs_error("change cwd to %s failed. ret=%d", cwd.c_str(), ret); + return ret; + } + // config parsed, initialize log. if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) { return ret; From b748fac23a71dbbbde594d3128a6c47d07a82cfb Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 23 Sep 2016 15:00:50 +0800 Subject: [PATCH 2/3] support asprocess for oryx. 2.0.218 --- README.md | 1 + trunk/conf/full.conf | 7 +++++++ trunk/src/app/srs_app_config.cpp | 21 ++++++++++++++++++++- trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_server.cpp | 21 ++++++++++++++++++++- trunk/src/app/srs_app_server.hpp | 2 ++ trunk/src/core/srs_core.hpp | 2 +- 7 files changed, 53 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fd97f3f07..de12ce60a 100755 --- a/README.md +++ b/README.md @@ -343,6 +343,7 @@ Remark: ## History +* v2.0, 2016-09-23, support asprocess for oryx. 2.0.218 * v2.0, 2016-09-23, support change work_dir for oryx. * v2.0, 2016-09-15, fix #640, typo for rtmp type. 2.0.217 * v2.0, 2016-09-12, fix fast stream error bug. 2.0.216 diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index a52fd7b4c..f4e83618c 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -55,6 +55,13 @@ utc_time off; # @reamrk do not support reload. # default: ./ work_dir ./; +# whether quit when parent process changed, +# used for supervisor mode(not daemon), srs should always quit when +# supervisor process exited. +# @remark conflict with daemon, error when both daemon and asprocess are on. +# @reamrk do not support reload. +# default: off +asprocess off; ############################################################################################# # heartbeat/stats sections diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index f0b28fbc4..0c190540a 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -1567,7 +1567,7 @@ int SrsConfig::check_config() && n != "max_connections" && n != "daemon" && n != "heartbeat" && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms" && n != "http_stream" && n != "http_server" && n != "stream_caster" - && n != "utc_time" && n != "work_dir" + && n != "utc_time" && n != "work_dir" && n != "asprocess" ) { ret = ERROR_SYSTEM_CONFIG_INVALID; srs_error("unsupported directive %s, ret=%d", n.c_str(), ret); @@ -2055,6 +2055,13 @@ int SrsConfig::check_config() // TODO: FIXME: required http server when hls storage is ram or both. } + // asprocess conflict with daemon + if (get_asprocess() && get_deamon()) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("daemon conflict with asprocess, ret=%d", ret); + return ret; + } + return ret; } @@ -2183,6 +2190,18 @@ string SrsConfig::get_work_dir() { return conf->arg0(); } +bool SrsConfig::get_asprocess() +{ + static bool DEFAULT = false; + + SrsConfDirective* conf = root->get("asprocess"); + 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 ef0e1ff79..0f8ac1217 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -379,6 +379,8 @@ public: * ignore if empty string. */ virtual std::string get_work_dir(); + // whether use asprocess mode. + virtual bool get_asprocess(); // stream_caster section public: /** diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 23fc68b0c..448aa467e 100755 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -488,6 +488,7 @@ SrsServer::SrsServer() signal_manager = NULL; handler = NULL; + ppid = -1; // donot new object in constructor, // for some global instance is not ready now, @@ -635,7 +636,16 @@ int SrsServer::initialize_st() // set current log id. _srs_context->generate_id(); - srs_trace("server main cid=%d", _srs_context->get_id()); + + // check asprocess. + bool asprocess = _srs_config->get_asprocess(); + if (ppid == 1) { + ret = ERROR_SYSTEM_ASSERT_FAILED; + srs_error("for asprocess, ppid should never be init(1), ret=%d", ret); + return ret; + } + srs_trace("server main cid=%d, pid=%d, ppid=%d, asprocess=%d", + _srs_context->get_id(), ::getpid(), ppid, asprocess); return ret; } @@ -945,6 +955,9 @@ int SrsServer::do_cycle() max = srs_max(max, SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES); #endif + // for asprocess. + bool asprocess = _srs_config->get_asprocess(); + // the deamon thread, update the time cache while (true) { if(handler && (ret = handler->on_cycle((int)conns.size())) != ERROR_SUCCESS){ @@ -962,6 +975,12 @@ int SrsServer::do_cycle() for (int i = 0; i < temp_max; i++) { st_usleep(SRS_SYS_CYCLE_INTERVAL * 1000); + // asprocess check. + if (asprocess && ::getppid() != ppid) { + srs_warn("asprocess ppid changed from %d to %d", ppid, ::getppid()); + return ret; + } + // gracefully quit for SIGINT or SIGTERM. if (signal_gracefully_quit) { srs_trace("cleanup for gracefully terminate."); diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index 532bdcb1a..8c1ecae16 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -277,6 +277,8 @@ private: bool signal_reload; bool signal_gmc_stop; bool signal_gracefully_quit; + // parent pid for asprocess. + int ppid; public: SrsServer(); virtual ~SrsServer(); diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 985fb15d3..251968158 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 217 +#define VERSION_REVISION 218 // generated by configure, only macros. #include From 07fe35f11d8ae827600eb7f6b90eca99bb801c08 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 23 Sep 2016 15:17:46 +0800 Subject: [PATCH 3/3] support asprocess for oryx. 2.0.218 --- trunk/src/app/srs_app_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 448aa467e..f3e73a04f 100755 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -488,7 +488,7 @@ SrsServer::SrsServer() signal_manager = NULL; handler = NULL; - ppid = -1; + ppid = ::getppid(); // donot new object in constructor, // for some global instance is not ready now,