Commit d1355d7c3438f1d516df9d7c40e2dc93b10e9ce2

Authored by Clang
1 parent 898711ff
Exists in master

更新启动端口检测

Showing 1 changed file with 25 additions and 1 deletions   Show diff stats
ngrokd.init
... ... @@ -30,7 +30,7 @@ LOGFILE=${ProGramInstallPath}/ngrok.log
30 30 SCRIPTNAME=/etc/init.d/${NAME}
31 31 PID_DIR=/var/run
32 32 PID_FILE=$PID_DIR/ngrok_clang.pid
33   -version="v5.1"
  33 +version="v5.2"
34 34 manage_port="4446"
35 35 RET_VAL=0
36 36  
... ... @@ -69,6 +69,29 @@ fun_load_config(){
69 69 cd ${ProGramInstallPath}
70 70 fi
71 71 }
  72 +fun_check_port(){
  73 + fun_load_config
  74 + strHttpPort=""
  75 + strHttpsPort=""
  76 + strRemotePort=""
  77 + strManPort=""
  78 + strHttpPort=`netstat -ntl | grep "\b:${http_port}\b"`
  79 + strHttpsPort=`netstat -ntl | grep "\b:${https_port}\b"`
  80 + strRemotePort=`netstat -ntl | grep "\b:${remote_port}\b"`
  81 + strManagePort=`netstat -ntl | grep "\b:${manage_port}\b"`
  82 + if [ -n "${strHttpPort}" ] || [ -n "${strHttpsPort}" ] || [ -n "${strRemotePort}" ] || [ -n "${strManagePort}" ]; then
  83 + [ -n "${strHttpPort}" ] && str_http_port="\"${http_port}\""
  84 + [ -n "${strHttpsPort}" ] && str_https_port="\"${https_port}\""
  85 + [ -n "${strRemotePort}" ] && str_remote_port="\"${remote_port}\""
  86 + [ -n "${strManagePort}" ] && str_manage_port="\"${manage_port}\""
  87 + echo "Error: Port ${str_http_port} ${str_https_port} ${str_remote_port} ${str_manage_port} is used,view relevant port:"
  88 + [ -n "${strHttpPort}" ] && netstat -ntlp | grep "\b:${http_port}\b"
  89 + [ -n "${strHttpsPort}" ] && netstat -ntlp | grep "\b:${https_port}\b"
  90 + [ -n "${strRemotePort}" ] && netstat -ntlp | grep "\b:${remote_port}\b"
  91 + [ -n "${strManagePort}" ] && netstat -ntlp | grep "\b:${manage_port}\b"
  92 + return 1
  93 + fi
  94 +}
72 95 fun_randstr(){
73 96 index=0
74 97 strRandomPass=""
... ... @@ -90,6 +113,7 @@ fun_start()
90 113 echo "${ProgramName} (pid `pidof $NAME`) already running."
91 114 return 0
92 115 fi
  116 + fun_check_port
93 117 fun_load_config
94 118 echo -n "Starting ${ProgramName}..."
95 119 ${BIN} -domain="$dns" -httpAddr=":$http_port" -httpsAddr=":$https_port" -pass="$pass" -tlsCrt="$srtCRT" -tlsKey="$strKey" -tunnelAddr=":$remote_port"${log_level} > ${LOGFILE} 2>&1 &
... ...