#!/bin/sh

# Copyright C 2002-2003 by Isilon Systems, Inc. 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,
# Inc.
# 
# 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. 
#  
# Isilon and Isilon Systems are registered trademarks of Isilon Systems,
# Inc.  Legion is a trademark of Isilon Systems, Inc.  All other
# trademarks and registered trademarks are the property of their
# respective holders.

# KEYWORD: shutdown nostart
# REQUIRE: isi_post_shutdown

echo -n "Isilon first-pass shutdown:"

# Shut down MCP first so it stops restarting things during shutdown
if [ -r /var/run/isi_mcp.pid ] ; then
	/bin/kill -QUIT `cat /var/run/isi_mcp.pid`
	echo -n " isi_mcp";
fi

# Tell isi_dmilog to send any final alerts and clear the log
#   for next reboot if necessary.
for isilon_daemon in isi_dmilog
do
    if [ -r /var/run/${isilon_daemon}.pid ] ; then
    	/bin/cat /var/run/${isilon_daemon}.pid | /usr/bin/xargs /bin/kill -USR1
        echo -n " ${isilon_daemon}"
    fi
done

# Stop the LCD
/usr/bin/isi_lcd_d stop
echo -n " isi_lcd_d"

# Shut down isi_flexnet_d
if [ -r /var/run/isi_flexnet_d.pid ] ; then
	/bin/kill -TERM `cat /var/run/isi_flexnet_d.pid`
	echo -n " isi_flexnet_d";
fi

#
# Stop the SAS PHY Monitor
#
# NOTE: Since we echo the name of the service being stopped,
#	we redirect stdout to /dev/null to squelch the output
#	from the control script.
#
/usr/bin/isi_hwtools/isi_sasphymon_ctl stop 1>/dev/null
echo -n " isi_sasphymon"

echo "."

# If we are booted off a USB stick, remove /etc/isilon_system_config.
# If we also support CTO, revert hardware capabilities/attributes back
# to defaults
/usr/bin/isi_hwtools/isi_hal_predicate supportsCto > /dev/null 2>&1
supports_cto=$?
booted_from_usb=`/usr/bin/python -c \
		"import isi.sys.bootdisk as bd;print bd.booted_from_reimage_flash() and 1 or 0"`

if [ ${booted_from_usb} -eq 1 ]; then
	/bin/rm -f /etc/isilon_system_config
	if [ ${supports_cto} -eq 1 ]; then
		/usr/bin/isi_inventory_tool --revert
	fi
fi
