mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 09:13:01 +02:00
board/aarch64/r2s: control WAN LED with a simple DHCP client monitor
When the interface is up and has a 'proto dhcp' address the WAN LED is lit up. When the interface goes down, or loses its DHCP lease, the LED is turned off. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
committed by
Tobias Waldekranz
parent
af5169e286
commit
e8e9f7c0a1
@@ -0,0 +1 @@
|
||||
service [12345789] log wan-monitor.sh -- WAN Health monitor
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
# Background WAN interface monitor. Lights up WAN LED
|
||||
# while the interface has a DHCP address.
|
||||
|
||||
LED_FILE="/run/led/wan-up"
|
||||
PID_FILE="/run/$(basename "$0").pid"
|
||||
|
||||
check_wan()
|
||||
{
|
||||
ip_info=$(ip a show wan)
|
||||
|
||||
if echo "$ip_info" | grep -q "inet .* proto dhcp"; then
|
||||
[ ! -f "$LED_FILE" ] && touch "$LED_FILE"
|
||||
else
|
||||
[ -f "$LED_FILE" ] && rm "$LED_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup()
|
||||
{
|
||||
rm -f "$LED_FILE"
|
||||
rm -f "$PID_FILE"
|
||||
exit 0
|
||||
}
|
||||
|
||||
trap 'cleanup' TERM INT HUP QUIT
|
||||
echo $$ > "$PID_FILE"
|
||||
|
||||
remaining_time=$((1800 - $(awk '{print int($1)}' /proc/uptime)))
|
||||
[ "$remaining_time" -lt 0 ] && remaining_time=0
|
||||
|
||||
while [ "$remaining_time" -gt 0 ]; do
|
||||
check_wan
|
||||
sleep 1
|
||||
remaining_time=$((remaining_time - 1))
|
||||
done
|
||||
|
||||
while :; do
|
||||
check_wan
|
||||
sleep 5
|
||||
done
|
||||
Reference in New Issue
Block a user