winlin

fix bug of init.d script

@@ -169,7 +169,7 @@ See also: [Performance Test Guide](https://github.com/winlinvip/simple-rtmp-serv @@ -169,7 +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, support make install and uninstall. 172 +* v1.0, 2014-03-22, support make install/install-api and uninstall.
173 * v1.0, 2014-03-22, add ./etc/init.d/srs, refine to support make clean then make. 173 * v1.0, 2014-03-22, add ./etc/init.d/srs, refine to support make clean then make.
174 * v1.0, 2014-03-21, write pid to ./objs/srs.pid. 174 * v1.0, 2014-03-21, write pid to ./objs/srs.pid.
175 * v1.0, 2014-03-20, refine hls code, support pure audio HLS. 175 * v1.0, 2014-03-20, refine hls code, support pure audio HLS.
  1 +ip=`ifconfig 2>&1|grep 'inet addr'|grep -v '127.0.0.1'|awk 'NR==1 {print $2}'|awk -F ':' '{print $2}'`
  2 +if [[ -z $ip ]]; then
  3 + echo "localhost"
  4 +else
  5 + echo $ip
  6 +fi
@@ -158,7 +158,7 @@ END @@ -158,7 +158,7 @@ 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 install help clean server bandwidth librtmp librtmp-sample utest _prepare_dir 161 +.PHONY: default _default install install-api help clean server bandwidth librtmp librtmp-sample utest _prepare_dir
162 162
163 # install prefix. 163 # install prefix.
164 SRS_PREFIX=${SRS_PREFIX} 164 SRS_PREFIX=${SRS_PREFIX}
@@ -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>|<install-demo>|<uninstall>" 190 + @echo "Usage: make <help>|<clean>|<server>|<bandwidth>|<librtmp>|<librtmp-sample>|<utest>|<install>|<install-api>|<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,7 +196,7 @@ help: @@ -196,7 +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 " install-api install srs api to the prefix path"
200 @echo " uninstall uninstall srs from prefix path" 200 @echo " uninstall uninstall srs from prefix path"
201 201
202 clean: 202 clean:
@@ -216,7 +216,7 @@ uninstall: @@ -216,7 +216,7 @@ uninstall:
216 @echo "rmdir \$(SRS_PREFIX)" 216 @echo "rmdir \$(SRS_PREFIX)"
217 @rm -rf \$(SRS_PREFIX) 217 @rm -rf \$(SRS_PREFIX)
218 218
219 -install-demo: install 219 +install-api: install
220 @echo "mkdir \$(SRS_PREFIX)" 220 @echo "mkdir \$(SRS_PREFIX)"
221 @mkdir -p \$(SRS_PREFIX) 221 @mkdir -p \$(SRS_PREFIX)
222 @echo "copy binary files" 222 @echo "copy binary files"
@@ -233,6 +233,12 @@ install-demo: install @@ -233,6 +233,12 @@ install-demo: install
233 @mkdir -p \$(SRS_PREFIX)/etc/init.d 233 @mkdir -p \$(SRS_PREFIX)/etc/init.d
234 @cp etc/init.d/srs-api \$(SRS_PREFIX)/etc/init.d 234 @cp etc/init.d/srs-api \$(SRS_PREFIX)/etc/init.d
235 @sed -i "s|^ROOT=.*|ROOT=\"\$(SRS_PREFIX)\"|g" \$(SRS_PREFIX)/etc/init.d/srs-api 235 @sed -i "s|^ROOT=.*|ROOT=\"\$(SRS_PREFIX)\"|g" \$(SRS_PREFIX)/etc/init.d/srs-api
  236 + @echo ""
  237 + @echo "api installed, to link and start api:"
  238 + @echo " sudo ln -sf /usr/local/srs/etc/init.d/srs-api /etc/init.d/srs-api"
  239 + @echo " /etc/init.d/srs-api start"
  240 + @echo " http://$(shell bash auto/local_ip.sh):8085"
  241 + @echo "@see: https://github.com/winlinvip/simple-rtmp-server/wiki/LinuxService"
236 242
237 install: 243 install:
238 @echo "mkdir \$(SRS_PREFIX)" 244 @echo "mkdir \$(SRS_PREFIX)"
@@ -247,6 +253,11 @@ install: @@ -247,6 +253,11 @@ install:
247 @mkdir -p \$(SRS_PREFIX)/etc/init.d 253 @mkdir -p \$(SRS_PREFIX)/etc/init.d
248 @cp etc/init.d/srs \$(SRS_PREFIX)/etc/init.d 254 @cp etc/init.d/srs \$(SRS_PREFIX)/etc/init.d
249 @sed -i "s|^ROOT=.*|ROOT=\"\$(SRS_PREFIX)\"|g" \$(SRS_PREFIX)/etc/init.d/srs 255 @sed -i "s|^ROOT=.*|ROOT=\"\$(SRS_PREFIX)\"|g" \$(SRS_PREFIX)/etc/init.d/srs
  256 + @echo ""
  257 + @echo "srs installed, to link and start srs:"
  258 + @echo " sudo ln -sf /usr/local/srs/etc/init.d/srs /etc/init.d/srs"
  259 + @echo " /etc/init.d/srs start"
  260 + @echo "@see: https://github.com/winlinvip/simple-rtmp-server/wiki/LinuxService"
250 261
251 END 262 END
252 263
@@ -71,6 +71,15 @@ start() { @@ -71,6 +71,15 @@ start() {
71 (cd ${ROOT}; nohup ${APP} -c ${CONFIG} >/dev/null 2>&1 &) 71 (cd ${ROOT}; nohup ${APP} -c ${CONFIG} >/dev/null 2>&1 &)
72 72
73 # check again after start server 73 # check again after start server
  74 + sleep 0.5
  75 + for ((i = 0; i < 5; i++)); do
  76 + # sleep a little while, for srs may start then crash.
  77 + sleep 0.1
  78 + load_process_info
  79 + ret=$?; if [[ 0 -ne $ret ]]; then failed_msg "SRS start failed"; return $ret; fi
  80 + done
  81 +
  82 + # check whether started.
74 load_process_info 83 load_process_info
75 ret=$?; if [[ 0 -eq $? ]]; then ok_msg "SRS started(pid ${srs_pid})"; return 0; fi 84 ret=$?; if [[ 0 -eq $? ]]; then ok_msg "SRS started(pid ${srs_pid})"; return 0; fi
76 85