Created
July 1, 2023 16:46
-
-
Save 0x5e/199872b9ff3297cb65f236c377d36ed8 to your computer and use it in GitHub Desktop.
OpenWrt passwall service watchdog. Auto restart service when tcp node dns resolve ip changed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Run this script from cron every 10 minutes: | |
# echo '*/10 * * * * /path/to/passwall_watchdog.sh' >> /etc/crontabs/root | |
enabled=$(uci get passwall.@global[0].enabled) | |
tcp_node=$(uci get passwall.@global[0].tcp_node) | |
address=$(uci get passwall.$tcp_node.address) | |
previous_ip=$(uci get passwall.$tcp_node.ip 2>/dev/null) | |
current_ip=$(resolveip $address) | |
if [ -z "$current_ip" ]; then | |
logger -t "passwall_watchdog" "resolveip failed, skip." | |
exit 0 | |
fi | |
if [ "$previous_ip" = "$current_ip" ]; then | |
exit 0 | |
else | |
uci set passwall.$tcp_node.ip=$current_ip | |
if [ "$enabled" = "1" ] && [ -n "$previous_ip" ]; then | |
logger -t "passwall_watchdog" "$address: $previous_ip -> $current_ip, restarting service..." | |
service passwall restart | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment