Add PostgreSQL HA OCF agent modular baseline

This commit is contained in:
Lyncoln
2026-09-12 01:28:33 -04:00
commit 4a358ae0f6
30 changed files with 7119 additions and 0 deletions
+109
View File
@@ -0,0 +1,109 @@
# Sourced by managed-container; uses the shared OCF and parameter environment.
demote_target()
{
local state_file
local type operation promote_uname demote_uname local_node
local now mtime age
state_file="/run/loxthelion/${OCF_RESOURCE_INSTANCE:-managed-container}.notify"
local_node="$(hostname)"
[ -r "${state_file}" ] || return 1
now="$(date +%s)" || return 1
mtime="$(stat -c %Y "${state_file}" 2>/dev/null)" || return 1
age=$((now - mtime))
[ "${age}" -ge 0 ] || return 1
[ "${age}" -le 120 ] || return 1
type="$(
sed -n 's/^type=//p' "${state_file}" | head -n1
)"
operation="$(
sed -n 's/^operation=//p' "${state_file}" | head -n1
)"
promote_uname="$(
sed -n 's/^promote_uname=//p' "${state_file}" | head -n1
)"
demote_uname="$(
sed -n 's/^demote_uname=//p' "${state_file}" | head -n1
)"
[ "${type}" = "pre" ] || return 1
[ "${operation}" = "demote" ] || return 1
[ "${demote_uname}" = "${local_node}" ] || return 1
[ -n "${promote_uname}" ] || return 1
[ "${promote_uname}" != "${local_node}" ] || return 1
case "${promote_uname}" in
*" "*) return 1 ;;
esac
printf '%s
' "${promote_uname}"
}
managed_notify()
{
local state_dir state_file
state_dir="/run/loxthelion"
state_file="${state_dir}/${OCF_RESOURCE_INSTANCE:-managed-container}.notify"
ocf_log info \
"notify: type=${OCF_RESKEY_CRM_meta_notify_type:-unset} operation=${OCF_RESKEY_CRM_meta_notify_operation:-unset}"
ocf_log info \
"notify: promote_uname=${OCF_RESKEY_CRM_meta_notify_promote_uname:-none} demote_uname=${OCF_RESKEY_CRM_meta_notify_demote_uname:-none}"
ocf_log info \
"notify: promoted_uname=${OCF_RESKEY_CRM_meta_notify_promoted_uname:-none} unpromoted_uname=${OCF_RESKEY_CRM_meta_notify_unpromoted_uname:-none}"
if ! mkdir -p -m 0755 "${state_dir}"; then
ocf_exit_reason \
"Unable to create notification state directory ${state_dir}"
return "${OCF_ERR_GENERIC}"
fi
if ! {
printf 'timestamp=%s\n' "$(date --iso-8601=seconds)"
printf 'node=%s\n' "$(hostname)"
printf 'type=%s\n' "${OCF_RESKEY_CRM_meta_notify_type:-}"
printf 'operation=%s\n' "${OCF_RESKEY_CRM_meta_notify_operation:-}"
printf 'promote_uname=%s\n' "${OCF_RESKEY_CRM_meta_notify_promote_uname:-}"
printf 'demote_uname=%s\n' "${OCF_RESKEY_CRM_meta_notify_demote_uname:-}"
printf 'promoted_uname=%s\n' "${OCF_RESKEY_CRM_meta_notify_promoted_uname:-}"
printf 'unpromoted_uname=%s\n' "${OCF_RESKEY_CRM_meta_notify_unpromoted_uname:-}"
} > "${state_file}"
then
ocf_exit_reason \
"Unable to write notification state ${state_file}"
return "${OCF_ERR_GENERIC}"
fi
chmod 0600 "${state_file}" || {
ocf_exit_reason \
"Unable to secure notification state ${state_file}"
return "${OCF_ERR_GENERIC}"
}
{
printf '%s node=%s type=%s operation=%s promote=[%s] demote=[%s] promoted=[%s] unpromoted=[%s]\n' \
"$(date --iso-8601=seconds)" \
"$(hostname)" \
"${OCF_RESKEY_CRM_meta_notify_type:-}" \
"${OCF_RESKEY_CRM_meta_notify_operation:-}" \
"${OCF_RESKEY_CRM_meta_notify_promote_uname:-}" \
"${OCF_RESKEY_CRM_meta_notify_demote_uname:-}" \
"${OCF_RESKEY_CRM_meta_notify_promoted_uname:-}" \
"${OCF_RESKEY_CRM_meta_notify_unpromoted_uname:-}" \
>> "${state_dir}/${OCF_RESOURCE_INSTANCE:-managed-container}.notify.log"
} || true
return "${OCF_SUCCESS}"
}