diff options
author | Jaymin Patel <jem.patel@gmail.com> | 2022-09-09 19:10:49 +0530 |
---|---|---|
committer | Jaymin Patel <jem.patel@gmail.com> | 2022-09-15 17:08:11 +0530 |
commit | 0f7415b8a89ea9ff44a725c2fd4763c6bdffc1d4 (patch) | |
tree | 005f6bf8b21377997f6e70ccfd49eb15a9cd574c /net/keepalived/files/usr | |
parent | 6d49ad9e5c5a93014cc99f1c956eaa51b36ee95f (diff) |
keepalived: add status rpc and service improvement
- enable json by default to generate json stats
- add rpc to generate json status
- add kmod-nf-ipvs dependencies for virtual servers
- set default vip labels on virtual interfaces
- set process name for keepalived child processes
Signed-off-by: Jaymin Patel <jem.patel@gmail.com>
Diffstat (limited to 'net/keepalived/files/usr')
-rw-r--r-- | net/keepalived/files/usr/libexec/rpcd/keepalived | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/net/keepalived/files/usr/libexec/rpcd/keepalived b/net/keepalived/files/usr/libexec/rpcd/keepalived new file mode 100644 index 000000000..2ae14f105 --- /dev/null +++ b/net/keepalived/files/usr/libexec/rpcd/keepalived @@ -0,0 +1,96 @@ +#!/bin/sh + +. /lib/functions.sh +. /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="/tmp/keepalived.json" + local pids + + [ -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() { + case "$1" in + dump) + keepalived_dump + ;; + *) + call_extra $1 + ;; + esac +} + +list_extra() { + if __function__ "${1}_help"; then + ${1}_help + else + json_add_object "$1" + 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 () { + case "$1" in + list) + list_methods + ;; + call) + call_method $2 + ;; + esac +} + +main "$@" |