keepalived: add support for directory sync
authorFrancesco Benini <francy.benini@gmail.com>
Sat, 1 Feb 2025 22:13:22 +0000 (23:13 +0100)
committerFlorian Eckert <Eckert.Florian@googlemail.com>
Wed, 5 Feb 2025 07:14:04 +0000 (08:14 +0100)
This commit adds support for folder synchronization.
An example is in the 810-files file where it is explained how to
synchronize all hotplug files of keepalived.

Signed-off-by: Francesco Benini <francy.benini@gmail.com>
net/keepalived/Makefile
net/keepalived/files/etc/hotplug.d/keepalived/810-files
net/keepalived/files/lib/functions/keepalived/hotplug.sh
net/keepalived/files/usr/share/keepalived/scripts/rsync.sh

index db660152edd36ddea9a8a12138ef0ba607d37917..573908cc8f7f6df4182f0d1e7f4a6b77adf03511 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=keepalived
 PKG_VERSION:=2.3.1
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://www.keepalived.org/software
index d6f9b90b7cc0942d3298ebf39f323fe94b28dd71..a306841552c628da326123ada9eb3a5e30090171 100644 (file)
@@ -15,4 +15,7 @@ add_sync_file /etc/shinit
 add_sync_file /etc/sysctl.conf
 add_sync_file /tmp/dhcp.leases
 
+# uncomment the following line and add /etc/hotplug.d/keepalived to sysupgrade.conf or keepalived configuration in order to enable hotplug scripts sync
+# add_sync_file /etc/hotplug.d/keepalived
+
 keepalived_hotplug
index 5bd96d5cf564b18fe1037ae4221b165e287806f6..8db32f7ea1259b166fb6cb72f5121d41a802b76d 100644 (file)
@@ -82,6 +82,17 @@ is_sync_file() {
        list_contains SYNC_FILES_LIST "$1"
 }
 
+is_sync_file_in_folder() {
+       local f="$1"
+       while [ "$f" != "" ]; do
+               f="${f%/*}"
+               if list_contains SYNC_FILES_LIST "$f"; then
+                       return 0
+               fi
+       done
+       return 1
+}
+
 _set_update_target() {
        set_var UPDATE_TARGET "${1:-1}"
 }
@@ -227,7 +238,7 @@ _notify_sync() {
                return
        fi
 
-       is_sync_file "$RSYNC_TARGET" || return
+       is_sync_file "$RSYNC_TARGET" || is_sync_file_in_folder "$RSYNC_TARGET" || return
 
        if ! cp -a "$RSYNC_SOURCE" "$RSYNC_TARGET"; then
                log_err "can not copy $RSYNC_SOURCE => $RSYNC_TARGET"
index fa15df2119fa3049653d315b0ef8a82c2eea93d5..78c533ff9aedeafd9404b52a2ccb0903796057d5 100644 (file)
@@ -44,11 +44,10 @@ ha_sync_send() {
        config_get sync_list "$cfg" sync_list
 
        for sync_file in $sync_list $(sysupgrade -l); do
-               [ -f "$sync_file" ] && {
-                       dir="${sync_file%/*}"
-                       list_contains files_list "${sync_file}" || append files_list "${sync_file}"
-               }
+               [ -f "$sync_file" ] && dir="${sync_file%/*}"
                [ -d "$sync_file" ] && dir="${sync_file}"
+
+               list_contains files_list "${sync_file}" || append files_list "${sync_file}"
                list_contains dirs_list "${sync_dir}${dir}" || append dirs_list "${sync_dir}${dir}"
        done