온실 파이: 네트워크 감시(공유기 핑 실패 시 wlan0 재연결→드라이버 재적재→재부팅) 스크립트·타이머 보관

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-18 21:28:32 +09:00
1 parent 73f5b0ddea
commit a1e60a9840
3 files changed
+37

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
[Unit]
Description=Network watchdog (ping gateway, recover Wi-Fi)
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/netwatch.sh
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# 공유기(.1)에 핑이 연속으로 안 되면 단계적으로 복구한다.
# 3회(약 3분): wlan0 재연결 / 6회: Wi-Fi 드라이버 재적재 / 10회(약 10분): 재부팅(부팅 후 15분 이내면 생략 — 재부팅 반복 방지)
GW=192.168.0.1
F=/run/netwatch.fails
n=$(cat "$F" 2>/dev/null || echo 0)
if ping -c2 -W2 "$GW" >/dev/null 2>&1; then
[ "$n" -ge 3 ] && logger -t netwatch "네트워크 복구됨 (연속 실패 $n회 뒤)"
echo 0 > "$F"; exit 0
fi
n=$((n+1)); echo "$n" > "$F"
logger -t netwatch "공유기 핑 실패 $n회 (wlan0: $(nmcli -t -f DEVICE,STATE dev | grep wlan0), usb: $(lsusb | grep -c 0bda:0179))"
if [ "$n" -eq 3 ]; then
logger -t netwatch "wlan0 재연결 시도"
nmcli device disconnect wlan0; sleep 2; nmcli device connect wlan0
elif [ "$n" -eq 6 ]; then
logger -t netwatch "Wi-Fi 드라이버 재적재"
nmcli radio wifi off; modprobe -r rtl8xxxu; sleep 2; modprobe rtl8xxxu; sleep 3; nmcli radio wifi on
elif [ "$n" -ge 10 ]; then
up=$(cut -d. -f1 /proc/uptime)
if [ "$up" -gt 900 ]; then
logger -t netwatch "10분 넘게 복구 안 됨 — 재부팅"; sync; systemctl reboot
fi
fi
+8
View File
@@ -0,0 +1,8 @@
[Unit]
Description=Run network watchdog every minute
[Timer]
OnBootSec=5min
OnUnitActiveSec=1min
AccuracySec=10s
[Install]
WantedBy=timers.target