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:
parent
3c5878c980
commit
62762cf1ad
4 changed files with 85 additions and 33 deletions
|
@ -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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue