winlin

merge srs2, support oryx

@@ -55,6 +55,19 @@ utc_time off; @@ -55,6 +55,19 @@ utc_time off;
55 # default: 10000 55 # default: 10000
56 pithy_print_ms 10000; 56 pithy_print_ms 10000;
57 57
  58 +# the work dir for server, to chdir(work_dir) when not empty or "./"
  59 +# user can config this directory to change the dir.
  60 +# @reamrk do not support reload.
  61 +# default: ./
  62 +work_dir ./;
  63 +# whether quit when parent process changed,
  64 +# used for supervisor mode(not daemon), srs should always quit when
  65 +# supervisor process exited.
  66 +# @remark conflict with daemon, error when both daemon and asprocess are on.
  67 +# @reamrk do not support reload.
  68 +# default: off
  69 +asprocess off;
  70 +
58 ############################################################################################# 71 #############################################################################################
59 # heartbeat/stats sections 72 # heartbeat/stats sections
60 ############################################################################################# 73 #############################################################################################
@@ -3536,7 +3536,7 @@ int SrsConfig::check_config() @@ -3536,7 +3536,7 @@ int SrsConfig::check_config()
3536 && n != "max_connections" && n != "daemon" && n != "heartbeat" 3536 && n != "max_connections" && n != "daemon" && n != "heartbeat"
3537 && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms" 3537 && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
3538 && n != "http_server" && n != "stream_caster" && n != "kafka" 3538 && n != "http_server" && n != "stream_caster" && n != "kafka"
3539 - && n != "utc_time" && n != "work_dir" 3539 + && n != "utc_time" && n != "work_dir" && n != "asprocess"
3540 ) { 3540 ) {
3541 ret = ERROR_SYSTEM_CONFIG_INVALID; 3541 ret = ERROR_SYSTEM_CONFIG_INVALID;
3542 srs_error("unsupported directive %s, ret=%d", n.c_str(), ret); 3542 srs_error("unsupported directive %s, ret=%d", n.c_str(), ret);
@@ -4065,6 +4065,13 @@ int SrsConfig::check_config() @@ -4065,6 +4065,13 @@ int SrsConfig::check_config()
4065 // TODO: FIXME: required http server when hls storage is ram or both. 4065 // TODO: FIXME: required http server when hls storage is ram or both.
4066 } 4066 }
4067 4067
  4068 + // asprocess conflict with daemon
  4069 + if (get_asprocess() && get_deamon()) {
  4070 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  4071 + srs_error("daemon conflict with asprocess, ret=%d", ret);
  4072 + return ret;
  4073 + }
  4074 +
4068 return ret; 4075 return ret;
4069 } 4076 }
4070 4077
@@ -4195,6 +4202,20 @@ string SrsConfig::get_work_dir() { @@ -4195,6 +4202,20 @@ string SrsConfig::get_work_dir() {
4195 } 4202 }
4196 4203
4197 return conf->arg0(); 4204 return conf->arg0();
  4205 +
  4206 + return conf->arg0();
  4207 +}
  4208 +
  4209 +bool SrsConfig::get_asprocess()
  4210 +{
  4211 + static bool DEFAULT = false;
  4212 +
  4213 + SrsConfDirective* conf = root->get("asprocess");
  4214 + if (!conf || conf->arg0().empty()) {
  4215 + return DEFAULT;
  4216 + }
  4217 +
  4218 + return SRS_CONF_PERFER_FALSE(conf->arg0());
4198 } 4219 }
4199 4220
4200 vector<SrsConfDirective*> SrsConfig::get_stream_casters() 4221 vector<SrsConfDirective*> SrsConfig::get_stream_casters()
@@ -618,6 +618,8 @@ public: @@ -618,6 +618,8 @@ public:
618 * ignore if empty string. 618 * ignore if empty string.
619 */ 619 */
620 virtual std::string get_work_dir(); 620 virtual std::string get_work_dir();
  621 + // whether use asprocess mode.
  622 + virtual bool get_asprocess();
621 // stream_caster section 623 // stream_caster section
622 public: 624 public:
623 /** 625 /**
@@ -494,6 +494,7 @@ SrsServer::SrsServer() @@ -494,6 +494,7 @@ SrsServer::SrsServer()
494 signal_manager = NULL; 494 signal_manager = NULL;
495 495
496 handler = NULL; 496 handler = NULL;
  497 + ppid = ::getppid();
497 498
498 // donot new object in constructor, 499 // donot new object in constructor,
499 // for some global instance is not ready now, 500 // for some global instance is not ready now,
@@ -653,7 +654,16 @@ int SrsServer::initialize_st() @@ -653,7 +654,16 @@ int SrsServer::initialize_st()
653 654
654 // set current log id. 655 // set current log id.
655 _srs_context->generate_id(); 656 _srs_context->generate_id();
656 - srs_trace("server main cid=%d", _srs_context->get_id()); 657 +
  658 + // check asprocess.
  659 + bool asprocess = _srs_config->get_asprocess();
  660 + if (ppid == 1) {
  661 + ret = ERROR_SYSTEM_ASSERT_FAILED;
  662 + srs_error("for asprocess, ppid should never be init(1), ret=%d", ret);
  663 + return ret;
  664 + }
  665 + srs_trace("server main cid=%d, pid=%d, ppid=%d, asprocess=%d",
  666 + _srs_context->get_id(), ::getpid(), ppid, asprocess);
657 667
658 return ret; 668 return ret;
659 } 669 }
@@ -964,6 +974,9 @@ int SrsServer::do_cycle() @@ -964,6 +974,9 @@ int SrsServer::do_cycle()
964 max = srs_max(max, SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES); 974 max = srs_max(max, SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES);
965 #endif 975 #endif
966 976
  977 + // for asprocess.
  978 + bool asprocess = _srs_config->get_asprocess();
  979 +
967 // the deamon thread, update the time cache 980 // the deamon thread, update the time cache
968 // TODO: FIXME: use SrsHourGlass. 981 // TODO: FIXME: use SrsHourGlass.
969 while (true) { 982 while (true) {
@@ -981,7 +994,13 @@ int SrsServer::do_cycle() @@ -981,7 +994,13 @@ int SrsServer::do_cycle()
981 for (int i = 0; i < dynamic_max; i++) { 994 for (int i = 0; i < dynamic_max; i++) {
982 st_usleep(SRS_SYS_CYCLE_INTERVAL * 1000); 995 st_usleep(SRS_SYS_CYCLE_INTERVAL * 1000);
983 996
984 - // gracefully quit for SIGINT or SIGTERM(SRS_SIGNAL_GRACEFULLY_QUIT). 997 + // asprocess check.
  998 + if (asprocess && ::getppid() != ppid) {
  999 + srs_warn("asprocess ppid changed from %d to %d", ppid, ::getppid());
  1000 + return ret;
  1001 + }
  1002 +
  1003 + // gracefully quit for SIGINT or SIGTERM.
985 if (signal_gracefully_quit) { 1004 if (signal_gracefully_quit) {
986 srs_trace("cleanup for gracefully terminate."); 1005 srs_trace("cleanup for gracefully terminate.");
987 return ret; 1006 return ret;
@@ -288,6 +288,8 @@ private: @@ -288,6 +288,8 @@ private:
288 bool signal_persistence_config; 288 bool signal_persistence_config;
289 bool signal_gmc_stop; 289 bool signal_gmc_stop;
290 bool signal_gracefully_quit; 290 bool signal_gracefully_quit;
  291 + // parent pid for asprocess.
  292 + int ppid;
291 public: 293 public:
292 SrsServer(); 294 SrsServer();
293 virtual ~SrsServer(); 295 virtual ~SrsServer();
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR 3 32 #define VERSION_MAJOR 3
33 #define VERSION_MINOR 0 33 #define VERSION_MINOR 0
34 -#define VERSION_REVISION 217 34 +#define VERSION_REVISION 218
35 35
36 // generated by configure, only macros. 36 // generated by configure, only macros.
37 #include <srs_auto_headers.hpp> 37 #include <srs_auto_headers.hpp>
@@ -264,7 +264,7 @@ int main(int argc, char** argv) @@ -264,7 +264,7 @@ int main(int argc, char** argv)
264 264
265 // change the work dir and set cwd. 265 // change the work dir and set cwd.
266 string cwd = _srs_config->get_work_dir(); 266 string cwd = _srs_config->get_work_dir();
267 - if (!cwd.empty() && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) { 267 + if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) {
268 srs_error("change cwd to %s failed. ret=%d", cwd.c_str(), ret); 268 srs_error("change cwd to %s failed. ret=%d", cwd.c_str(), ret);
269 return ret; 269 return ret;
270 } 270 }