#!/bin/sh # 1) This script must go with HBS install. # 2) If giving option '--debug', this script will show all debug messang and NOT stop. # --> get the dir of this script SOURCE="${BASH_SOURCE[0]}" # resolve $SOURCE until the file is no longer a symlink while [ -h "$SOURCE" ]; do DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )" SOURCE="$(readlink "$SOURCE")" [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it # relative to the path where the symlink file was located done SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )" # --> set python3 env . $SCRIPT_DIR/set_py3_env.sh > /dev/null 2>&1 function fn_print_usage() { echo "Usage(QPKG mode): $0 {start|stop|restart}" echo "Usage(RD mode) : $0 {start|stop|restart} --debug" exit 1 } #RR2S_SUB_PATH=bin/rr2_daemon.py #RR2S_SUB_PATHC=bin/rr2_daemon.pyc # # #function fn_set_script_root() { # if [ -e "$HBS_INST_PATH/rr2/$RR2S_SUB_PATHC" ] || [ -e "$HBS_INST_PATH/rr2/$RR2S_SUB_PATH" ]; then # SCRIPT_ROOT="$HBS_INST_PATH/rr2" # else # SCRIPT_ROOT="$CURR_DIR/.." # fi #} # #function fn_start_rtrr_daemon() { # # --> kill previous RTRR_DAEMON anyway # echo "starting rtrr server..." # # killall RTRR_DAEMON > /dev/null 2>&1 # # --> sometime, the above cmd can't kill all DAEMON at one time, # # so use rr2_tool to kill all process instead. # $SCRIPT_DIR/rr2_tool.sh -stoprtrrd > /dev/null 2>&1 # RTRRD_CONF=/etc/config/qsync/qsyncd.conf # ENABLED=$(/sbin/getcfg "" Enabled -d 1 -f $RTRRD_CONF) # if [ "$ENABLED" != "1" ]; then # /bin/echo "RTRR DAEMON is disabled." # # fn_log "RTRR DAEMON is disabled." # exit 1 # fi # RTRR_DAEMON -syslog -c:$RTRRD_CONF > /dev/null 2>&1 # $SCRIPT_DIR/rr2_tool.sh -waitrtrrsstart 10 #} # #function fn_stop_rtrr_daemon() { # echo "stopping rtrr server..." # # killall RTRR_DAEMON > /dev/null 2>&1 # # --> sometime, the above cmd can't kill all DAEMON at one time, # # so use rr2_tool to kill all process instead. # $SCRIPT_DIR/rr2_tool.sh -stoprtrrd > /dev/null 2>&1 # # # $SCRIPT_DIR/rr2_tool.sh -waitsevstop RTRR_DAEMON 10 > /dev/null 2>&1 # $SCRIPT_DIR/rr2_tool.sh -waitrtrrsstop 10 #} # #function fn_start_rr2_daemon() { # echo "starting rr2 server..." # if [ $DEBUG -eq 1 ]; then # python3 $RR2S_PY -conf $RR2S_CONF -logdir $RR2S_LOGD $TR_LEVEL --trconsole & # else # python3 $RR2S_PY -conf $RR2S_CONF -logdir $RR2S_LOGD $TR_LEVEL > /dev/null 2>&1 & # # --> check if server starts for 10 secs # $SCRIPT_DIR/rr2_tool.sh -waitrr2sstart 10 # fi #} # #function fn_stop_rr2_daemon() { # echo "stopping rr2 server..." # # --> we should not use the following script to kill rr2_server, since it will kill this script too # # kill $(ps | grep rr2_server.py | awk '{ print $1 }') > /dev/null 2>&1 & # # --> instead, we use another py to get rr2 server pid and then kill them # $SCRIPT_DIR/rr2_tool.sh -stoprr2s # # # --> wait 10s for server stops # # $RR2S_CURR_DIR/rr2_tool.sh -waitsevstop rr2_server.py 10 > /dev/null 2>&1 # $SCRIPT_DIR/rr2_tool.sh -waitrr2sstop 10 #} # #function fn_start_service_gateway() { # echo "starting service gateway..." # # if [ -e "$SCRIPT_ROOT/bin/proxy/gateway.pyc" ]; then # : ${SERVICE_GATEWAY:="$SCRIPT_ROOT/bin/proxy/gateway.pyc"} # else # : ${SERVICE_GATEWAY:="$SCRIPT_ROOT/bin/proxy/gateway.py"} # fi # # : ${SERVICE_GATEWAY_CONF:=${HBS_INST_PATH}/rr2/config/server/service_gateway.conf} # python ${SERVICE_GATEWAY} --config ${SERVICE_GATEWAY_CONF} # # $SCRIPT_DIR/rr2_tool.sh -waitgatewaysstart 10 #} # #function fn_stop_service_gateway() { # echo "stopping service gateway..." # # : ${SERVICE_GATEWAY_PIDFILE:=$SCRIPT_ROOT/logs/server/service_gateway.pid} ## if [ -e ${SERVICE_GATEWAY_PIDFILE} ]; then ## kill $(<$SERVICE_GATEWAY_PIDFILE) > /dev/null 2>&1 ## else ## kill $(ps | grep gateway.py | awk '{ print $1 }') > /dev/null 2>&1 ## fi # # --> kill any process regarding gateway.py # $SCRIPT_DIR/rr2_tool.sh -killproc gateway.py 1 > /dev/null 2>&1 # $SCRIPT_DIR/rr2_tool.sh -waitgatewaysstop 10 #} # #function fn_stop_service_gateway() { # echo "stopping service gateway..." # # : ${SERVICE_GATEWAY_PIDFILE:=$SCRIPT_ROOT/logs/server/service_gateway.pid} ## if [ -e ${SERVICE_GATEWAY_PIDFILE} ]; then ## kill $(<$SERVICE_GATEWAY_PIDFILE) > /dev/null 2>&1 ## else ## kill $(ps | grep gateway.py | awk '{ print $1 }') > /dev/null 2>&1 ## fi # # --> kill any process regarding gateway.py # $SCRIPT_DIR/rr2_tool.sh -killproc gateway.py 1 > /dev/null 2>&1 # $SCRIPT_DIR/rr2_tool.sh -waitgatewaysstop 10 #} # ## --> check if arguments are valid #DEBUG=0 #for arg in $* #do # if [ $arg == "--debug" ]; then # DEBUG=1 # echo "*** DEBUG MODE" # echo "*** CURR_DIR=$CURR_DIR" # set -x # break # fi #done # #TR_LEVEL="" #if [ $DEBUG -eq 1 ]; then # set -x # TR_LEVEL="--trlevel DEBUG" #fi # ## --> decide SCRIPT_ROOT #SCRIPT_ROOT="$RR2S_CURR_DIR/.." #fn_set_script_root # ## --> decide RR2S_PY #if [ -e "$SCRIPT_ROOT/$RR2S_SUB_PATHC" ]; then # RR2S_PY="$SCRIPT_ROOT/$RR2S_SUB_PATHC" #else # RR2S_PY="$SCRIPT_ROOT/$RR2S_SUB_PATH" #fi # #RR2S_CONF="$SCRIPT_ROOT/config/server/rr2_server.conf" #RR2S_LOGD="$SCRIPT_ROOT/logs/server" # ## --> reset BIN_PY_PATH #if [ $DEBUG -eq 1 ]; then # python3 --version #fi # #case "$1" in # start) # fn_start_rtrr_daemon # fn_start_rr2_daemon # fn_start_service_gateway # ;; # stop) # fn_stop_service_gateway # fn_stop_rr2_daemon # fn_stop_rtrr_daemon # ;; # restart) # $0 stop # if [ $# -eq 1 ]; then # $0 start # else # # --> forward option '--debug' # if [ $# -eq 2 ]; then # $0 start $2 # fi # fi # ;; # # *) # fn_print_usage #esac # --> check if having debug string DEBUG=0 DEBUG_ARG= for arg in $* do if [ $arg == "--debug" ]; then DEBUG=1 DEBUG_ARG=--debug echo "*** DEBUG MODE" set -x break fi done # --> QTSHBS00-3634-disable-tfo # The qpkg script, hbs.sh, will invoke this script anyway, # so put the tfo disabling script here. touch /etc/config/qsync/disable_tfo > /dev/null 2>&1 # --> to use consistent code, we user rr2_cli/server.py here, instead of using rr2_tool.py. # --> decide PY or PYC if [ -e "$HBS_INST_PATH/rr2/bin/cli/server.py" ]; then PY_ENTRY="$HBS_INST_PATH/rr2/bin/cli/server.py" else PY_ENTRY="$HBS_INST_PATH/rr2/bin/cli/server.pyc" fi # --> get arg#1 OPTIONS="stop start restart" ARG1= for opt in $OPTIONS do if [ "$1" == "$opt" ]; then ARG1=-$1 fi done if [ -z "$ARG1" ] then fn_print_usage else python3 $PY_ENTRY $ARG1 $DEBUG_ARG fi if [ $DEBUG -eq 1 ]; then set +x fi exit 0