您可以使用notify命令写出状态文件.
# for ANY state transition.
# "notify" script is called AFTER the
# notify_* script(s) and is executed
# with 3 arguments provided by keepalived
# (ie don’t include parameters in the notify line).
# arguments
# $1 = "GROUP"|"INSTANCE"
# $2 = name of group or instance
# $3 = target state of transition
# ("MASTER"|"BACKUP"|"FAULT")
notify /path/notify.sh
创建一个通知脚本,如:
#!/bin/bash
# notify.sh
echo $1 $2 is in $3 state > /var/run/keepalive.$1.$2.state
和get状态脚本如:
#!/bin/bash
# getstate.sh
cat /var/run/keepalive.*.*.state