Update and rename check_pivpn.sh to check_openvpn.sh

This commit is contained in:
spleenftw authored and GitHub committed 2024-02-23 00:38:36 +01:00
1 parent ed362c4643
commit 8e10308df7
1 file changed
+1 -1
+43
View File
@@ -0,0 +1,43 @@
#!/bin/bash
# /usr/local/bin/check_openvpn.sh
# Set the initial status
status=""
# Function to restart OpenVPN service
restart_openvpn() {
systemctl restart openvpn_exporter
}
# Check if OpenVPN service is active
if systemctl is-active --quiet openvpn; then
status="ACTIVE"
else
status="NON-ACTIVE"
fi
# Display the initial status
echo "Service is $status"
# Continuously monitor the status and restart if it changes
while true; do
# Check if OpenVPN service is active
if systemctl is-active --quiet openvpn; then
new_status="ACTIVE"
else
new_status="NON-ACTIVE"
fi
# Check if the status has changed
if [ "$new_status" != "$status" ]; then
status="$new_status"
echo "Service is now $status"
# Restart OpenVPN service
restart_openvpn
fi
# Sleep for a while before checking again
sleep 5
done