#!/bin/bash

#       Copyright (c) Marathon Technologies Corporation, 2008.
#       All Rights Reserved. Unpublished rights reserved
#       under the copyright laws of the United States.
# 
#       The software contained on this media is proprietary
#       to and embodies the confidential technology of
#       Marathon Technologies Corporation. Possession, use,
#       duplication or dissemination of the software and
#       media is authorized only pursuant to a valid written
#       license from Marathon Technologies Corporation.
# 
#       RESTRICTED RIGHTS LEGEND Use, duplication, or
#       disclosure by the U.S. Government is subject to
#       restrictions as set forth in Subparagraph (c)(1)(ii)
#       of DFARS 252.227-7013, or in FAR 52.227-19, as
#       applicable.

. /opt/xensource/xha/ha_rc

#
#   ha_stop_daemon
#

daemon_pid=`calldaemon pid`
status=$?

if [ $status -eq $MTC_EXIT_SUCCESS ]; then
    # send SIGTERM to the daemon
    kill -15 $daemon_pid
    while true; do
        daemon_pid=`calldaemon pid`
        status=$?
        if [ $status -ne $MTC_EXIT_SUCCESS ]; then

            # one more attempt to mask any
            # transient error codes

            sleep 1
            daemon_pid=`calldaemon pid`
            status=$?
            
            break
        fi
        sleep 1
    done
fi

if [ $status -eq $MTC_EXIT_DAEMON_IS_NOT_PRESENT ]; then
    status=$MTC_EXIT_SUCCESS
fi

exit $status
