packages/net/keepalived/files/usr/libexec/rpcd/keepalived
Jaymin Patel 33398a38aa 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>
2022-10-13 16:57:02 +05:30

111 lines
1.4 KiB
Bash

#!/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
[ -d $RPC_SCRIPTS ] && include $RPC_SCRIPTS
__function__() {
type "$1" > /dev/null 2>&1
}
foreach_extra() {
local file obj
[ ! -d $RPC_SCRIPTS ] && return
for file in "$RPC_SCRIPTS"/*; do
obj="${file##*/}"
$1 "${obj%%.*}"
done
}
keepalived_dump() {
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
json_load "{ \"status\" : $(cat $stats_file) }"
else
json_init
fi
json_dump
}
call_extra() {
if __function__ "$1"; then
$1
else
json_init
json_add_string error "invalid call $1"
json_dump
fi
}
call_method() {
local cmd=$1
case "$cmd" in
dump)
keepalived_dump
;;
*)
call_extra "$cmd"
;;
esac
}
list_extra() {
local arg func
arg=$1
func="${arg}_help"
if __function__ "$func"; then
$func
else
json_add_object "$arg"
json_close_object
fi
}
list_methods() {
local file
json_init
json_add_object dump
json_close_object
foreach_extra list_extra "${1}"
json_dump
}
main() {
local cmd=$1
shift
case "$cmd" in
list)
list_methods "$@"
;;
call)
call_method "$@"
;;
esac
}
main "$@"