#!/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 )" # --> include qpkg_sh_log function source "$InstallPath/qpkg_sh_log.sh" # --> functions function fn_print_usage() { echo "Usage(QPKG mode): $0 {start|stop|restart}" echo "Usage(RD mode) : $0 {start|stop|restart} --debug" exit 1 } 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 RTRR_DAEMON -syslog -c:/etc/qsync/qsyncd.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 # $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 $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="--trlevel INFO" 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 if [ $DEBUG -eq 1 ]; then set +x fi exit 0