#!/bin/sh export QNAP_QPKG="CloudLink" CONF=/etc/config/qpkg.conf QPKG_INSTALL_PATH=`/sbin/getcfg -f /etc/config/qpkg.conf $QNAP_QPKG Install_Path` TUNNEL_AGENT_DAEMON_PID_LIST=`/bin/ps --columns 256 | /bin/grep "$QPKG_INSTALL_PATH/bin/tunnel_agent_daemon.sh" | /bin/grep -v grep | /bin/awk '{print $1}'` SETSID_BIN=/bin/setsid # check if got QPKG_INSTALL_PATH if [ "$QPKG_INSTALL_PATH" == "" ]; then echo "Failed to get QPKG_INSTALL_PATH" exit 1 fi function customize_by_device_type() { DEVICE_TYPE=`/usr/sbin/qcloud_tool -d 2>/dev/null` if [ "$DEVICE_TYPE" = "QVP" ]; then /bin/cp ${QPKG_INSTALL_PATH}/ui/customized/tunnel_agent_embedded_main_qvp.js ${QPKG_INSTALL_PATH}/ui/tunnel_agent_embedded_main.js fi } case "$1" in start) ENABLED=$(/sbin/getcfg $QNAP_QPKG Enable -u -d FALSE -f $CONF) if [ "$ENABLED" != "TRUE" ]; then echo "$QNAP_QPKG is disabled." exit 1 fi : ADD START ACTIONS HERE # execute customized part $(customize_by_device_type) # execute "cd" to avoid cwd missing cd ${QPKG_INSTALL_PATH} # create web UI symbolic link /bin/mkdir -p /home/httpd/cgi-bin/qpkg /bin/rm -rf /home/httpd/cgi-bin/qpkg/${QNAP_QPKG} /bin/ln -sf ${QPKG_INSTALL_PATH}/ui /home/httpd/cgi-bin/qpkg/${QNAP_QPKG} # start tunnel agent ${QPKG_INSTALL_PATH}/bin/tunnel_agent_ctl.sh start &> /dev/null # start daemon if [ -z "$TUNNEL_AGENT_DAEMON_PID_LIST" ]; then if [ -f "$SETSID_BIN" ]; then $SETSID_BIN ${QPKG_INSTALL_PATH}/bin/tunnel_agent_daemon.sh &> /dev/null & else ${QPKG_INSTALL_PATH}/bin/tunnel_agent_daemon.sh &> /dev/null & fi fi ;; stop) : ADD STOP ACTIONS HERE # stop daemon # kill all tunnel agent process for i in "${TUNNEL_AGENT_DAEMON_PID_LIST[@]}" do if [ -f "$SETSID_BIN" ]; then # use bash kill instead /bin/kill for kill process group # tunnel daemon and inotifywait kill -9 -- -$i &>/dev/null else /bin/kill -9 $i &>/dev/null fi done # stop tunnel agent ${QPKG_INSTALL_PATH}/bin/tunnel_agent_ctl.sh stop ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 esac exit 0