#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos72L src/bos/usr/sbin/triton/scripts/daemon-stop.sh 1.5 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2014,2018 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)67        1.5  src/bos/usr/sbin/triton/scripts/daemon-stop.sh, dascache, bos72L, l2018_27B7 6/27/18 05:00:38

#set -x
rc=0
flag=0
export LANG=C
/usr/bin/ps -ef | /usr/bin/grep '/usr/sbin/pfcdaemon' | /usr/bin/grep -v 'grep' 2>&1 > /dev/null
if [ $? -eq 0 ]
then
	/usr/bin/stopsrc -s pfcdaemon
	if [ $? -ne 0 ]
	then
                rc=1
		exit $rc 
	fi
fi

i=0
while [ $i -lt 30 ]
do
     /usr/bin/lssrc -s pfcdaemon | /usr/bin/grep 'inoperative' 2>&1 > /dev/null
     if [ $? -eq 0 ]
     then
            #pfcdaemon became inoperative
         flag=0
         break;
     else
         flag=1
         sleep 10
     fi     
     ((i = i+1))
done

if [ $flag -eq 1 ]
then
    #still pfcdaemon is running.
    rc=1    
    exit $rc
fi

slibclean 
# If kernel extension is not unloaded, wait 10 sec
genkex | grep pfcdd
if [ $? -eq 0 ]
then
	i=0
	while [ $i -lt 30 ]
	do
        	sleep 10
                slibclean   
		genkex | grep pfcdd  
		if [ $? -ne 0 ]
		then
                        #Kernel extensions are unloaded.
                        rc=0
			break;
		else
                        rc=1
                fi     
		((i=$i+1))
	done
fi

exit $rc