瀏覽代碼

2019-12-09 / Folus Wen

Actions:
1. run_tmate.sh modify timeout spec.
2. check_tmate.sh change loop logic.

Files:
1. As follow commit history.
FolusWen 5 年之前
父節點
當前提交
7cf5b856ad

二進制
EVSE/Projects/AW-Regular/Images/ramdisk.gz


+ 0 - 1
EVSE/rootfs/etc/init.d/rcS

@@ -72,7 +72,6 @@ echo -e " Starting LIGHTTPD		: \n"
 
 cp /root/.tmate.conf /
 /usr/sbin/crond &
-/usr/bin/check_tmate.sh &
 
 #status $? 0
 

+ 18 - 35
EVSE/rootfs/usr/bin/check_tmate.sh

@@ -1,45 +1,28 @@
 #!/bin/sh
-interval_polling_second=60
 interval_restart_minute=30
 
-while :
-do
-        DATE=`date +%Y-%m-%d_%H:%M:%S`
-        ppid=`pgrep -f "tmate -S /tmp/tmate.sock new-session -d"`
+DATE=`date +%Y-%m-%d_%H:%M:%S`
+ppid=`pgrep -f "tmate -S /tmp/tmate.sock new-session -d"`
 
-        if [ $ppid > 0 ]; then
+if [ $ppid > 0 ]; then
 
-            minute="$(date +%M)"
-            if [ $(($minute % $interval_restart_minute)) == 0 ]; then
-                echo [ $DATE ] "pkill tmate..."  >> /Storage/SystemLog/check_tmate.log
+	minute="$(date +%M)"
+        if [ $(($minute % $interval_restart_minute)) == 0 ]; then
+        	echo [ $DATE ] "pkill tmate..."  >> /Storage/SystemLog/check_tmate.log
                 `/usr/bin/pkill tmate`
-            else
+	else
                 echo [ $DATE ] "tmate already running..."  >> /Storage/SystemLog/check_tmate.log
-            fi
-        else
-                addr=`/usr/bin/run_tmate.sh`
-                id=CSU3_$(cat /sys/class/net/eth0/address)
-                `/usr/bin/timeout -t 10 /usr/bin/wget --spider folus.no-ip.org:8090/tmate_update.php?chargerID=$id\&tmateAddr=${addr:4}`
-
-                if [ $? -eq 0 ] && [ ${#addr} -ge 10 ]; then
-                        echo [ $DATE ] $addr  >> /Storage/SystemLog/check_tmate.log
-                else
-                        echo [ $DATE ] "tmate start fail..."  >> /Storage/SystemLog/check_tmate.log
-			`/usr/bin/pkill tmate`
-		fi
         fi
+else
+	addr=`/usr/bin/run_tmate.sh`
+        id=CSU3_$(cat /sys/class/net/eth0/address)
+        `/usr/bin/timeout -t 20 /usr/bin/wget --spider folus.no-ip.org:8090/tmate_update.php?chargerID=$id\&tmateAddr=${addr:4}`
 
-        sleep $interval_polling_second
-done
-
-
-
-
-
-
-
-
-
-
-
+        if [ $? -eq 0 ] && [ ${#addr} -ge 10 ]; then
+        	echo [ $DATE ] $addr  >> /Storage/SystemLog/check_tmate.log
+        else
+                echo [ $DATE ] "tmate start fail..."  >> /Storage/SystemLog/check_tmate.log
+		`/usr/bin/pkill tmate`
+	fi
+fi
 

+ 1 - 1
EVSE/rootfs/usr/bin/run_tmate.sh

@@ -1,5 +1,5 @@
 #!/bin/sh
 /bin/tmate -S /tmp/tmate.sock new-session -d               # Launch tmate in a detached state
-/usr/bin/timeout /bin/tmate -S /tmp/tmate.sock wait tmate-ready             # Blocks until the SSH connection is established
+/usr/bin/timeout -t 20 /bin/tmate -S /tmp/tmate.sock wait tmate-ready             # Blocks until the SSH connection is established
 /bin/tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}'    # Prints the SSH connection string
 

+ 1 - 0
EVSE/rootfs/var/spool/cron/crontabs/root

@@ -21,3 +21,4 @@
 #
 # m h  dom mon dow   command
 0 0 * * * cat "" > /Storage/SystemLog/check_tmate.log
+* * * * * /usr/bin/check_tmate.sh >> /Storage/SystemLog/check_tmate.log 2>&1