🌴 Sync 2026-03-05 23:51:42

This commit is contained in:
github-actions[bot] committed 2026-03-05 23:51:42 +08:00
1 parent 97c049ed0a
commit 0acff03804
14253 files changed
+3893239

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
:
include $(TOPDIR)/rules.mk
PKG_NAME:=pingcontrol
PKG_VERSION:=1
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/pingcontrol
include $(INCLUDE_DIR)/package.mk
define Package/pingcontrol
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Network interface watchdog
PKGARCH:=all
endef
define Package/pingcontrol/description
This package contains a utility for managing the interface using ping requests.
endef
define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/pingcontrol/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) ./files/pingcontrol $(1)/bin/
$(INSTALL_DIR) $(1)/etc/config
$(CP) ./files/pingcontrol.config $(1)/etc/config/pingcontrol
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/pingcontrol.init $(1)/etc/init.d/pingcontrol
endef
$(eval $(call BuildPackage,pingcontrol))
+114
View File
@@ -0,0 +1,114 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
INSTANCE=$1
IFACE=$(uci -q get pingcontrol.$1.iface)
CHECK_PERIOD=$(uci -q get pingcontrol.$1.check_period)
TESTIP=$(uci -q get pingcontrol.$1.testip)
SW_BEFORE_MODRES=$(uci -q get pingcontrol.$1.sw_before_modres)
SW_BEFORE_SYSRES=$(uci -q get pingcontrol.$1.sw_before_sysres)
PING_OK=$(uci -q get pingcontrol.$1.ping_ok)
SILENT=$(uci -q get pingcontrol.$1.ping_silent)
PING_LOST=$(uci -q get pingcontrol.$1.ping_lost)
PING_RESTORED=$(uci -q get pingcontrol.$1.ping_restored)
BEFORE_IFACE_DOWN=$(uci -q get pingcontrol.$1.before_iface_down)
AFTER_IFACE_UP=$(uci -q get pingcontrol.$1.after_iface_up)
BEFORE_REBOOT=$(uci -q get pingcontrol.$1.before_reboot)
host_up_count=0
lost1=0
lost2=0
lost_flag=0
IP_COUNT=$(echo $TESTIP | wc -w)
let SW_BEFORE_MODRES=SW_BEFORE_MODRES*IP_COUNT
let SW_BEFORE_SYSRES=SW_BEFORE_SYSRES*IP_COUNT
ubus call network.interface.$IFACE up
while [[ -z "$IFNAME" ]]; do
json_load "$(ubus call network.interface.$IFACE status)"
json_get_var IFNAME l3_device
sleep $CHECK_PERIOD
done
while true; do
for IP in $TESTIP
do
[ -n $IFNAME ] && {
/bin/ping -w5 -c1 -s8 -I $IFNAME $IP &> /dev/null
STATUS=$?
} || {
/bin/ping -w5 -c1 -s8 $IP &> /dev/null
STATUS=$?
}
if [[ "${STATUS}" -eq "0" ]]; then
let host_up_count++
else
logger -t pingcontrol "$INSTANCE: Ping to host $IP lost"
if [[ -n "$PING_LOST" ]]; then
logger -t pingcontrol "$INSTANCE: Execute $PING_LOST"
eval $PING_LOST
fi
let lost1++
let lost2++
lost_flag=1
fi
done
if [[ "$host_up_count" -gt "0" ]]; then
[ "${SILENT}" != "1" ] && {
logger -t pingcontrol "$INSTANCE: Ping OK, reset counters"
}
if [[ "$lost_flag" -eq "1" ]]; then
if [[ -n "$PING_RESTORED" ]]; then
logger -t pingcontrol "$INSTANCE: Execute $PING_RESTORED"
eval $PING_RESTORED
fi
else
if [[ -n "$PING_OK" ]]; then
[ "${SILENT}" != "1" ] && {
logger -t pingcontrol "$INSTANCE: Execute $PING_OK"
}
eval $PING_OK
fi
fi
host_up_count=0
lost1=0
lost2=0
lost_flag=0
fi
if [[ "$lost1" -gt "0" ]]; then
if [[ "$SW_BEFORE_MODRES" -ne "0" ]]; then
if [[ "$lost1" -ge "$SW_BEFORE_MODRES" ]]; then
if [[ -n "$BEFORE_IFACE_DOWN" ]]; then
logger -t pingcontrol "$INSTANCE: Execute $BEFORE_IFACE_DOWN"
eval $BEFORE_IFACE_DOWN
fi
logger -t pingcontrol "$INSTANCE: Ifup/ifdown $IFACE"
ubus call network.interface.$IFACE down
sleep 1
ubus call network.interface.$IFACE up
if [[ -n "$AFTER_IFACE_UP" ]]; then
logger -t pingcontrol "$INSTANCE: Execute $AFTER_IFACE_UP"
eval $AFTER_IFACE_UP
fi
lost1=0
fi
fi
if [[ "$SW_BEFORE_SYSRES" -ne "0" ]]; then
if [[ "$lost2" -ge "$SW_BEFORE_SYSRES" ]]; then
if [[ -n "$BEFORE_REBOOT" ]]; then
logger -t pingcontrol "$INSTANCE: Execute $BEFORE_REBOOT"
eval $BEFORE_REBOOT
fi
logger -t pingcontrol "$INSTANCE: Reboot now!"
reboot
fi
fi
fi
sleep $CHECK_PERIOD
done
+8
View File
@@ -0,0 +1,8 @@
config pingcontrol 'pingcontrol'
option enabled '0'
option check_period '30'
option iface 'internet'
option testip '8.8.8.8'
option ping_silent '1'
option sw_before_modres '3'
option sw_before_sysres '0'
+49
View File
@@ -0,0 +1,49 @@
#!/bin/sh /etc/rc.common
START=80
USE_PROCD=1
PROG=/bin/pingcontrol
validate_pingcontrol_section() {
uci_validate_section pingcontrol pingcontrol "${1}" \
'enabled:bool:0' \
'iface:string' \
'check_period:uinteger' \
'testip:list(host)' \
'sw_before_modres:uinteger' \
'sw_before_sysres:uinteger'
}
pingcontrol_instance() {
local enabled iface check_period testip sw_before_modres sw_before_sysres
validate_pingcontrol_section "$1" || {
echo "validation failed"
return 1
}
[ "$enabled" = 0 ] && return
procd_open_instance
procd_set_param command "$PROG" "$1"
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param respawn
procd_close_instance
}
start_service() {
config_load 'pingcontrol'
config_foreach pingcontrol_instance 'pingcontrol'
}
service_triggers() {
procd_add_reload_trigger 'pingcontrol'
procd_add_validation validate_pingcontrol_section
}
reload_service() {
stop
start
}