正在显示
4 个修改的文件
包含
85 行增加
和
33 行删除
@@ -551,5 +551,9 @@ else | @@ -551,5 +551,9 @@ else | ||
551 | echo "#undef SRS_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H | 551 | echo "#undef SRS_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H |
552 | fi | 552 | fi |
553 | 553 | ||
554 | +echo "" >> $SRS_AUTO_HEADERS_H | ||
555 | +# prefix | ||
556 | +echo "#define SRS_PREFIX \"${SRS_PREFIX}\"" >> $SRS_AUTO_HEADERS_H | ||
557 | + | ||
554 | # new empty line to auto headers file. | 558 | # new empty line to auto headers file. |
555 | echo "" >> $SRS_AUTO_HEADERS_H | 559 | echo "" >> $SRS_AUTO_HEADERS_H |
@@ -29,6 +29,7 @@ SRS_GPERF_CP=RESERVED # gperf cpu profile | @@ -29,6 +29,7 @@ SRS_GPERF_CP=RESERVED # gperf cpu profile | ||
29 | SRS_GPROF=RESERVED # gprof | 29 | SRS_GPROF=RESERVED # gprof |
30 | SRS_ARM_UBUNTU12=RESERVED # armhf(v7cpu) built on ubuntu12 | 30 | SRS_ARM_UBUNTU12=RESERVED # armhf(v7cpu) built on ubuntu12 |
31 | # arguments | 31 | # arguments |
32 | +SRS_PREFIX=/usr/local/srs | ||
32 | SRS_JOBS=1 | 33 | SRS_JOBS=1 |
33 | SRS_STATIC=RESERVED | 34 | SRS_STATIC=RESERVED |
34 | 35 | ||
@@ -85,6 +86,7 @@ do | @@ -85,6 +86,7 @@ do | ||
85 | --without-arm-ubuntu12) SRS_ARM_UBUNTU12=NO ;; | 86 | --without-arm-ubuntu12) SRS_ARM_UBUNTU12=NO ;; |
86 | 87 | ||
87 | --jobs) SRS_JOBS=${value} ;; | 88 | --jobs) SRS_JOBS=${value} ;; |
89 | + --prefix) SRS_PREFIX=${value} ;; | ||
88 | --static) SRS_STATIC=YES ;; | 90 | --static) SRS_STATIC=YES ;; |
89 | 91 | ||
90 | *) | 92 | *) |
@@ -188,6 +190,7 @@ if [ $help = yes ]; then | @@ -188,6 +190,7 @@ if [ $help = yes ]; then | ||
188 | --static whether add '-static' to link options. always set this option for arm. | 190 | --static whether add '-static' to link options. always set this option for arm. |
189 | --jobs[=N] Allow N jobs at once; infinite jobs with no arg. | 191 | --jobs[=N] Allow N jobs at once; infinite jobs with no arg. |
190 | used for make in the configure, for example, to make ffmpeg. | 192 | used for make in the configure, for example, to make ffmpeg. |
193 | + --prefix=<path> the absolute install path for srs. | ||
191 | 194 | ||
192 | END | 195 | END |
193 | exit 0 | 196 | exit 0 |
@@ -250,6 +253,7 @@ if [ $SRS_GPERF_MP = RESERVED ]; then echo "you must specifies the gperf-mp, see | @@ -250,6 +253,7 @@ if [ $SRS_GPERF_MP = RESERVED ]; then echo "you must specifies the gperf-mp, see | ||
250 | if [ $SRS_GPERF_CP = RESERVED ]; then echo "you must specifies the gperf-cp, see: ./configure --help"; __check_ok=NO; fi | 253 | if [ $SRS_GPERF_CP = RESERVED ]; then echo "you must specifies the gperf-cp, see: ./configure --help"; __check_ok=NO; fi |
251 | if [ $SRS_GPROF = RESERVED ]; then echo "you must specifies the gprof, see: ./configure --help"; __check_ok=NO; fi | 254 | if [ $SRS_GPROF = RESERVED ]; then echo "you must specifies the gprof, see: ./configure --help"; __check_ok=NO; fi |
252 | if [ $SRS_ARM_UBUNTU12 = RESERVED ]; then echo "you must specifies the arm-ubuntu12, see: ./configure --help"; __check_ok=NO; fi | 255 | if [ $SRS_ARM_UBUNTU12 = RESERVED ]; then echo "you must specifies the arm-ubuntu12, see: ./configure --help"; __check_ok=NO; fi |
256 | +if [[ -z $SRS_PREFIX ]]; then echo "you must specifies the prefix, see: ./configure --prefix"; __check_ok=NO; fi | ||
253 | if [ $__check_ok = NO ]; then | 257 | if [ $__check_ok = NO ]; then |
254 | exit 1; | 258 | exit 1; |
255 | fi | 259 | fi |
@@ -272,5 +276,5 @@ if [ $SRS_GPERF_CP = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --with-gcp"; el | @@ -272,5 +276,5 @@ if [ $SRS_GPERF_CP = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --with-gcp"; el | ||
272 | if [ $SRS_GPROF = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --with-gprof"; else SRS_CONFIGURE="${SRS_CONFIGURE} --without-gprof"; fi | 276 | if [ $SRS_GPROF = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --with-gprof"; else SRS_CONFIGURE="${SRS_CONFIGURE} --without-gprof"; fi |
273 | if [ $SRS_ARM_UBUNTU12 = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --with-arm-ubuntu12"; else SRS_CONFIGURE="${SRS_CONFIGURE} --without-arm-ubuntu12"; fi | 277 | if [ $SRS_ARM_UBUNTU12 = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --with-arm-ubuntu12"; else SRS_CONFIGURE="${SRS_CONFIGURE} --without-arm-ubuntu12"; fi |
274 | if [ $SRS_STATIC = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --static"; fi | 278 | if [ $SRS_STATIC = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --static"; fi |
275 | -SRS_CONFIGURE="${SRS_CONFIGURE} ${SRS_JOBS}" | 279 | +SRS_CONFIGURE="${SRS_CONFIGURE} ${SRS_JOBS} --prefix=${SRS_PREFIX}" |
276 | echo "regenerate config: ${SRS_CONFIGURE}" | 280 | echo "regenerate config: ${SRS_CONFIGURE}" |
@@ -158,7 +158,10 @@ END | @@ -158,7 +158,10 @@ END | ||
158 | # makefile | 158 | # makefile |
159 | echo "generate Makefile" | 159 | echo "generate Makefile" |
160 | cat << END > ${SRS_MAKEFILE} | 160 | cat << END > ${SRS_MAKEFILE} |
161 | -.PHONY: default _default help clean server bandwidth librtmp librtmp-sample utest _prepare_dir | 161 | +.PHONY: default _default install help clean server bandwidth librtmp librtmp-sample utest _prepare_dir |
162 | + | ||
163 | +# install prefix. | ||
164 | +SRS_PREFIX=${SRS_PREFIX} | ||
162 | 165 | ||
163 | END | 166 | END |
164 | 167 | ||
@@ -184,7 +187,7 @@ _default: bandwidth librtmp-sample utest | @@ -184,7 +187,7 @@ _default: bandwidth librtmp-sample utest | ||
184 | @bash objs/_srs_build_summary.sh | 187 | @bash objs/_srs_build_summary.sh |
185 | 188 | ||
186 | help: | 189 | help: |
187 | - @echo "Usage: make <help>|<clean>|<server>|<bandwidth>|<librtmp>|<librtmp-sample>|<utest>" | 190 | + @echo "Usage: make <help>|<clean>|<server>|<bandwidth>|<librtmp>|<librtmp-sample>|<utest>|<install>|<uninstall>" |
188 | @echo " help display this help menu" | 191 | @echo " help display this help menu" |
189 | @echo " clean cleanup project" | 192 | @echo " clean cleanup project" |
190 | @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)" |
@@ -192,6 +195,8 @@ help: | @@ -192,6 +195,8 @@ help: | ||
192 | @echo " librtmp build the client publish/play library." | 195 | @echo " librtmp build the client publish/play library." |
193 | @echo " librtmp-sample build the srs-librtmp sample" | 196 | @echo " librtmp-sample build the srs-librtmp sample" |
194 | @echo " utest build the utest for srs" | 197 | @echo " utest build the utest for srs" |
198 | + @echo " install install srs to the prefix path" | ||
199 | + @echo " uninstall uninstall srs from prefix path" | ||
195 | 200 | ||
196 | clean: | 201 | clean: |
197 | (cd ${SRS_OBJS}; rm -f rm -rf srs bandwidth srs_utest) | 202 | (cd ${SRS_OBJS}; rm -f rm -rf srs bandwidth srs_utest) |
@@ -204,6 +209,28 @@ server: _prepare_dir | @@ -204,6 +209,28 @@ server: _prepare_dir | ||
204 | 209 | ||
205 | END | 210 | END |
206 | 211 | ||
212 | +# install entry | ||
213 | +cat << END >> ${SRS_MAKEFILE} | ||
214 | +uninstall: | ||
215 | + @echo "rmdir \$(SRS_PREFIX)" | ||
216 | + @rm -rf \$(SRS_PREFIX) | ||
217 | + | ||
218 | +install: | ||
219 | + @echo "mkdir \$(SRS_PREFIX)" | ||
220 | + @mkdir -p \$(SRS_PREFIX) | ||
221 | + @echo "copy binary files" | ||
222 | + @mkdir -p \$(SRS_PREFIX)/objs | ||
223 | + @cp objs/srs \$(SRS_PREFIX)/objs | ||
224 | + @echo "copy srs conf files" | ||
225 | + @mkdir -p \$(SRS_PREFIX)/conf | ||
226 | + @cp conf/*.conf \$(SRS_PREFIX)/conf | ||
227 | + @echo "copy init.d script files" | ||
228 | + @mkdir -p \$(SRS_PREFIX)/etc/init.d | ||
229 | + @cp etc/init.d/simple-rtmp-server \$(SRS_PREFIX)/etc/init.d | ||
230 | + @sed -i "s|^ROOT=.*|ROOT=\"\$(SRS_PREFIX)\"|g" \$(SRS_PREFIX)/etc/init.d/simple-rtmp-server | ||
231 | + | ||
232 | +END | ||
233 | + | ||
207 | if [ $SRS_BWTC = YES ]; then | 234 | if [ $SRS_BWTC = YES ]; then |
208 | cat << END >> ${SRS_MAKEFILE} | 235 | cat << END >> ${SRS_MAKEFILE} |
209 | bandwidth: server | 236 | bandwidth: server |
@@ -10,18 +10,22 @@ | @@ -10,18 +10,22 @@ | ||
10 | # Description: https://github.com/winlinvip/simple-rtmp-server | 10 | # Description: https://github.com/winlinvip/simple-rtmp-server |
11 | ### END INIT INFO | 11 | ### END INIT INFO |
12 | 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="./objs/srs" | ||
17 | +CONFIG="./conf/srs.conf" | ||
18 | +DEFAULT_PID_FILE='./objs/srs.pid' | ||
19 | + | ||
20 | +######################################################################## | ||
21 | +# utility functions | ||
22 | +######################################################################## | ||
13 | RED="\\e[31m" | 23 | RED="\\e[31m" |
14 | GREEN="\\e[32m" | 24 | GREEN="\\e[32m" |
15 | YELLOW="\\e[33m" | 25 | YELLOW="\\e[33m" |
16 | BLACK="\\e[0m" | 26 | BLACK="\\e[0m" |
17 | POS="\\e[60G" | 27 | POS="\\e[60G" |
18 | 28 | ||
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(){ | 29 | ok_msg(){ |
26 | echo -e "${1}${POS}${BLACK}[${GREEN} OK ${BLACK}]" | 30 | echo -e "${1}${POS}${BLACK}[${GREEN} OK ${BLACK}]" |
27 | } | 31 | } |
@@ -41,7 +45,11 @@ load_process_info() { | @@ -41,7 +45,11 @@ load_process_info() { | ||
41 | srs_pid_file=`cat ${ROOT}/${CONFIG} |grep ^pid|awk '{print $2}'|awk -F ';' '{print $1}'` | 45 | 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 | 46 | if [[ -z $srs_pid_file ]]; then srs_pid_file=${DEFAULT_PID_FILE}; fi |
43 | 47 | ||
44 | - srs_pid=`cat $srs_pid_file 2>/dev/null` | 48 | + if [[ -f $srs_pid_file ]]; then |
49 | + srs_pid=`cat $srs_pid_file 2>/dev/null` | ||
50 | + else | ||
51 | + srs_pid=`cat ${ROOT}/$srs_pid_file 2>/dev/null` | ||
52 | + fi | ||
45 | ret=$?; if [[ 0 -ne $ret ]]; then error_msg="file $srs_pid_file does not exists"; return 1; fi | 53 | ret=$?; if [[ 0 -ne $ret ]]; then error_msg="file $srs_pid_file does not exists"; return 1; fi |
46 | 54 | ||
47 | ps -p ${srs_pid} >/dev/null 2>/dev/null | 55 | ps -p ${srs_pid} >/dev/null 2>/dev/null |
@@ -53,15 +61,10 @@ load_process_info() { | @@ -53,15 +61,10 @@ load_process_info() { | ||
53 | start() { | 61 | start() { |
54 | # if exists, exit. | 62 | # if exists, exit. |
55 | load_process_info | 63 | 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. | 64 | + if [[ 0 -eq $? ]]; then failed_msg "SRS started(pid ${srs_pid}), should not start it again."; return 0; fi |
62 | 65 | ||
63 | # not exists, start server | 66 | # not exists, start server |
64 | - ok_msg "Starting srs..." | 67 | + ok_msg "Starting SRS..." |
65 | # TODO: FIXME: set limit by, for instance, "ulimit -HSn 10000" | 68 | # TODO: FIXME: set limit by, for instance, "ulimit -HSn 10000" |
66 | # TODO: FIXME: write log to, for instance, the same dir of log. | 69 | # TODO: FIXME: write log to, for instance, the same dir of log. |
67 | # TODO: FIXME: support deamon, without nohup. | 70 | # TODO: FIXME: support deamon, without nohup. |
@@ -69,22 +72,18 @@ start() { | @@ -69,22 +72,18 @@ start() { | ||
69 | 72 | ||
70 | # check again after start server | 73 | # check again after start server |
71 | load_process_info | 74 | 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 | 75 | + ret=$?; if [[ 0 -eq $? ]]; then ok_msg "SRS started(pid ${srs_pid})"; return 0; fi |
76 | + | ||
77 | + failed_msg "SRS not started" | ||
78 | + return $ret | ||
77 | } | 79 | } |
78 | 80 | ||
79 | stop() { | 81 | stop() { |
80 | # not start, exit | 82 | # not start, exit |
81 | load_process_info | 83 | load_process_info |
82 | - if [[ 0 -ne $? ]]; then | ||
83 | - failed_msg "srs not start." | ||
84 | - return 0 | ||
85 | - fi | 84 | + if [[ 0 -ne $? ]]; then failed_msg "SRS not start."; return 0; fi |
86 | 85 | ||
87 | - ok_msg "Stopping srs(pid ${srs_pid})..." | 86 | + ok_msg "Stopping SRS(pid ${srs_pid})..." |
88 | 87 | ||
89 | # process exists, kill util stop | 88 | # process exists, kill util stop |
90 | for((;;)); do | 89 | for((;;)); do |
@@ -94,7 +93,7 @@ stop() { | @@ -94,7 +93,7 @@ stop() { | ||
94 | ret=$?; if [[ 0 -ne $ret ]]; then failed_msg "send signal SIGTERM failed ret=$ret"; return $ret; fi | 93 | ret=$?; if [[ 0 -ne $ret ]]; then failed_msg "send signal SIGTERM failed ret=$ret"; return $ret; fi |
95 | sleep 0.1 | 94 | sleep 0.1 |
96 | else | 95 | else |
97 | - ok_msg "srs stopped" | 96 | + ok_msg "SRS stopped" |
98 | break; | 97 | break; |
99 | fi | 98 | fi |
100 | done | 99 | done |
@@ -107,15 +106,30 @@ stop() { | @@ -107,15 +106,30 @@ stop() { | ||
107 | # @return 0 if srs is running; otherwise, 1 for stopped. | 106 | # @return 0 if srs is running; otherwise, 1 for stopped. |
108 | status() { | 107 | status() { |
109 | load_process_info | 108 | load_process_info |
110 | - ret=$?; if [[ 0 -eq $ret ]]; then | ||
111 | - echo "srs(pid ${srs_pid}) is running." | ||
112 | - return 0 | ||
113 | - fi | 109 | + ret=$?; if [[ 0 -eq $ret ]]; then echo "SRS(pid ${srs_pid}) is running."; return 0; fi |
114 | 110 | ||
115 | - echo "srs is stopped, $error_msg" | 111 | + echo "SRS is stopped, $error_msg" |
116 | return 1 | 112 | return 1 |
117 | } | 113 | } |
118 | 114 | ||
115 | +reload() { | ||
116 | + # not start, exit | ||
117 | + load_process_info | ||
118 | + if [[ 0 -ne $? ]]; then failed_msg "SRS not start."; return 0; fi | ||
119 | + | ||
120 | + ok_msg "Reload SRS(pid ${srs_pid})..." | ||
121 | + | ||
122 | + # process exists, reload it | ||
123 | + kill -s SIGHUP ${srs_pid} 2>/dev/null | ||
124 | + ret=$?; if [[ 0 -ne $ret ]]; then failed_msg "Reload SRS failed ret=$ret"; return $ret; fi | ||
125 | + | ||
126 | + load_process_info | ||
127 | + if [[ 0 -ne $? ]]; then failed_msg "SRS reload failed."; return $ret; fi | ||
128 | + | ||
129 | + ok_msg "SRS reloaded" | ||
130 | + return 0 | ||
131 | +} | ||
132 | + | ||
119 | menu() { | 133 | menu() { |
120 | case "$1" in | 134 | case "$1" in |
121 | start) | 135 | start) |
@@ -131,6 +145,9 @@ menu() { | @@ -131,6 +145,9 @@ menu() { | ||
131 | status) | 145 | status) |
132 | status | 146 | status |
133 | ;; | 147 | ;; |
148 | + reload) | ||
149 | + reload | ||
150 | + ;; | ||
134 | *) | 151 | *) |
135 | echo "Usage: $0 {start|stop|status|restart|reload}" | 152 | echo "Usage: $0 {start|stop|status|restart|reload}" |
136 | return 1 | 153 | return 1 |
-
请 注册 或 登录 后发表评论