2013-11-23 03:36:07 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2015-04-29 09:38:23 +00:00
|
|
|
Copyright (c) 2013-2015 SRS(simple-rtmp-server)
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-04-10 06:12:22 +00:00
|
|
|
#include <srs_core.hpp>
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2014-03-23 04:42:05 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2014-04-15 06:01:57 +00:00
|
|
|
#ifdef SRS_AUTO_GPERF_MP
|
2014-03-18 03:32:58 +00:00
|
|
|
#include <gperftools/heap-profiler.h>
|
2014-03-06 10:12:19 +00:00
|
|
|
#endif
|
2014-04-15 06:01:57 +00:00
|
|
|
#ifdef SRS_AUTO_GPERF_CP
|
2014-03-18 03:32:58 +00:00
|
|
|
#include <gperftools/profiler.h>
|
2014-03-06 10:12:19 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-10 06:12:22 +00:00
|
|
|
#include <srs_kernel_error.hpp>
|
|
|
|
#include <srs_app_server.hpp>
|
|
|
|
#include <srs_app_config.hpp>
|
|
|
|
#include <srs_app_log.hpp>
|
2014-06-08 05:03:03 +00:00
|
|
|
#include <srs_kernel_utility.hpp>
|
2014-12-04 13:35:13 +00:00
|
|
|
#include <srs_core_performance.hpp>
|
2014-04-10 06:12:22 +00:00
|
|
|
|
2014-04-12 12:37:16 +00:00
|
|
|
// pre-declare
|
|
|
|
int run();
|
|
|
|
int run_master();
|
|
|
|
|
|
|
|
// for the main objects(server, config, log, context),
|
|
|
|
// never subscribe handler in constructor,
|
|
|
|
// instead, subscribe handler in initialize method.
|
2014-04-10 06:12:22 +00:00
|
|
|
// kernel module.
|
|
|
|
ISrsLog* _srs_log = new SrsFastLog();
|
|
|
|
ISrsThreadContext* _srs_context = new SrsThreadContext();
|
|
|
|
// app module.
|
|
|
|
SrsConfig* _srs_config = new SrsConfig();
|
|
|
|
SrsServer* _srs_server = new SrsServer();
|
|
|
|
|
2014-09-26 03:05:45 +00:00
|
|
|
/**
|
|
|
|
* show the features by macro, the actual macro values.
|
|
|
|
*/
|
|
|
|
void show_macro_features()
|
2014-09-23 08:53:12 +00:00
|
|
|
{
|
|
|
|
#ifdef SRS_AUTO_SSL
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature rtmp handshake: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature rtmp handshake: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SRS_AUTO_HLS
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature hls: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature hls: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-12 03:15:15 +00:00
|
|
|
#ifdef SRS_AUTO_HDS
|
|
|
|
srs_trace("check feature hds: on");
|
|
|
|
#else
|
|
|
|
srs_warn("check feature hds: off");
|
|
|
|
#endif
|
|
|
|
|
2014-09-23 08:53:12 +00:00
|
|
|
#ifdef SRS_AUTO_HTTP_CALLBACK
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature http callback: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature http callback: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SRS_AUTO_HTTP_API
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature http api: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature http api: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SRS_AUTO_HTTP_SERVER
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature http server: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature http server: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-27 02:23:40 +00:00
|
|
|
#ifdef SRS_AUTO_HTTP_CORE
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature http parser: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature http parser: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SRS_AUTO_DVR
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature dvr: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature dvr: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SRS_AUTO_TRANSCODE
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature transcode: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature transcode: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SRS_AUTO_INGEST
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature ingest: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature ingest: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SRS_AUTO_STAT
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature system stat: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature system stat: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SRS_AUTO_NGINX
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature compile nginx: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature compile nginx: off");
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
2014-10-09 02:41:24 +00:00
|
|
|
#ifdef SRS_AUTO_FFMPEG_TOOL
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_trace("check feature compile ffmpeg: on");
|
2014-09-23 08:53:12 +00:00
|
|
|
#else
|
2014-11-06 06:23:08 +00:00
|
|
|
srs_warn("check feature compile ffmpeg: off");
|
|
|
|
#endif
|
2014-12-04 13:35:13 +00:00
|
|
|
|
2015-02-15 13:28:31 +00:00
|
|
|
#ifdef SRS_AUTO_STREAM_CASTER
|
|
|
|
srs_trace("stream caster: on");
|
|
|
|
#else
|
|
|
|
srs_warn("stream caster: off");
|
|
|
|
#endif
|
|
|
|
|
2014-12-04 13:35:13 +00:00
|
|
|
#ifdef SRS_PERF_MERGED_READ
|
|
|
|
srs_trace("MR(merged-read): on, @see %s", RTMP_SIG_SRS_ISSUES(241));
|
|
|
|
#else
|
|
|
|
srs_warn("MR(merged-read): off, @see %s", RTMP_SIG_SRS_ISSUES(241));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
srs_trace("MR(merged-read) default %d sleep %d", SRS_PERF_MR_ENABLED, SRS_PERF_MR_SLEEP);
|
|
|
|
srs_trace("MW(merged-write) default sleep %d", SRS_PERF_MW_SLEEP);
|
|
|
|
srs_trace("read chunk stream cache cid [0, %d)", SRS_PERF_CHUNK_STREAM_CACHE);
|
|
|
|
srs_trace("default gop cache %d, play queue %ds", SRS_PERF_GOP_CACHE, SRS_PERF_PLAY_QUEUE);
|
2015-03-04 08:52:43 +00:00
|
|
|
|
|
|
|
#ifndef SRS_PERF_COMPLEX_SEND
|
|
|
|
srs_warn("complex send algorithm disabled.");
|
|
|
|
#else
|
|
|
|
srs_trace("complex send algorithm enabled.");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SRS_PERF_TCP_NODELAY
|
2015-08-22 01:49:38 +00:00
|
|
|
srs_warn("TCP_NODELAY enabled, may hurts performance.");
|
2015-03-04 08:52:43 +00:00
|
|
|
#else
|
|
|
|
srs_trace("TCP_NODELAY disabled.");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SRS_PERF_SO_SNDBUF_SIZE
|
|
|
|
srs_warn("socket send buffer size %d", SRS_PERF_SO_SNDBUF_SIZE);
|
|
|
|
#else
|
|
|
|
srs_trace("auto guess socket send buffer by merged write");
|
|
|
|
#endif
|
2014-12-04 13:35:13 +00:00
|
|
|
|
|
|
|
int possible_mr_latency = 0;
|
|
|
|
#ifdef SRS_PERF_MERGED_READ
|
|
|
|
possible_mr_latency = SRS_PERF_MR_SLEEP;
|
|
|
|
#endif
|
|
|
|
srs_trace("system default latency in ms: mw(0-%d) + mr(0-%d) + play-queue(0-%d)",
|
|
|
|
SRS_PERF_MW_SLEEP, possible_mr_latency, SRS_PERF_PLAY_QUEUE*1000);
|
2014-11-06 06:23:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void check_macro_features()
|
|
|
|
{
|
2015-03-10 04:50:27 +00:00
|
|
|
// important preset.
|
|
|
|
#ifdef SRS_OSX
|
|
|
|
srs_trace("SRS for OSX");
|
|
|
|
#endif
|
|
|
|
#ifdef SRS_PI
|
|
|
|
srs_trace("SRS for pi");
|
|
|
|
#endif
|
|
|
|
#ifdef SRS_CUBIE
|
|
|
|
srs_trace("SRS for cubieboard");
|
|
|
|
#endif
|
|
|
|
#ifdef SRS_ARM_UBUNTU12
|
|
|
|
srs_trace("SRS for arm(build on ubuntu)");
|
|
|
|
#endif
|
|
|
|
#ifdef SRS_MIPS_UBUNTU12
|
|
|
|
srs_trace("SRS for mips(build on ubuntu)");
|
|
|
|
#endif
|
|
|
|
|
2014-11-06 06:23:08 +00:00
|
|
|
// for special features.
|
2014-12-04 13:35:13 +00:00
|
|
|
#ifndef SRS_PERF_MERGED_READ
|
|
|
|
srs_warn("MR(merged-read) is disabled, hurts read performance. @see %s", RTMP_SIG_SRS_ISSUES(241));
|
|
|
|
#endif
|
|
|
|
|
2014-12-06 11:56:06 +00:00
|
|
|
srs_trace("writev limits write %d iovs a time", sysconf(_SC_IOV_MAX));
|
|
|
|
|
2015-03-15 00:15:04 +00:00
|
|
|
#if VERSION_MAJOR > VERSION_STABLE
|
|
|
|
#warning "current branch is not stable, please use stable branch instead."
|
|
|
|
srs_warn("SRS %s is not stable, please use stable branch %s instead", RTMP_SIG_SRS_VERSION, VERSION_STABLE_BRANCH);
|
2014-09-23 08:53:12 +00:00
|
|
|
#endif
|
2015-06-08 01:47:45 +00:00
|
|
|
|
2015-06-13 07:45:25 +00:00
|
|
|
#ifdef SRS_AUTO_MEM_WATCH
|
2015-06-08 01:47:45 +00:00
|
|
|
#warning "srs memory watcher will hurts performance. user should kill by SIGTERM or init.d script."
|
|
|
|
srs_warn("srs memory watcher will hurts performance. user should kill by SIGTERM or init.d script.");
|
|
|
|
#endif
|
2015-03-04 08:52:43 +00:00
|
|
|
|
2015-03-10 10:07:43 +00:00
|
|
|
#if defined(SRS_AUTO_STREAM_CASTER)
|
|
|
|
#warning "stream caster is experiment feature."
|
|
|
|
srs_warn("stream caster is experiment feature.");
|
|
|
|
#endif
|
|
|
|
|
2015-03-04 08:52:43 +00:00
|
|
|
#if defined(SRS_PERF_SO_SNDBUF_SIZE) && !defined(SRS_PERF_MW_SO_SNDBUF)
|
|
|
|
#error "SRS_PERF_SO_SNDBUF_SIZE depends on SRS_PERF_MW_SO_SNDBUF"
|
|
|
|
#endif
|
2015-09-23 07:46:51 +00:00
|
|
|
|
|
|
|
#ifndef SRS_OSX
|
|
|
|
#if defined(__amd64__)
|
|
|
|
srs_trace("cpu is amd64, glibc %d.%d", (int)__GLIBC__, (int)__GLIBC_MINOR__);
|
|
|
|
#endif
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
srs_trace("cpu is x86_64, glibc %d.%d", (int)__GLIBC__, (int)__GLIBC_MINOR__);
|
|
|
|
#endif
|
|
|
|
#if defined(__i386__)
|
|
|
|
srs_trace("cpu is i386, glibc %d.%d", (int)__GLIBC__, (int)__GLIBC_MINOR__);
|
|
|
|
#endif
|
|
|
|
#if defined(__arm__)
|
|
|
|
srs_trace("cpu is arm, glibc %d.%d", (int)__GLIBC__, (int)__GLIBC_MINOR__);
|
|
|
|
#endif
|
|
|
|
#endif
|
2014-09-23 08:53:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 03:05:45 +00:00
|
|
|
/**
|
|
|
|
* main entrance.
|
|
|
|
*/
|
2014-04-12 12:35:40 +00:00
|
|
|
int main(int argc, char** argv)
|
2014-03-01 10:27:55 +00:00
|
|
|
{
|
2014-03-18 03:32:58 +00:00
|
|
|
int ret = ERROR_SUCCESS;
|
2014-09-26 03:05:45 +00:00
|
|
|
|
2014-04-12 12:35:40 +00:00
|
|
|
// TODO: support both little and big endian.
|
|
|
|
srs_assert(srs_is_little_endian());
|
|
|
|
|
2014-11-27 09:47:13 +00:00
|
|
|
// for gperf gmp or gcp,
|
|
|
|
// should never enable it when not enabled for performance issue.
|
2014-04-15 06:01:57 +00:00
|
|
|
#ifdef SRS_AUTO_GPERF_MP
|
2014-04-12 12:35:40 +00:00
|
|
|
HeapProfilerStart("gperf.srs.gmp");
|
|
|
|
#endif
|
2014-04-15 06:01:57 +00:00
|
|
|
#ifdef SRS_AUTO_GPERF_CP
|
2014-04-12 12:35:40 +00:00
|
|
|
ProfilerStart("gperf.srs.gcp");
|
|
|
|
#endif
|
|
|
|
|
2014-11-27 10:48:01 +00:00
|
|
|
// directly compile error when these two macro defines.
|
2014-11-06 06:23:08 +00:00
|
|
|
#if defined(SRS_AUTO_GPERF_MC) && defined(SRS_AUTO_GPERF_MP)
|
2014-11-27 10:48:01 +00:00
|
|
|
#error ("option --with-gmc confict with --with-gmp, "
|
2014-04-12 12:35:40 +00:00
|
|
|
"@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n"
|
|
|
|
"Note that since the heap-checker uses the heap-profiling framework internally, "
|
|
|
|
"it is not possible to run both the heap-checker and heap profiler at the same time");
|
|
|
|
#endif
|
2014-03-23 06:51:35 +00:00
|
|
|
|
2015-06-09 02:52:32 +00:00
|
|
|
// never use gmp to check memory leak.
|
|
|
|
#ifdef SRS_AUTO_GPERF_MP
|
|
|
|
#warning "gmp is not used for memory leak, please use gmc instead."
|
|
|
|
#endif
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2014-04-12 12:35:40 +00:00
|
|
|
// never use srs log(srs_trace, srs_error, etc) before config parse the option,
|
|
|
|
// which will load the log config and apply it.
|
|
|
|
if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
|
2014-03-21 07:45:34 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-12 12:35:40 +00:00
|
|
|
// config parsed, initialize log.
|
|
|
|
if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) {
|
2014-03-18 03:32:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2014-09-26 09:47:43 +00:00
|
|
|
|
|
|
|
// we check the config when the log initialized.
|
|
|
|
if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) {
|
|
|
|
return ret;
|
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2014-04-12 12:35:40 +00:00
|
|
|
srs_trace("srs(simple-rtmp-server) "RTMP_SIG_SRS_VERSION);
|
2015-08-22 01:49:38 +00:00
|
|
|
srs_trace("license: "RTMP_SIG_SRS_LICENSE", "RTMP_SIG_SRS_COPYRIGHT);
|
|
|
|
srs_trace("primary/master: "RTMP_SIG_SRS_PRIMARY);
|
2014-11-25 02:41:55 +00:00
|
|
|
srs_trace("authors: "RTMP_SIG_SRS_AUTHROS);
|
2014-09-23 08:53:12 +00:00
|
|
|
srs_trace("contributors: "SRS_AUTO_CONSTRIBUTORS);
|
2014-04-15 06:01:57 +00:00
|
|
|
srs_trace("uname: "SRS_AUTO_UNAME);
|
|
|
|
srs_trace("build: %s, %s", SRS_AUTO_BUILD_DATE, srs_is_little_endian()? "little-endian":"big-endian");
|
2014-04-16 07:04:38 +00:00
|
|
|
srs_trace("configure: "SRS_AUTO_USER_CONFIGURE);
|
|
|
|
srs_trace("features: "SRS_AUTO_CONFIGURE);
|
2014-04-15 06:01:57 +00:00
|
|
|
#ifdef SRS_AUTO_ARM_UBUNTU12
|
2014-05-04 10:38:08 +00:00
|
|
|
srs_trace("arm tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN);
|
2014-04-12 12:35:40 +00:00
|
|
|
#endif
|
2014-08-29 07:07:04 +00:00
|
|
|
srs_trace("conf: %s, limit: %d", _srs_config->config().c_str(), _srs_config->get_max_connections());
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2014-09-23 08:53:12 +00:00
|
|
|
// features
|
2014-11-06 06:23:08 +00:00
|
|
|
check_macro_features();
|
2015-03-10 04:50:27 +00:00
|
|
|
show_macro_features();
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2014-08-05 01:16:25 +00:00
|
|
|
/**
|
|
|
|
* we do nothing in the constructor of server,
|
|
|
|
* and use initialize to create members, set hooks for instance the reload handler,
|
|
|
|
* all initialize will done in this stage.
|
|
|
|
*/
|
2015-03-31 10:06:55 +00:00
|
|
|
if ((ret = _srs_server->initialize(NULL)) != ERROR_SUCCESS) {
|
2014-03-18 03:32:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-12 12:35:40 +00:00
|
|
|
return run();
|
2013-11-23 03:36:07 +00:00
|
|
|
}
|
2014-03-23 04:42:05 +00:00
|
|
|
|
2014-04-12 12:35:40 +00:00
|
|
|
int run()
|
2014-03-23 04:42:05 +00:00
|
|
|
{
|
|
|
|
// if not deamon, directly run master.
|
|
|
|
if (!_srs_config->get_deamon()) {
|
|
|
|
return run_master();
|
|
|
|
}
|
|
|
|
|
|
|
|
srs_trace("start deamon mode...");
|
|
|
|
|
|
|
|
int pid = fork();
|
|
|
|
|
2014-04-16 07:04:38 +00:00
|
|
|
if(pid < 0) {
|
2014-03-23 04:42:05 +00:00
|
|
|
srs_error("create process error. ret=-1"); //ret=0
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// grandpa
|
2014-04-10 06:22:09 +00:00
|
|
|
if(pid > 0) {
|
2014-03-23 04:42:05 +00:00
|
|
|
int status = 0;
|
2014-04-10 06:22:09 +00:00
|
|
|
if(waitpid(pid, &status, 0) == -1) {
|
2014-03-23 04:42:05 +00:00
|
|
|
srs_error("wait child process error! ret=-1"); //ret=0
|
|
|
|
}
|
|
|
|
srs_trace("grandpa process exit.");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// father
|
|
|
|
pid = fork();
|
|
|
|
|
2014-04-16 07:04:38 +00:00
|
|
|
if(pid < 0) {
|
|
|
|
srs_error("create process error. ret=0");
|
2014-03-23 04:42:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-04-10 06:22:09 +00:00
|
|
|
if(pid > 0) {
|
2014-04-16 07:04:38 +00:00
|
|
|
srs_trace("father process exit. ret=0");
|
2014-03-23 04:42:05 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// son
|
|
|
|
srs_trace("son(deamon) process running.");
|
|
|
|
|
|
|
|
return run_master();
|
|
|
|
}
|
|
|
|
|
2014-04-12 12:35:40 +00:00
|
|
|
int run_master()
|
2014-03-23 04:42:05 +00:00
|
|
|
{
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
2015-05-19 10:06:20 +00:00
|
|
|
if ((ret = _srs_server->initialize_st()) != ERROR_SUCCESS) {
|
2014-04-30 03:26:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2015-05-19 10:06:20 +00:00
|
|
|
if ((ret = _srs_server->initialize_signal()) != ERROR_SUCCESS) {
|
2014-03-23 04:42:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2014-03-25 03:04:36 +00:00
|
|
|
|
2015-05-19 10:06:20 +00:00
|
|
|
if ((ret = _srs_server->acquire_pid_file()) != ERROR_SUCCESS) {
|
2014-04-12 12:35:40 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2014-04-03 10:32:51 +00:00
|
|
|
|
2014-04-12 12:35:40 +00:00
|
|
|
if ((ret = _srs_server->listen()) != ERROR_SUCCESS) {
|
|
|
|
return ret;
|
|
|
|
}
|
2014-03-23 06:40:55 +00:00
|
|
|
|
2014-04-30 03:26:32 +00:00
|
|
|
if ((ret = _srs_server->register_signal()) != ERROR_SUCCESS) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-07 14:25:43 +00:00
|
|
|
if ((ret = _srs_server->http_handle()) != ERROR_SUCCESS) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-12 12:35:40 +00:00
|
|
|
if ((ret = _srs_server->ingest()) != ERROR_SUCCESS) {
|
2014-03-23 06:40:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-22 09:40:05 +00:00
|
|
|
if ((ret = _srs_server->start_kafka()) != ERROR_SUCCESS) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-12 12:35:40 +00:00
|
|
|
if ((ret = _srs_server->cycle()) != ERROR_SUCCESS) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-03-23 04:42:05 +00:00
|
|
|
}
|
2014-08-02 14:18:39 +00:00
|
|
|
|