#!/bin/sh
#
# Copyright C 2016 by Isilon Systems, LLC. All rights not expressly
# granted herein are reserved.
# Created in the United States of America.
#
# This digital media is protected by U.S. and international copyright and
# intellectual property laws. Unless otherwise specified, all information
# and screens appearing as part of this digital medium, including
# software, services, documents, text, images, icons, and logos design;
# the selection, assembly, arrangement, and design thereof; and the code
# that enables its presentation, are the sole property of Isilon Systems,
# LLC.
#
# Except as otherwise required by applicable law, no part of any
# copyrighted material may be reproduced, modified, translated,
# distributed, published, or transmitted by any means, electronic or
# mechanical, for any purpose, without the prior written consent of Isilon
# Systems, LLC.
#
# Isilon and Isilon Systems are registered trademarks of Isilon Systems,
# LLC.  Legion is a trademark of Isilon Systems, LLC.  All other
# trademarks and registered trademarks are the property of their
# respective holders.
#

# PROVIDE: isi_psi_init
# REQUIRE: isi_module_init isi_bootdisk_init

. /etc/rc.subr

name="isi_psi_init"
start_cmd="isi_psi_startup"


# XXX: When isi_psi_d becomes a full-fledged daemon, it should be managed by mcp
#      Keep in mind the startup order, isi_psi_d must start up before anything that uses PSI.
isi_psi_startup()
{
	# isi_psi_tool --pull will compare mfg partition files
	# with non-volatile data, if available (e.g. BMC NVRAM),
	# and restore any missing or different files, as necessary.
	/usr/bin/isi_hwtools/isi_psi_tool --pull
	result=$?
	if [ ${result} -ne 0 ]; then
	    # On local failure, attempt pull from peer node
	    /usr/bin/isi_hwtools/isi_psi_tool --pull --peer
	fi

	# isi_psi_tool --copy will pull the PSI config files to
	# /etc/psi.conf.d from the appropriate location
	# (mfg or /etc/psi), for nodes supporting them
	/usr/bin/isi_hwtools/isi_psi_tool --copy

	/usr/bin/isi_psi_d
}

load_rc_config $name
run_rc_command "$1"
