#! /bin/sh
#
# Copyright (c) 2014-2017 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#

### BEGIN INIT INFO
# Description: sm.shutdown
#
# Short-Description: Service Management Engine Shutdowm.
# Provides: sm.shutdown
# Required-Start: $null
# Should-Start: $null
# Should-Stop: $null
# Required-Stop: $null
# Default-Start: $null
# Default-Stop: $null
### END INIT INFO

case "$1" in
    start)
        ;;

    stop)
        . /etc/platform/platform.conf
        if [[ "$subfunction" == "controller,worker"* ]]; then
            # Trigger logout of iSCSI connections to avoid shutdown race condition
            /sbin/iscsiadm -m node --logoutall=all
        fi
        touch /var/run/.sm_node_unhealthy

        date >> /var/log/sm-shutdown.log
        echo "Shutdown SM." >> /var/log/sm-shutdown.log

        sleep 5
        ;;

    status)
        ;;

    restart)
        ;;

    reload)
        ;;

    force-reload)
        ;;

    *)
esac

