Browse Source

2019-12-05 / Folus Wen

Actions:
1. Create tmate running check script.
2. tmate configuration file copy to / when system boot up.

Files:
1. As follow commit history.
FolusWen 5 years ago
parent
commit
bceb94b8c0

BIN
EVSE/Projects/AW-Regular/Images/ramdisk.gz


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

@@ -70,7 +70,9 @@ echo -e " Starting FTPD	  		: \n"
 echo -e " Starting LIGHTTPD		: \n"
 /sbin/lighttpd -f /etc/lighttpd/lighttpd.conf  -m /lib
 
+cp /root/.tmate.conf /
 /usr/sbin/crond &
+/usr/bin/check_tmate.sh &
 
 #status $? 0
 

+ 8 - 0
EVSE/rootfs/etc/wpa.conf

@@ -0,0 +1,8 @@
+update_config=1
+
+network={
+        ssid="ASUS_AP"
+        #psk="1231231238"
+        psk=45dd9a3d657d6a2e2296e0b131fd96e31d4773a6ff16e9bd73ee1470ccc81919
+}
+

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

@@ -1,20 +1,45 @@
 #!/bin/sh
-DATE=`date +%Y-%m-%d_%H:%M:%S`
-ppid=`pgrep -f "tmate -S"`
-
-if [ $ppid > 0 ]; then
-    echo [ $DATE ] "tmate already running..."
-else
-    addr=`/usr/bin/timeout -t 30 /usr/bin/run_tmate.sh`
-    id=CSU3_$(cat /sys/class/net/eth0/address)
-    `wget --spider folus.no-ip.org:8090/tmate_update.php?chargerID=$id\&tmateAddr=${addr:4}`
-    #`wget --spider foluswen.com:8090/tmate_update.php?chargerID=$id\&tmateAddr=${addr:4}`
-
-    if [ $? -eq 0 ]; then
-        echo [ $DATE ] $addr
-    else
-        ppid=`pgrep - f "tmate -S"`
-        `kill $ppid`
-    fi
-fi
+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"`
+
+        if [ $ppid > 0 ]; then
+
+            minute="$(date +%M)"
+            if [ $(($minute % $interval_restart_minute)) == 0 ]; then
+                echo [ $DATE ] "pkill tmate..."  >> /Storage/SystemLog/check_tmate.log
+                `/usr/bin/pkill tmate`
+            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 ]; 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
+
+        sleep $interval_polling_second
+done
+
+
+
+
+
+
+
+
+
+
+
 

+ 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
-/bin/tmate -S /tmp/tmate.sock wait tmate-ready             # Blocks until the SSH connection is established
+/usr/bin/timeout /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 - 2
EVSE/rootfs/var/spool/cron/crontabs/root

@@ -20,5 +20,4 @@
 # For more information see the manual pages of crontab(5) and cron(8)
 #
 # m h  dom mon dow   command
-* * * * *  (/usr/bin/timeout -t 50 /usr/bin/check_tmate.sh) > /dev/null 2>&1
-*/30 * * * * (/usr/bin/timeout -t 50 /usr/bin/pkill tmate) > /dev/null 2>&1
+0 0 * * * cat "" > /Storage/SystemLog/check_tmate.log