winlin

add reload support. add make install and uninstall

... ... @@ -551,5 +551,9 @@ else
echo "#undef SRS_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H
fi
echo "" >> $SRS_AUTO_HEADERS_H
# prefix
echo "#define SRS_PREFIX \"${SRS_PREFIX}\"" >> $SRS_AUTO_HEADERS_H
# new empty line to auto headers file.
echo "" >> $SRS_AUTO_HEADERS_H
... ...
... ... @@ -29,6 +29,7 @@ SRS_GPERF_CP=RESERVED # gperf cpu profile
SRS_GPROF=RESERVED # gprof
SRS_ARM_UBUNTU12=RESERVED # armhf(v7cpu) built on ubuntu12
# arguments
SRS_PREFIX=/usr/local/srs
SRS_JOBS=1
SRS_STATIC=RESERVED
... ... @@ -85,6 +86,7 @@ do
--without-arm-ubuntu12) SRS_ARM_UBUNTU12=NO ;;
--jobs) SRS_JOBS=${value} ;;
--prefix) SRS_PREFIX=${value} ;;
--static) SRS_STATIC=YES ;;
*)
... ... @@ -188,6 +190,7 @@ if [ $help = yes ]; then
--static whether add '-static' to link options. always set this option for arm.
--jobs[=N] Allow N jobs at once; infinite jobs with no arg.
used for make in the configure, for example, to make ffmpeg.
--prefix=<path> the absolute install path for srs.
END
exit 0
... ... @@ -250,6 +253,7 @@ if [ $SRS_GPERF_MP = RESERVED ]; then echo "you must specifies the gperf-mp, see
if [ $SRS_GPERF_CP = RESERVED ]; then echo "you must specifies the gperf-cp, see: ./configure --help"; __check_ok=NO; fi
if [ $SRS_GPROF = RESERVED ]; then echo "you must specifies the gprof, see: ./configure --help"; __check_ok=NO; fi
if [ $SRS_ARM_UBUNTU12 = RESERVED ]; then echo "you must specifies the arm-ubuntu12, see: ./configure --help"; __check_ok=NO; fi
if [[ -z $SRS_PREFIX ]]; then echo "you must specifies the prefix, see: ./configure --prefix"; __check_ok=NO; fi
if [ $__check_ok = NO ]; then
exit 1;
fi
... ... @@ -272,5 +276,5 @@ if [ $SRS_GPERF_CP = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --with-gcp"; el
if [ $SRS_GPROF = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --with-gprof"; else SRS_CONFIGURE="${SRS_CONFIGURE} --without-gprof"; fi
if [ $SRS_ARM_UBUNTU12 = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --with-arm-ubuntu12"; else SRS_CONFIGURE="${SRS_CONFIGURE} --without-arm-ubuntu12"; fi
if [ $SRS_STATIC = YES ]; then SRS_CONFIGURE="${SRS_CONFIGURE} --static"; fi
SRS_CONFIGURE="${SRS_CONFIGURE} ${SRS_JOBS}"
SRS_CONFIGURE="${SRS_CONFIGURE} ${SRS_JOBS} --prefix=${SRS_PREFIX}"
echo "regenerate config: ${SRS_CONFIGURE}"
... ...
... ... @@ -158,7 +158,10 @@ END
# makefile
echo "generate Makefile"
cat << END > ${SRS_MAKEFILE}
.PHONY: default _default help clean server bandwidth librtmp librtmp-sample utest _prepare_dir
.PHONY: default _default install help clean server bandwidth librtmp librtmp-sample utest _prepare_dir
# install prefix.
SRS_PREFIX=${SRS_PREFIX}
END
... ... @@ -184,7 +187,7 @@ _default: bandwidth librtmp-sample utest
@bash objs/_srs_build_summary.sh
help:
@echo "Usage: make <help>|<clean>|<server>|<bandwidth>|<librtmp>|<librtmp-sample>|<utest>"
@echo "Usage: make <help>|<clean>|<server>|<bandwidth>|<librtmp>|<librtmp-sample>|<utest>|<install>|<uninstall>"
@echo " help display this help menu"
@echo " clean cleanup project"
@echo " server build the srs(simple rtmp server) over st(state-threads)"
... ... @@ -192,6 +195,8 @@ help:
@echo " librtmp build the client publish/play library."
@echo " librtmp-sample build the srs-librtmp sample"
@echo " utest build the utest for srs"
@echo " install install srs to the prefix path"
@echo " uninstall uninstall srs from prefix path"
clean:
(cd ${SRS_OBJS}; rm -f rm -rf srs bandwidth srs_utest)
... ... @@ -204,6 +209,28 @@ server: _prepare_dir
END
# install entry
cat << END >> ${SRS_MAKEFILE}
uninstall:
@echo "rmdir \$(SRS_PREFIX)"
@rm -rf \$(SRS_PREFIX)
install:
@echo "mkdir \$(SRS_PREFIX)"
@mkdir -p \$(SRS_PREFIX)
@echo "copy binary files"
@mkdir -p \$(SRS_PREFIX)/objs
@cp objs/srs \$(SRS_PREFIX)/objs
@echo "copy srs conf files"
@mkdir -p \$(SRS_PREFIX)/conf
@cp conf/*.conf \$(SRS_PREFIX)/conf
@echo "copy init.d script files"
@mkdir -p \$(SRS_PREFIX)/etc/init.d
@cp etc/init.d/simple-rtmp-server \$(SRS_PREFIX)/etc/init.d
@sed -i "s|^ROOT=.*|ROOT=\"\$(SRS_PREFIX)\"|g" \$(SRS_PREFIX)/etc/init.d/simple-rtmp-server
END
if [ $SRS_BWTC = YES ]; then
cat << END >> ${SRS_MAKEFILE}
bandwidth: server
... ...
... ... @@ -10,18 +10,22 @@
# Description: https://github.com/winlinvip/simple-rtmp-server
### END INIT INFO
# the config of ROOT, user must modify it when start srs from other directory,
# it's ok to use the script by command ./etc/init.d/simple-rtmp-server
ROOT="./"
APP="./objs/srs"
CONFIG="./conf/srs.conf"
DEFAULT_PID_FILE='./objs/srs.pid'
########################################################################
# utility functions
########################################################################
RED="\\e[31m"
GREEN="\\e[32m"
YELLOW="\\e[33m"
BLACK="\\e[0m"
POS="\\e[60G"
# the pid file is generated by install wizard
ROOT="./"
APP="./objs/srs"
CONFIG="./conf/srs.conf"
DEFAULT_PID_FILE='./objs/srs.pid'
ok_msg(){
echo -e "${1}${POS}${BLACK}[${GREEN} OK ${BLACK}]"
}
... ... @@ -41,7 +45,11 @@ load_process_info() {
srs_pid_file=`cat ${ROOT}/${CONFIG} |grep ^pid|awk '{print $2}'|awk -F ';' '{print $1}'`
if [[ -z $srs_pid_file ]]; then srs_pid_file=${DEFAULT_PID_FILE}; fi
if [[ -f $srs_pid_file ]]; then
srs_pid=`cat $srs_pid_file 2>/dev/null`
else
srs_pid=`cat ${ROOT}/$srs_pid_file 2>/dev/null`
fi
ret=$?; if [[ 0 -ne $ret ]]; then error_msg="file $srs_pid_file does not exists"; return 1; fi
ps -p ${srs_pid} >/dev/null 2>/dev/null
... ... @@ -53,15 +61,10 @@ load_process_info() {
start() {
# if exists, exit.
load_process_info
if [[ 0 -eq $? ]]; then
failed_msg "srs started(pid ${srs_pid}), should not start it again."
return 0
fi
# try to get log dir.
if [[ 0 -eq $? ]]; then failed_msg "SRS started(pid ${srs_pid}), should not start it again."; return 0; fi
# not exists, start server
ok_msg "Starting srs..."
ok_msg "Starting SRS..."
# TODO: FIXME: set limit by, for instance, "ulimit -HSn 10000"
# TODO: FIXME: write log to, for instance, the same dir of log.
# TODO: FIXME: support deamon, without nohup.
... ... @@ -69,22 +72,18 @@ start() {
# check again after start server
load_process_info
if [[ 0 -eq $? ]]; then
ok_msg "srs started(pid ${srs_pid})"
else
failed_msg "srs not started"
fi
ret=$?; if [[ 0 -eq $? ]]; then ok_msg "SRS started(pid ${srs_pid})"; return 0; fi
failed_msg "SRS not started"
return $ret
}
stop() {
# not start, exit
load_process_info
if [[ 0 -ne $? ]]; then
failed_msg "srs not start."
return 0
fi
if [[ 0 -ne $? ]]; then failed_msg "SRS not start."; return 0; fi
ok_msg "Stopping srs(pid ${srs_pid})..."
ok_msg "Stopping SRS(pid ${srs_pid})..."
# process exists, kill util stop
for((;;)); do
... ... @@ -94,7 +93,7 @@ stop() {
ret=$?; if [[ 0 -ne $ret ]]; then failed_msg "send signal SIGTERM failed ret=$ret"; return $ret; fi
sleep 0.1
else
ok_msg "srs stopped"
ok_msg "SRS stopped"
break;
fi
done
... ... @@ -107,15 +106,30 @@ stop() {
# @return 0 if srs is running; otherwise, 1 for stopped.
status() {
load_process_info
ret=$?; if [[ 0 -eq $ret ]]; then
echo "srs(pid ${srs_pid}) is running."
return 0
fi
ret=$?; if [[ 0 -eq $ret ]]; then echo "SRS(pid ${srs_pid}) is running."; return 0; fi
echo "srs is stopped, $error_msg"
echo "SRS is stopped, $error_msg"
return 1
}
reload() {
# not start, exit
load_process_info
if [[ 0 -ne $? ]]; then failed_msg "SRS not start."; return 0; fi
ok_msg "Reload SRS(pid ${srs_pid})..."
# process exists, reload it
kill -s SIGHUP ${srs_pid} 2>/dev/null
ret=$?; if [[ 0 -ne $ret ]]; then failed_msg "Reload SRS failed ret=$ret"; return $ret; fi
load_process_info
if [[ 0 -ne $? ]]; then failed_msg "SRS reload failed."; return $ret; fi
ok_msg "SRS reloaded"
return 0
}
menu() {
case "$1" in
start)
... ... @@ -131,6 +145,9 @@ menu() {
status)
status
;;
reload)
reload
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload}"
return 1
... ...