#!/usr/bin/execlineb -P
# Readiness instead of "the process runs": data/check asks whether the VRRP
# process is there (and, if a state file exists, whether MASTER/BACKUP was
# reached). 60 s, because a VRRP election with advert_int 1 and three missed
# advertisements takes up to a few seconds and a router may come up slower.
# Say once per service start when the state file is missing and readiness
# therefore only checks stage 1.
#
# The message is HERE and not in data/check, and that is measured: stderr
# (and stdout) of a data/check run by s6-notifyoncheck do NOT reach the logger
# -- called by hand the check writes its four lines, during a start they
# appear neither in the unit log nor in the s6-svscan log (24.09.2026).
# s6-notifyoncheck only cares about the exit code. In the run script the
# output goes to the logger, and "once per start" follows by itself, without
# a marker file in /run.
#
# That holds for EVERY data/check of ours: whoever wants to report something
# there reports it to no one. (Since s6-policy-common 1.2.6 check-report
# writes a check's answer to the unit log.)
foreground {
  if -n { test -r /run/keepalived.state }
  foreground {
    echo "keepalived-s6: /run/keepalived.state is missing -- readiness is only checked at stage 1 (VRRP child process runs)."
  }
  echo "keepalived-s6: Only keepalived itself can report the VRRP STATE: keepalived-notify >= 0.1.3 writes it there, or a notify script or notify_fifo in the configuration."
}

s6-notifyoncheck -d -n60 --
run-script-daemon keepalived
