#!/bin/sh QPKG_INSTALL_PATH="`dirname $0`/.." QPKG_INSTALL_PATH=`cd "$QPKG_INSTALL_PATH"; pwd` TUNNEL_AGENT_PID_LIST=`/bin/ps --columns 256 | /bin/grep "tunnelagent" | /bin/grep -v grep | /bin/grep -v ' Z ' | /bin/awk '{print $1}'` case "$1" in start) QPKG_ENABLED=$(/sbin/getcfg $QNAP_QPKG Enable -d FALSE -f /etc/config/qpkg.conf) VLINK_STATUS=$(/sbin/getcfg -f /etc/config/qid.conf "QNAP VLink Service" STATUS -d Disable) STATUS=$(/sbin/getcfg -f /etc/config/qid.conf "QNAP ID Service" "STATUS" -d "") if [ "$QPKG_ENABLED" == "TRUE" ] && [ "$VLINK_STATUS" == "Enable" ] && [ "$STATUS" == "3" ]; then # check if need to start tunnel agent if [ "$TUNNEL_AGENT_PID_LIST" == "" ]; then # add event log flag if [ "y$2" != "ydaemon" ]; then /sbin/setcfg -f /etc/config/qpkg.conf CloudLink TUNNEL_EVENT_LOG TRUE fi # start agent /sbin/daemon_mgr tunnelagent start "PATH=$QPKG_INSTALL_PATH/python/bin QNAP_QPKG=$QNAP_QPKG QNAP_HOME=$QPKG_INSTALL_PATH $QPKG_INSTALL_PATH/bin/tunnelagent &>/dev/null &" fi # check if need to start cloudlink_p2p_agent if [ -f $QPKG_INSTALL_PATH/bin/cloudlink_p2p_agent_ctl.sh ]; then $QPKG_INSTALL_PATH/bin/cloudlink_p2p_agent_ctl.sh start > /dev/null 2>&1 fi else $0 stop fi ;; stop) # kill all tunnel agent process if [ "$TUNNEL_AGENT_PID_LIST" != "" ]; then /sbin/daemon_mgr tunnelagent stop "PATH=$QPKG_INSTALL_PATH/python/bin QNAP_QPKG=$QNAP_QPKG QNAP_HOME=$QPKG_INSTALL_PATH $QPKG_INSTALL_PATH/bin/tunnelagent &>/dev/null &" for i in "${TUNNEL_AGENT_PID_LIST[@]}" do /bin/kill -9 $i &>/dev/null done TUNNEL_AGENT_CLOSED=true fi /bin/rm -f /var/run/tunnelagent.pid > /dev/null 2>&1 # we add this feature for QTS_4.3.5 above versions, and use the existence of qanalytic_tool # to enable the send action. qanalytic_tools before QTS_4.3.5 are called qanalytic_send if [ -x '/usr/local/bin/qanalytic_tool' ]; then QPKG_VER=`/sbin/getcfg -f /etc/config/qpkg.conf $QNAP_QPKG Version` if [ "x$TUNNEL_AGENT_CLOSED" = "xtrue" ]; then /usr/local/bin/qanalytic_tool send -p myqnapcloud -r device_cloudlink_tunnel -e "qpkg_version=$QPKG_VER status=disabled" > /dev/null 2>&1 & fi fi # check if need to start cloudlink_p2p_agent if [ -f $QPKG_INSTALL_PATH/bin/cloudlink_p2p_agent_ctl.sh ]; then $QPKG_INSTALL_PATH/bin/cloudlink_p2p_agent_ctl.sh stop > /dev/null 2>&1 fi ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 esac exit 0