-
Notifications
You must be signed in to change notification settings - Fork 3
/
ngrok.sh
38 lines (35 loc) · 969 Bytes
/
ngrok.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
#----------用户配置----------
#sunny文件的目录
SUNNYDIR=
#你在ngrok.cc的地址,一般是free.ngrok.cc
SERVER=
#代理端口,在仪表盘可以看到
PORT=
#Sunny的管道ID
SUNNYID=
#---------------------------
timeout=5
target=https://www.ngrok.cc
ret_code=`curl -I -s --connect-timeout $timeout $target -w %{http_code} | tail -n1`
while [ "x$ret_code" != "x200" ]; do
echo "[`date`]等待网络连接" | tee -a $SUNNYDIR/log.txt
sleep 3
ret_code=`curl -I -s --connect-timeout $timeout $target -w %{http_code} | tail -n1`
done
echo "[`date`]网络已连接,开始部署服务" | tee -a $SUNNYDIR/log.txt
$SUNNYDIR/sunny clientid $SUNNYID &
sleep 10
while true
do
nc -z -v -w5 $SERVER $PORT >/dev/null 2>&1
result1=$?
if [ "$result1" != 0 ]; then
echo "[`date`]监测到服务离线,尝试重启" | tee -a $SUNNYDIR/log.txt
sudo killall -9 sunny
/home/pi/ngrok/sunny clientid $SUNNYID &
sleep 10
else
sleep 60
fi
done