#!/bin/sh
# Copyright (c) 2019 iXsystems, Inc.
# All rights reserved.
# This file is a part of TrueNAS
# and may not be copied and/or distributed
# without the express permission of iXsystems.
#
# $FreeBSD$
#

# PROVIDE: ix-haready
# REQUIRES: middlewared ix-postinit securelevel
# KEYWORD: shutdown

. /etc/rc.subr

name="ix_haready"
start_cmd='haready_start'
stop_cmd='haready_stop'

haready_start()
{
	# Tell CARP to start allowing and advertising CARP/VRRP packets.
	# See #28198 for one of the reasons why this is required.
	/sbin/sysctl net.inet.carp.allow=1
}

haready_stop()
{
	# Once we start shutdown process, demote from CARP master role,
	# so that another controller could promote ASAP, if it is there.
	# Kill fenced here just in case of some races.  Normally it should
	# be killed by carp-state-change-hook.py on CARP event.
	/bin/pkill -9 -f fenced
	/sbin/sysctl net.inet.carp.allow=0
}

run_rc_command "$1"
