mirror of
https://github.com/openwrt/packages.git
synced 2025-12-24 08:28:20 +04:00
keepalived: high-availability files and data sync
add new package keepalived-sync to synchronize files and data between master and backup node. The master node uses SSH over rsync to send and the backup node will use inotifywatch to watch received files. The master node can track rsync.sh script to send configuration file on a backup node based on the vrrp_script configuration of the same script. The backup node will have a keepalived-inotify service, which would watch for newly received files and it would call hotplug event. Each service can keep its respective script under the keepalived hotplug directory and executes commands to stop, start service or update any config in real-time. Whenever a switchover will happen, the backup node would have the latest config and data files from the master node. Hotplug events can be used to apply config when files are received. Signed-off-by: Jaymin Patel <jem.patel@gmail.com>
This commit is contained in:
59
net/keepalived/files/usr/libexec/keepalived/rpc/sync.sh
Normal file
59
net/keepalived/files/usr/libexec/keepalived/rpc/sync.sh
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
|
||||
# shellcheck disable=SC2039
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
. /usr/share/libubox/jshn.sh
|
||||
# shellcheck source=/dev/null
|
||||
. /lib/functions.sh
|
||||
|
||||
peer() {
|
||||
local cfg=$1
|
||||
local c_name=$2
|
||||
local name last_sync_time last_sync_status
|
||||
|
||||
config_get name "$cfg" name
|
||||
[ "$name" != "$c_name" ] && return
|
||||
|
||||
config_get last_sync_time "$cfg" last_sync_time 0
|
||||
config_get last_sync_status "$cfg" last_sync_status NA
|
||||
|
||||
json_add_object unicast_peer
|
||||
json_add_string name "$name"
|
||||
json_add_int time "$last_sync_time"
|
||||
json_add_string status "$last_sync_status"
|
||||
json_close_array
|
||||
}
|
||||
|
||||
unicast_peer() {
|
||||
config_foreach peer peer "$1"
|
||||
}
|
||||
|
||||
vrrp_instance() {
|
||||
local cfg=$1
|
||||
local name
|
||||
|
||||
config_get name "$cfg" name
|
||||
|
||||
json_add_object vrrp_instance
|
||||
json_add_string name "$name"
|
||||
json_add_array unicast_peer
|
||||
config_list_foreach "$cfg" unicast_peer unicast_peer
|
||||
json_close_array
|
||||
json_close_object
|
||||
}
|
||||
|
||||
rsync_status() {
|
||||
config_load keepalived
|
||||
|
||||
json_init
|
||||
json_add_array vrrp_instance
|
||||
config_foreach vrrp_instance vrrp_instance
|
||||
json_close_array
|
||||
json_dump
|
||||
}
|
||||
|
||||
sync_help() {
|
||||
json_add_object rsync_status
|
||||
json_close_object
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
# shellcheck disable=SC2039
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
. /lib/functions.sh
|
||||
# shellcheck source=/dev/null
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
RPC_SCRIPTS=/usr/libexec/keepalived/rpc
|
||||
@@ -16,21 +20,22 @@ foreach_extra() {
|
||||
|
||||
[ ! -d $RPC_SCRIPTS ] && return
|
||||
|
||||
for file in $RPC_SCRIPTS/*; do
|
||||
for file in "$RPC_SCRIPTS"/*; do
|
||||
obj="${file##*/}"
|
||||
$1 "${obj%%.*}"
|
||||
done
|
||||
}
|
||||
|
||||
keepalived_dump() {
|
||||
local stats_file="/tmp/keepalived.json"
|
||||
local pids
|
||||
local stats_file pids
|
||||
|
||||
stats_file="/tmp/keepalived.json"
|
||||
|
||||
[ -f "$stats_file" ] && rm -f "$stats_file"
|
||||
|
||||
pids=$(pidof /usr/sbin/keepalived)
|
||||
if [ -n "$pids" ]; then
|
||||
kill -37 $pids > /dev/null 2>&1
|
||||
kill -37 "$pids" > /dev/null 2>&1
|
||||
json_load "{ \"status\" : $(cat $stats_file) }"
|
||||
else
|
||||
json_init
|
||||
@@ -50,21 +55,28 @@ call_extra() {
|
||||
}
|
||||
|
||||
call_method() {
|
||||
case "$1" in
|
||||
local cmd=$1
|
||||
|
||||
case "$cmd" in
|
||||
dump)
|
||||
keepalived_dump
|
||||
;;
|
||||
*)
|
||||
call_extra $1
|
||||
call_extra "$cmd"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
list_extra() {
|
||||
if __function__ "${1}_help"; then
|
||||
${1}_help
|
||||
local arg func
|
||||
|
||||
arg=$1
|
||||
func="${arg}_help"
|
||||
|
||||
if __function__ "$func"; then
|
||||
$func
|
||||
else
|
||||
json_add_object "$1"
|
||||
json_add_object "$arg"
|
||||
json_close_object
|
||||
fi
|
||||
}
|
||||
@@ -77,18 +89,21 @@ list_methods() {
|
||||
json_add_object dump
|
||||
json_close_object
|
||||
|
||||
foreach_extra list_extra ${1}
|
||||
foreach_extra list_extra "${1}"
|
||||
|
||||
json_dump
|
||||
}
|
||||
|
||||
main () {
|
||||
case "$1" in
|
||||
main() {
|
||||
local cmd=$1
|
||||
shift
|
||||
|
||||
case "$cmd" in
|
||||
list)
|
||||
list_methods
|
||||
list_methods "$@"
|
||||
;;
|
||||
call)
|
||||
call_method $2
|
||||
call_method "$@"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user