add ./etc/init.d/srs, refine configure to support make clean then make.
正在显示
7 个修改的文件
包含
155 行增加
和
6 行删除
@@ -169,6 +169,7 @@ See also: [Performance Test Guide](https://github.com/winlinvip/simple-rtmp-serv | @@ -169,6 +169,7 @@ See also: [Performance Test Guide](https://github.com/winlinvip/simple-rtmp-serv | ||
169 | * nginx v1.5.0: 139524 lines <br/> | 169 | * nginx v1.5.0: 139524 lines <br/> |
170 | 170 | ||
171 | ## History | 171 | ## History |
172 | +* v1.0, 2014-03-22, add ./etc/init.d/srs, refine configure to support make clean then make. | ||
172 | * v1.0, 2014-03-21, write pid to ./objs/srs.pid. | 173 | * v1.0, 2014-03-21, write pid to ./objs/srs.pid. |
173 | * v1.0, 2014-03-20, refine hls code, support pure audio HLS. | 174 | * v1.0, 2014-03-20, refine hls code, support pure audio HLS. |
174 | * v1.0, 2014-03-19, add vn/an for FFMPEG to drop video/audio for radio stream. | 175 | * v1.0, 2014-03-19, add vn/an for FFMPEG to drop video/audio for radio stream. |
@@ -21,7 +21,7 @@ log_dir ./objs/logs; | @@ -21,7 +21,7 @@ log_dir ./objs/logs; | ||
21 | # the max connections. | 21 | # the max connections. |
22 | # if exceed the max connections, server will drop the new connection. | 22 | # if exceed the max connections, server will drop the new connection. |
23 | # default: 2000 | 23 | # default: 2000 |
24 | -max_connections 2000; | 24 | +max_connections 1000; |
25 | # vhost list, the __defaultVhost__ is the default vhost | 25 | # vhost list, the __defaultVhost__ is the default vhost |
26 | # for example, user use ip to access the stream: rtmp://192.168.1.2/live/livestream. | 26 | # for example, user use ip to access the stream: rtmp://192.168.1.2/live/livestream. |
27 | # for which cannot identify the required vhost. | 27 | # for which cannot identify the required vhost. |
@@ -194,8 +194,7 @@ help: | @@ -194,8 +194,7 @@ help: | ||
194 | @echo " utest build the utest for srs" | 194 | @echo " utest build the utest for srs" |
195 | 195 | ||
196 | clean: | 196 | clean: |
197 | - (rm -f Makefile) | ||
198 | - (cd ${SRS_OBJS}; rm -rf ${SRS_BUILD_SUMMARY} srs bandwidth *.hpp srs_utest) | 197 | + (cd ${SRS_OBJS}; rm -f rm -rf srs bandwidth srs_utest) |
199 | (cd ${SRS_OBJS}; rm -rf src research include lib utest) | 198 | (cd ${SRS_OBJS}; rm -rf src research include lib utest) |
200 | (cd research/librtmp; make clean) | 199 | (cd research/librtmp; make clean) |
201 | 200 |
trunk/etc/init.d/srs
0 → 100755
1 | +#!/bin/bash | ||
2 | + | ||
3 | +### BEGIN INIT INFO | ||
4 | +# Provides: simple-rtmp-server(srs) | ||
5 | +# RequiRED-Start: $all | ||
6 | +# RequiRED-Stop: $all | ||
7 | +# Default-Start: 2 3 4 5 | ||
8 | +# Default-Stop: 0 1 6 | ||
9 | +# Short-Description: simple-rtmp-server(srs) | ||
10 | +# Description: https://github.com/winlinvip/simple-rtmp-server | ||
11 | +### END INIT INFO | ||
12 | + | ||
13 | +RED="\\e[31m" | ||
14 | +GREEN="\\e[32m" | ||
15 | +YELLOW="\\e[33m" | ||
16 | +BLACK="\\e[0m" | ||
17 | +POS="\\e[60G" | ||
18 | + | ||
19 | +# the pid file is generated by install wizard | ||
20 | +ROOT="./" | ||
21 | +APP="./objs/srs" | ||
22 | +CONFIG="./conf/srs.conf" | ||
23 | +DEFAULT_PID_FILE='./objs/srs.pid' | ||
24 | + | ||
25 | +ok_msg(){ | ||
26 | + echo -e "${1}${POS}${BLACK}[${GREEN} OK ${BLACK}]" | ||
27 | +} | ||
28 | + | ||
29 | +failed_msg(){ | ||
30 | + echo -e "${1}${POS}${BLACK}[${RED}FAILED${BLACK}]" | ||
31 | +} | ||
32 | + | ||
33 | +# load process info of srs | ||
34 | +# @set variable $srs_pid to the process id in srs.pid file. | ||
35 | +# @return 0, if process exists; otherwise: | ||
36 | +# 1, for pid file not exists. | ||
37 | +# 2, for get proecess info by pid failed. | ||
38 | +# @set variable $error_msg if error. | ||
39 | +# @set variable $srs_pid_file to pid file. | ||
40 | +load_process_info() { | ||
41 | + srs_pid_file=`cat ${ROOT}/${CONFIG} |grep ^pid|awk '{print $2}'|awk -F ';' '{print $1}'` | ||
42 | + if [[ -z $srs_pid_file ]]; then srs_pid_file=${DEFAULT_PID_FILE}; fi | ||
43 | + | ||
44 | + srs_pid=`cat $srs_pid_file 2>/dev/null` | ||
45 | + ret=$?; if [[ 0 -ne $ret ]]; then error_msg="file $srs_pid_file does not exists"; return 1; fi | ||
46 | + | ||
47 | + ps -p ${srs_pid} >/dev/null 2>/dev/null | ||
48 | + ret=$?; if [[ 0 -ne $ret ]]; then error_msg="process $srs_pid does not exists"; return 2; fi | ||
49 | + | ||
50 | + return 0; | ||
51 | +} | ||
52 | + | ||
53 | +start() { | ||
54 | + # if exists, exit. | ||
55 | + load_process_info | ||
56 | + if [[ 0 -eq $? ]]; then | ||
57 | + failed_msg "srs started(pid ${srs_pid}), should not start it again." | ||
58 | + return 0 | ||
59 | + fi | ||
60 | + | ||
61 | + # try to get log dir. | ||
62 | + | ||
63 | + # not exists, start server | ||
64 | + ok_msg "Starting srs..." | ||
65 | + # TODO: FIXME: set limit by, for instance, "ulimit -HSn 10000" | ||
66 | + # TODO: FIXME: write log to, for instance, the same dir of log. | ||
67 | + # TODO: FIXME: support deamon, without nohup. | ||
68 | + (cd ${ROOT}; nohup ${APP} -c ${CONFIG} >/dev/null 2>&1 &) | ||
69 | + | ||
70 | + # check again after start server | ||
71 | + load_process_info | ||
72 | + if [[ 0 -eq $? ]]; then | ||
73 | + ok_msg "srs started(pid ${srs_pid})" | ||
74 | + else | ||
75 | + failed_msg "srs not started" | ||
76 | + fi | ||
77 | +} | ||
78 | + | ||
79 | +stop() { | ||
80 | + # not start, exit | ||
81 | + load_process_info | ||
82 | + if [[ 0 -ne $? ]]; then | ||
83 | + failed_msg "srs not start." | ||
84 | + return 0 | ||
85 | + fi | ||
86 | + | ||
87 | + ok_msg "Stopping srs(pid ${srs_pid})..." | ||
88 | + | ||
89 | + # process exists, kill util stop | ||
90 | + for((;;)); do | ||
91 | + load_process_info | ||
92 | + if [[ 0 -eq $? ]]; then | ||
93 | + kill -s SIGTERM ${srs_pid} 2>/dev/null | ||
94 | + ret=$?; if [[ 0 -ne $ret ]]; then failed_msg "send signal SIGTERM failed ret=$ret"; return $ret; fi | ||
95 | + sleep 0.1 | ||
96 | + else | ||
97 | + ok_msg "srs stopped" | ||
98 | + break; | ||
99 | + fi | ||
100 | + done | ||
101 | + | ||
102 | + sleep 0.1 | ||
103 | + return 0 | ||
104 | +} | ||
105 | + | ||
106 | +# get the status of srs process | ||
107 | +# @return 0 if srs is running; otherwise, 1 for stopped. | ||
108 | +status() { | ||
109 | + load_process_info | ||
110 | + ret=$?; if [[ 0 -eq $ret ]]; then | ||
111 | + echo "srs(pid ${srs_pid}) is running." | ||
112 | + return 0 | ||
113 | + fi | ||
114 | + | ||
115 | + echo "srs is stopped, $error_msg" | ||
116 | + return 1 | ||
117 | +} | ||
118 | + | ||
119 | +menu() { | ||
120 | + case "$1" in | ||
121 | + start) | ||
122 | + start | ||
123 | + ;; | ||
124 | + stop) | ||
125 | + stop | ||
126 | + ;; | ||
127 | + restart) | ||
128 | + stop | ||
129 | + start | ||
130 | + ;; | ||
131 | + status) | ||
132 | + status | ||
133 | + ;; | ||
134 | + *) | ||
135 | + echo "Usage: $0 {start|stop|status|restart|reload}" | ||
136 | + return 1 | ||
137 | + ;; | ||
138 | + esac | ||
139 | +} | ||
140 | + | ||
141 | +menu $1 | ||
142 | + | ||
143 | +code=$? | ||
144 | +exit ${code} |
@@ -370,8 +370,12 @@ void SrsServer::on_signal(int signo) | @@ -370,8 +370,12 @@ void SrsServer::on_signal(int signo) | ||
370 | #endif | 370 | #endif |
371 | return; | 371 | return; |
372 | } | 372 | } |
373 | - | ||
374 | - // TODO: handle the SIGINT, SIGTERM. | 373 | + |
374 | + if (signo == SIGTERM) { | ||
375 | + srs_trace("user terminate program"); | ||
376 | + exit(0); | ||
377 | + return; | ||
378 | + } | ||
375 | } | 379 | } |
376 | 380 | ||
377 | void SrsServer::close_listeners() | 381 | void SrsServer::close_listeners() |
@@ -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 "0" | 32 | #define VERSION_MAJOR "0" |
33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
34 | -#define VERSION_REVISION "24" | 34 | +#define VERSION_REVISION "25" |
35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
36 | // server info. | 36 | // server info. |
37 | #define RTMP_SIG_SRS_KEY "srs" | 37 | #define RTMP_SIG_SRS_KEY "srs" |
@@ -65,6 +65,7 @@ int main(int argc, char** argv) | @@ -65,6 +65,7 @@ int main(int argc, char** argv) | ||
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | signal(SIGNAL_RELOAD, handler); | 67 | signal(SIGNAL_RELOAD, handler); |
68 | + signal(SIGTERM, handler); | ||
68 | signal(SIGINT, handler); | 69 | signal(SIGINT, handler); |
69 | 70 | ||
70 | if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { | 71 | if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { |
-
请 注册 或 登录 后发表评论