1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

add reload support. add make install and uninstall

This commit is contained in:
winlin 2014-03-22 22:07:14 +08:00
parent 3c5878c980
commit 62762cf1ad
4 changed files with 85 additions and 33 deletions

View file

@ -551,5 +551,9 @@ else
echo "#undef SRS_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H echo "#undef SRS_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H
fi fi
echo "" >> $SRS_AUTO_HEADERS_H
# prefix
echo "#define SRS_PREFIX \"${SRS_PREFIX}\"" >> $SRS_AUTO_HEADERS_H
# new empty line to auto headers file. # new empty line to auto headers file.
echo "" >> $SRS_AUTO_HEADERS_H echo "" >> $SRS_AUTO_HEADERS_H

View file

@ -29,6 +29,7 @@ SRS_GPERF_CP=RESERVED # gperf cpu profile
SRS_GPROF=RESERVED # gprof SRS_GPROF=RESERVED # gprof
SRS_ARM_UBUNTU12=RESERVED # armhf(v7cpu) built on ubuntu12 SRS_ARM_UBUNTU12=RESERVED # armhf(v7cpu) built on ubuntu12
# arguments # arguments
SRS_PREFIX=/usr/local/srs
SRS_JOBS=1 SRS_JOBS=1
SRS_STATIC=RESERVED SRS_STATIC=RESERVED
@ -85,6 +86,7 @@ do
--without-arm-ubuntu12) SRS_ARM_UBUNTU12=NO ;; --without-arm-ubuntu12) SRS_ARM_UBUNTU12=NO ;;
--jobs) SRS_JOBS=${value} ;; --jobs) SRS_JOBS=${value} ;;
--prefix) SRS_PREFIX=${value} ;;
--static) SRS_STATIC=YES ;; --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. --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. --jobs[=N] Allow N jobs at once; infinite jobs with no arg.
used for make in the configure, for example, to make ffmpeg. used for make in the configure, for example, to make ffmpeg.
--prefix=<path> the absolute install path for srs.
END END
exit 0 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_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_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 [ $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 if [ $__check_ok = NO ]; then
exit 1; exit 1;
fi 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_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_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 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}" echo "regenerate config: ${SRS_CONFIGURE}"

31
trunk/configure vendored
View file

@ -158,7 +158,10 @@ END
# makefile # makefile
echo "generate Makefile" echo "generate Makefile"
cat << END > ${SRS_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 END
@ -184,7 +187,7 @@ _default: bandwidth librtmp-sample utest
@bash objs/_srs_build_summary.sh @bash objs/_srs_build_summary.sh
help: 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 " help display this help menu"
@echo " clean cleanup project" @echo " clean cleanup project"
@echo " server build the srs(simple rtmp server) over st(state-threads)" @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 build the client publish/play library."
@echo " librtmp-sample build the srs-librtmp sample" @echo " librtmp-sample build the srs-librtmp sample"
@echo " utest build the utest for srs" @echo " utest build the utest for srs"
@echo " install install srs to the prefix path"
@echo " uninstall uninstall srs from prefix path"
clean: clean:
(cd ${SRS_OBJS}; rm -f rm -rf srs bandwidth srs_utest) (cd ${SRS_OBJS}; rm -f rm -rf srs bandwidth srs_utest)
@ -204,6 +209,28 @@ server: _prepare_dir
END 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 if [ $SRS_BWTC = YES ]; then
cat << END >> ${SRS_MAKEFILE} cat << END >> ${SRS_MAKEFILE}
bandwidth: server bandwidth: server

View file

@ -10,18 +10,22 @@
# Description: https://github.com/winlinvip/simple-rtmp-server # Description: https://github.com/winlinvip/simple-rtmp-server
### END INIT INFO ### 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" RED="\\e[31m"
GREEN="\\e[32m" GREEN="\\e[32m"
YELLOW="\\e[33m" YELLOW="\\e[33m"
BLACK="\\e[0m" BLACK="\\e[0m"
POS="\\e[60G" 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(){ ok_msg(){
echo -e "${1}${POS}${BLACK}[${GREEN} OK ${BLACK}]" 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}'` 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 [[ -z $srs_pid_file ]]; then srs_pid_file=${DEFAULT_PID_FILE}; fi
srs_pid=`cat $srs_pid_file 2>/dev/null` 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 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 ps -p ${srs_pid} >/dev/null 2>/dev/null
@ -53,15 +61,10 @@ load_process_info() {
start() { start() {
# if exists, exit. # if exists, exit.
load_process_info load_process_info
if [[ 0 -eq $? ]]; then if [[ 0 -eq $? ]]; then failed_msg "SRS started(pid ${srs_pid}), should not start it again."; return 0; fi
failed_msg "srs started(pid ${srs_pid}), should not start it again."
return 0
fi
# try to get log dir.
# not exists, start server # not exists, start server
ok_msg "Starting srs..." ok_msg "Starting SRS..."
# TODO: FIXME: set limit by, for instance, "ulimit -HSn 10000" # TODO: FIXME: set limit by, for instance, "ulimit -HSn 10000"
# TODO: FIXME: write log to, for instance, the same dir of log. # TODO: FIXME: write log to, for instance, the same dir of log.
# TODO: FIXME: support deamon, without nohup. # TODO: FIXME: support deamon, without nohup.
@ -69,22 +72,18 @@ start() {
# check again after start server # check again after start server
load_process_info load_process_info
if [[ 0 -eq $? ]]; then ret=$?; if [[ 0 -eq $? ]]; then ok_msg "SRS started(pid ${srs_pid})"; return 0; fi
ok_msg "srs started(pid ${srs_pid})"
else failed_msg "SRS not started"
failed_msg "srs not started" return $ret
fi
} }
stop() { stop() {
# not start, exit # not start, exit
load_process_info load_process_info
if [[ 0 -ne $? ]]; then if [[ 0 -ne $? ]]; then failed_msg "SRS not start."; return 0; fi
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 # process exists, kill util stop
for((;;)); do for((;;)); do
@ -94,7 +93,7 @@ stop() {
ret=$?; if [[ 0 -ne $ret ]]; then failed_msg "send signal SIGTERM failed ret=$ret"; return $ret; fi ret=$?; if [[ 0 -ne $ret ]]; then failed_msg "send signal SIGTERM failed ret=$ret"; return $ret; fi
sleep 0.1 sleep 0.1
else else
ok_msg "srs stopped" ok_msg "SRS stopped"
break; break;
fi fi
done done
@ -107,15 +106,30 @@ stop() {
# @return 0 if srs is running; otherwise, 1 for stopped. # @return 0 if srs is running; otherwise, 1 for stopped.
status() { status() {
load_process_info load_process_info
ret=$?; if [[ 0 -eq $ret ]]; then ret=$?; if [[ 0 -eq $ret ]]; then echo "SRS(pid ${srs_pid}) is running."; return 0; fi
echo "srs(pid ${srs_pid}) is running."
return 0
fi
echo "srs is stopped, $error_msg" echo "SRS is stopped, $error_msg"
return 1 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() { menu() {
case "$1" in case "$1" in
start) start)
@ -131,6 +145,9 @@ menu() {
status) status)
status status
;; ;;
reload)
reload
;;
*) *)
echo "Usage: $0 {start|stop|status|restart|reload}" echo "Usage: $0 {start|stop|status|restart|reload}"
return 1 return 1