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:
Jaymin Patel
2022-09-09 19:10:49 +05:30
parent 83ff83e320
commit 33398a38aa
18 changed files with 912 additions and 15 deletions

View File

@@ -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
}