正在显示
2 个修改的文件
包含
145 行增加
和
1 行删除
@@ -187,7 +187,7 @@ _default: bandwidth librtmp-sample utest | @@ -187,7 +187,7 @@ _default: bandwidth librtmp-sample utest | ||
187 | @bash objs/_srs_build_summary.sh | 187 | @bash objs/_srs_build_summary.sh |
188 | 188 | ||
189 | help: | 189 | help: |
190 | - @echo "Usage: make <help>|<clean>|<server>|<bandwidth>|<librtmp>|<librtmp-sample>|<utest>|<install>|<uninstall>" | 190 | + @echo "Usage: make <help>|<clean>|<server>|<bandwidth>|<librtmp>|<librtmp-sample>|<utest>|<install>|<install-demo>|<uninstall>" |
191 | @echo " help display this help menu" | 191 | @echo " help display this help menu" |
192 | @echo " clean cleanup project" | 192 | @echo " clean cleanup project" |
193 | @echo " server build the srs(simple rtmp server) over st(state-threads)" | 193 | @echo " server build the srs(simple rtmp server) over st(state-threads)" |
@@ -196,6 +196,7 @@ help: | @@ -196,6 +196,7 @@ help: | ||
196 | @echo " librtmp-sample build the srs-librtmp sample" | 196 | @echo " librtmp-sample build the srs-librtmp sample" |
197 | @echo " utest build the utest for srs" | 197 | @echo " utest build the utest for srs" |
198 | @echo " install install srs to the prefix path" | 198 | @echo " install install srs to the prefix path" |
199 | + @echo " install-demo install srs demo to the prefix path" | ||
199 | @echo " uninstall uninstall srs from prefix path" | 200 | @echo " uninstall uninstall srs from prefix path" |
200 | 201 | ||
201 | clean: | 202 | clean: |
@@ -215,6 +216,22 @@ uninstall: | @@ -215,6 +216,22 @@ uninstall: | ||
215 | @echo "rmdir \$(SRS_PREFIX)" | 216 | @echo "rmdir \$(SRS_PREFIX)" |
216 | @rm -rf \$(SRS_PREFIX) | 217 | @rm -rf \$(SRS_PREFIX) |
217 | 218 | ||
219 | +install-demo: | ||
220 | + @echo "mkdir \$(SRS_PREFIX)" | ||
221 | + @mkdir -p \$(SRS_PREFIX) | ||
222 | + @echo "copy binary files" | ||
223 | + @mkdir -p \$(SRS_PREFIX)/research/api-server | ||
224 | + @cp research/api-server/server.py \$(SRS_PREFIX)/research/api-server | ||
225 | + @echo "copy html files" | ||
226 | + @mkdir -p \$(SRS_PREFIX)/research/api-server/static-dir/players | ||
227 | + @cp research/api-server/static-dir/crossdomain.xml \$(SRS_PREFIX)/research/api-server/static-dir | ||
228 | + @cp research/api-server/static-dir/index.html \$(SRS_PREFIX)/research/api-server/static-dir | ||
229 | + @cp -r research/api-server/static-dir/players/* \$(SRS_PREFIX)/research/api-server/static-dir/players | ||
230 | + @echo "copy init.d script files" | ||
231 | + @mkdir -p \$(SRS_PREFIX)/etc/init.d | ||
232 | + @cp etc/init.d/simple-rtmp-server-api \$(SRS_PREFIX)/etc/init.d | ||
233 | + @sed -i "s|^ROOT=.*|ROOT=\"\$(SRS_PREFIX)\"|g" \$(SRS_PREFIX)/etc/init.d/simple-rtmp-server-api | ||
234 | + | ||
218 | install: | 235 | install: |
219 | @echo "mkdir \$(SRS_PREFIX)" | 236 | @echo "mkdir \$(SRS_PREFIX)" |
220 | @mkdir -p \$(SRS_PREFIX) | 237 | @mkdir -p \$(SRS_PREFIX) |
trunk/etc/init.d/simple-rtmp-server-api
0 → 100755
1 | +#!/bin/bash | ||
2 | + | ||
3 | +### BEGIN INIT INFO | ||
4 | +# Provides: simple-rtmp-server-api(srs-api) | ||
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-api(srs-api) | ||
10 | +# Description: https://github.com/winlinvip/simple-rtmp-server | ||
11 | +### END INIT INFO | ||
12 | + | ||
13 | +# the config of ROOT, user must modify it when start srs from other directory, | ||
14 | +# it's ok to use the script by command ./etc/init.d/simple-rtmp-server | ||
15 | +ROOT="./" | ||
16 | +APP="python ./research/api-server/server.py" | ||
17 | +CONFIG="8085" | ||
18 | + | ||
19 | +######################################################################## | ||
20 | +# utility functions | ||
21 | +######################################################################## | ||
22 | +RED="\\e[31m" | ||
23 | +GREEN="\\e[32m" | ||
24 | +YELLOW="\\e[33m" | ||
25 | +BLACK="\\e[0m" | ||
26 | +POS="\\e[60G" | ||
27 | + | ||
28 | +ok_msg(){ | ||
29 | + echo -e "${1}${POS}${BLACK}[${GREEN} OK ${BLACK}]" | ||
30 | +} | ||
31 | + | ||
32 | +failed_msg(){ | ||
33 | + echo -e "${1}${POS}${BLACK}[${RED}FAILED${BLACK}]" | ||
34 | +} | ||
35 | + | ||
36 | +# load process info of srs-api | ||
37 | +# @set variable $srs_api_id to the process id. | ||
38 | +# @return 0, if process exists; otherwise: | ||
39 | +# 1, for srs-api not exists. | ||
40 | +# @set variable $error_msg if error. | ||
41 | +load_process_info() { | ||
42 | + srs_api_id=`ps aux|grep python|grep research|grep "api-server"|awk '{print $2}'` | ||
43 | + if [[ -z $srs_api_id ]]; then error_msg="srs-api process does not exists"; return 1; fi | ||
44 | + | ||
45 | + return 0; | ||
46 | +} | ||
47 | + | ||
48 | +start() { | ||
49 | + # if exists, exit. | ||
50 | + load_process_info | ||
51 | + if [[ 0 -eq $? ]]; then failed_msg "SRS-api started(pid ${srs_api_id}), should not start it again."; return 0; fi | ||
52 | + | ||
53 | + # not exists, start server | ||
54 | + ok_msg "Starting SRS-api..." | ||
55 | + # TODO: FIXME: set limit by, for instance, "ulimit -HSn 10000" | ||
56 | + # TODO: FIXME: write log to, for instance, the same dir of log. | ||
57 | + # TODO: FIXME: support deamon, without nohup. | ||
58 | + (cd ${ROOT}; nohup ${APP} ${CONFIG} >/dev/null 2>&1 &) | ||
59 | + | ||
60 | + # check again after start server | ||
61 | + load_process_info | ||
62 | + ret=$?; if [[ 0 -eq $? ]]; then ok_msg "SRS-api started(pid ${srs_api_id})"; return 0; fi | ||
63 | + | ||
64 | + failed_msg "SRS-api not started" | ||
65 | + return $ret | ||
66 | +} | ||
67 | + | ||
68 | +stop() { | ||
69 | + # not start, exit | ||
70 | + load_process_info | ||
71 | + if [[ 0 -ne $? ]]; then failed_msg "SRS-api not start."; return 0; fi | ||
72 | + | ||
73 | + ok_msg "Stopping SRS-api(pid ${srs_api_id})..." | ||
74 | + | ||
75 | + # process exists, kill util stop | ||
76 | + for((;;)); do | ||
77 | + load_process_info | ||
78 | + if [[ 0 -eq $? ]]; then | ||
79 | + kill -s SIGKILL ${srs_api_id} 2>/dev/null | ||
80 | + ret=$?; if [[ 0 -ne $ret ]]; then failed_msg "send signal SIGKILL failed ret=$ret"; return $ret; fi | ||
81 | + sleep 0.1 | ||
82 | + else | ||
83 | + ok_msg "SRS-api stopped" | ||
84 | + break; | ||
85 | + fi | ||
86 | + done | ||
87 | + | ||
88 | + sleep 0.1 | ||
89 | + return 0 | ||
90 | +} | ||
91 | + | ||
92 | +# get the status of srs-api process | ||
93 | +# @return 0 if srs-api is running; otherwise, 1 for stopped. | ||
94 | +status() { | ||
95 | + load_process_info | ||
96 | + ret=$?; if [[ 0 -eq $ret ]]; then echo "SRS-api(pid ${srs_api_id}) is running."; return 0; fi | ||
97 | + | ||
98 | + echo "SRS-api is stopped" | ||
99 | + return 1 | ||
100 | +} | ||
101 | + | ||
102 | +menu() { | ||
103 | + case "$1" in | ||
104 | + start) | ||
105 | + start | ||
106 | + ;; | ||
107 | + stop) | ||
108 | + stop | ||
109 | + ;; | ||
110 | + restart) | ||
111 | + stop | ||
112 | + start | ||
113 | + ;; | ||
114 | + status) | ||
115 | + status | ||
116 | + ;; | ||
117 | + *) | ||
118 | + echo "Usage: $0 {start|stop|status|restart}" | ||
119 | + return 1 | ||
120 | + ;; | ||
121 | + esac | ||
122 | +} | ||
123 | + | ||
124 | +menu $1 | ||
125 | + | ||
126 | +code=$? | ||
127 | +exit ${code} |
-
请 注册 或 登录 后发表评论