#!/bin/sh
#
# Copyright (C) 2026 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-2.0-only
#
# Release the global keepalived hotplug lock acquired by 00-lock.
# Only acts when the flag file created by 00-lock is present — this avoids
# incorrectly releasing a lock held by a concurrent event in the rare case
# where 00-lock timed out and proceeded without acquiring the lock.

case "$ACTION" in
	NOTIFY_MASTER|NOTIFY_BACKUP|NOTIFY_FAULT|NOTIFY_STOP) ;;
	*) return 0 2>/dev/null || exit 0 ;;
esac

LOCKFILE="/var/lock/keepalived-hotplug.lock"
ACQUIRED_FLAG="/var/lock/keepalived-hotplug-acquired"

if [ -f "$ACQUIRED_FLAG" ]; then
	rm -f "$ACQUIRED_FLAG"
	lock -u "$LOCKFILE"
fi
