121 lines
4.3 KiB
Bash
Executable File
121 lines
4.3 KiB
Bash
Executable File
# Sourced by managed-container; uses the shared OCF and parameter environment.
|
|
|
|
mc_pg_demote_notification_target()
|
|
{
|
|
local allow_self="${1:-false}"
|
|
local state_file
|
|
local type operation promote_uname demote_uname local_node
|
|
local now mtime age
|
|
local promote_norm local_norm demote_norm
|
|
|
|
state_file="/run/loxthelion/${OCF_RESOURCE_INSTANCE:-managed-container}.notify"
|
|
local_node="${OCF_RESKEY_CRM_meta_on_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
|
|
|
|
local_norm="$(printf '%s' "${local_node}" | tr '[:upper:]' '[:lower:]')"
|
|
demote_norm="$(printf '%s' "${demote_uname}" | tr '[:upper:]' '[:lower:]')"
|
|
promote_norm="$(printf '%s' "${promote_uname}" | tr '[:upper:]' '[:lower:]')"
|
|
|
|
[ "${demote_norm}" = "${local_norm}" ] || return 1
|
|
[ -n "${promote_uname}" ] || return 1
|
|
|
|
case "${promote_uname}" in
|
|
*" "*) return 1 ;;
|
|
esac
|
|
|
|
if [ "${allow_self}" != true ] && [ "${promote_norm}" = "${local_norm}" ]; then
|
|
return 1
|
|
fi
|
|
|
|
printf '%s\n' "${promote_uname}"
|
|
}
|
|
|
|
# Legacy callers retain the historical requirement for a distinct successor.
|
|
demote_target()
|
|
{
|
|
mc_pg_demote_notification_target false
|
|
}
|
|
|
|
# Native-peer demotion can distinguish a true handoff from Pacemaker's
|
|
# demote/restart/re-promote of the same node after a resource-definition change.
|
|
mc_pg_native_demote_target()
|
|
{
|
|
mc_pg_demote_notification_target true
|
|
}
|
|
|
|
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}"
|
|
}
|