summaryrefslogtreecommitdiff
path: root/roles/install_monitoring/files/check_internet.sh
diff options
context:
space:
mode:
authorNiklas Yann Wettengel <niyawe@niyawe.de>2017-03-18 18:38:46 +0100
committerNiklas Yann Wettengel <niyawe@niyawe.de>2017-03-18 18:38:46 +0100
commitcd31d75443119be6580e91d5a9a3ab7742f875ab (patch)
tree0d12fe52bbb796969336dae613e66ca5f433aba4 /roles/install_monitoring/files/check_internet.sh
parent710a210ae6f165c2e3ce165d30d27f189311656b (diff)
updated setup_fastd.yml
added features: - fastd-services-api - install_nginx - install_monitoring
Diffstat (limited to 'roles/install_monitoring/files/check_internet.sh')
-rwxr-xr-xroles/install_monitoring/files/check_internet.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/roles/install_monitoring/files/check_internet.sh b/roles/install_monitoring/files/check_internet.sh
new file mode 100755
index 0000000..5fbe0c2
--- /dev/null
+++ b/roles/install_monitoring/files/check_internet.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+INTERFACE=mullvad
+FAILED_FILE=/tmp/mullvad.failed
+fail=false
+
+if [ ! -e /sys/class/net/$INTERFACE ]; then
+ echo "$INTERFACE interface does not exist"
+ fail=true
+else
+ start_bytes=$(cat /sys/class/net/$INTERFACE/statistics/rx_bytes)
+ sleep 30
+ end_bytes=$(cat /sys/class/net/$INTERFACE/statistics/rx_bytes)
+
+ if [ $(($end_bytes-$start_bytes)) -lt 1000 ]; then
+ #echo "no traffic via $INTERFACE"
+ fail=true
+ fi
+fi
+
+if $fail; then
+ systemctl is-active openvpn-client@mullvad.service > /dev/null
+ if [ $? -ne 0 ]; then
+ systemctl status openvpn-client@mullvad.service
+ if [ -e $FAILED_FILE ]; then
+ echo restart openvpn-client@mullvad.service
+ systemctl restart openvpn-client@mullvad.service
+ else
+ touch $FAILED_FILE
+ fi
+ fi
+else
+ if [ -e $FAILED_FILE ]; then
+ rm $FAILED_FILE
+ fi
+fi
+