#!/command/with-contenv bash
# VRRP for the connector-remote HA group (docs/design/pfconnector-remote-ha.md).
# The VIP comes from the env file or from the connector configuration cached
# by pfconnector-client (pfconnector-env.sh resolves both). Without one, the
# service marks itself "run once" and exits; the client brings it up
# (configure-keepalived.sh + s6-svc -u) once the admin enables HA.
exec 2>&1
. /usr/local/pf/sbin/pfconnector-env.sh
if [ -z "${PFCONNECTOR_HA_VIP:-}" ] || [ ! -s /etc/keepalived/keepalived.conf ]; then
    echo "keepalived: no virtual IP configured, HA disabled"
    s6-svc -O /run/service/keepalived
    exit 0
fi
exec /usr/sbin/keepalived --dont-fork --log-console --log-detail --use-file /etc/keepalived/keepalived.conf
