🤞 Sync 2026-03-06 20:21:12

This commit is contained in:
github-actions[bot] committed 2026-03-06 20:21:12 +08:00
1 parent 383bda44e8
commit 54e9196bd1
4 files changed
+46 -28

No files matched your search

+2 -2
View File
@@ -7,8 +7,8 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=floatip PKG_NAME:=floatip
PKG_VERSION:=1.0.10 PKG_VERSION:=1.1.0
PKG_RELEASE:=1 PKG_RELEASE:=2
PKG_MAINTAINER:=jjm2473 <jjm2473@gmail.com> PKG_MAINTAINER:=jjm2473 <jjm2473@gmail.com>
include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/package.mk
+4 -4
View File
@@ -13,7 +13,7 @@ enable_lan_ping() {
start_service() { start_service() {
config_load floatip config_load floatip
config_get_bool enabled "main" enabled 0 config_get_bool enabled "main" enabled 0
ifdown floatip /usr/libexec/floatip.sh down
[[ "$enabled" = 1 ]] || { [[ "$enabled" = 1 ]] || {
enable_lan_ping enable_lan_ping
return 0 return 0
@@ -62,15 +62,15 @@ start_service() {
return 0 return 0
} }
procd_open_instance procd_open_instance
procd_set_param command /usr/libexec/floatip.sh "$lan_iface" "$set_prefix" procd_set_param command /usr/libexec/floatip.sh up "$lan_iface" "$set_prefix"
procd_set_param stderr 1 procd_set_param stderr 1
procd_set_param file /etc/config/floatip procd_set_param file /etc/config/floatip
procd_close_instance procd_close_instance
} }
stop_service() { service_stopped() {
/usr/libexec/floatip.sh down
enable_lan_ping enable_lan_ping
ifdown floatip
} }
service_triggers() { service_triggers() {
+35 -22
View File
@@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
LOCK_FILE="/var/lock/floatip_loop.lock" LOCK_FILE="/var/lock/floatip_loop.lock"
LOCK_FILE_UPDOWN="/var/lock/floatip_updown.lock"
DEFAULT_PREFIX=24 DEFAULT_PREFIX=24
@@ -19,28 +20,34 @@ host_alive() {
# arping -f -q -b -c 2 -w 2 -i 1 -I $LAN_IFACE "$1" # arping -f -q -b -c 2 -w 2 -i 1 -I $LAN_IFACE "$1"
} }
try_lock_updown() {
exec 201>"$LOCK_FILE_UPDOWN"
flock -x 201 && return 0
return 1
}
unlock_updown() {
flock -u 201
}
set_up() { set_up() {
local ipaddr="$1" local ipaddr="$1"
try_lock_updown || return 1
echo "set my floatip to $ipaddr" >&2 echo "set my floatip to $ipaddr" >&2
if ! uci -q get network.floatip.ipaddr | grep -Fwq $ipaddr; then ip addr add "$ipaddr" dev "$LAN_IFACE"
if [[ "x$(uci -q get network.floatip)" = xinterface ]]; then echo "ip addr del \"$ipaddr\" dev \"$LAN_IFACE\"" > /tmp/run/floatip_cleanup.sh
uci -q batch <<-EOF >/dev/null unlock_updown
set network.floatip.device=$LAN_IFACE return 0
delete network.floatip.ipaddr }
add_list network.floatip.ipaddr=$ipaddr
EOF set_down() {
else try_lock_updown || return 1
uci -q batch <<-EOF >/dev/null if [ -f /tmp/run/floatip_cleanup.sh ]; then
set network.floatip=interface sh -c '. /tmp/run/floatip_cleanup.sh'
set network.floatip.proto=static rm -f /tmp/run/floatip_cleanup.sh
set network.floatip.device=$LAN_IFACE
add_list network.floatip.ipaddr=$ipaddr
set network.floatip.auto=0
EOF
fi
uci commit network
fi fi
ifup floatip unlock_updown
return 0
} }
set_lan_ping() { set_lan_ping() {
@@ -112,7 +119,7 @@ fallback_loop() {
if [[ $found_alive = 1 ]]; then if [[ $found_alive = 1 ]]; then
if [[ $floatip_up = 1 ]]; then if [[ $floatip_up = 1 ]]; then
echo "set down floatip" >&2 echo "set down floatip" >&2
ifdown floatip set_down || exit 1
floatip_up=0 floatip_up=0
else else
dead_counter=0 dead_counter=0
@@ -130,7 +137,7 @@ fallback_loop() {
continue continue
fi fi
echo "no host alive, set up floatip $ipaddr" >&2 echo "no host alive, set up floatip $ipaddr" >&2
set_up "$ipaddr" set_up "$ipaddr" || exit 1
floatip_up=1 floatip_up=1
sleep 5 sleep 5
done done
@@ -182,7 +189,7 @@ main_loop() {
set_lan_ping set_lan_ping
if [[ $found_alive = 0 ]]; then if [[ $found_alive = 0 ]]; then
echo "no host alive, and url passed, set up floatip $ipaddr" >&2 echo "no host alive, and url passed, set up floatip $ipaddr" >&2
set_up "$ipaddr" set_up "$ipaddr" || exit 1
floatip_up=1 floatip_up=1
fi fi
else else
@@ -198,7 +205,7 @@ main_loop() {
continue continue
fi fi
echo "set down floatip, and disable ping" >&2 echo "set down floatip, and disable ping" >&2
ifdown floatip set_down || exit 1
set_lan_ping 0 set_lan_ping 0
floatip_up=0 floatip_up=0
fi fi
@@ -219,6 +226,12 @@ main() {
fi fi
} }
if [[ "$1" = "down" ]]; then
set_down
exit 0
fi
shift
try_lock() { try_lock() {
exec 200>"$LOCK_FILE" exec 200>"$LOCK_FILE"
flock -x 200 && return 0 flock -x 200 && return 0
+5
View File
@@ -13,6 +13,11 @@ uci -q batch <<-EOF >/dev/null
commit ucitrack commit ucitrack
EOF EOF
uci -q batch <<-EOF >/dev/null
delete network.floatip
commit network
EOF
# don't change role if enabled # don't change role if enabled
[[ "`uci -q get floatip.main.enabled`" = "1" ]] && exit 0 [[ "`uci -q get floatip.main.enabled`" = "1" ]] && exit 0