#!/bin/sh
# $Header: S77netbackup.sh,v 1.11 2002/08/28 13:42:23 djs Stab $
#
#bcpyrght
#***************************************************************************
#* $VRTScprght: Copyright 1993 - 2002 VERITAS Software Corporation, All Rights Reserved $ *
#***************************************************************************
#ecpyrght
#
# S77netbackup.sh
#
# This is a sample script that can be copied to the correct system startup
# directory (e.g./etc/rc2.d) to automatically start the NetBackup request
# daemon at system initiation.
# It also starts the Media Manager device daemon (ltid).
#
# Note - when the Media Manager device daemon (ltid) is started, it automatically
# starts the Media Manager volume daemon (/usr/openv/volmgr/bin/vmd) and robotic
# daemons as required.

VMPS=/usr/openv/volmgr/bin/vmps
BPPS=/usr/openv/netbackup/bin/bpps
LTID=/usr/openv/volmgr/bin/ltid 
BPRD=/usr/openv/netbackup/bin/initbprd
VISD=/usr/openv/netbackup/bin/visd
NBDBDMON=/usr/openv/netbackup/bin/admincmd/nbdbdmon
MAKE_SCSI_DEV=/usr/openv/volmgr/bin/make_scsi_dev

TMPF=/tmp/active_ovVM_processes
/bin/rm -f $TMPF
$VMPS > $TMPF

if [ -f "$LTID" ]
then
	ltid=`grep ltid $TMPF`
	# Don't start ltid if already started by HSM startup script.
	if test Y"$ltid" = Y
	then
		if [ -f ${MAKE_SCSI_DEV} -a "`uname -s`" = "Linux" ] ; then
			echo "Rebuilding device nodes." > /dev/console
			$MAKE_SCSI_DEV
		fi
		$LTID
		echo "Media Manager daemons started." > /dev/console
	fi
else
	echo "Media Manager daemons not started." > /dev/console
fi

/bin/rm -f $TMPF

if [ -f "$BPRD" ]
then
	$BPRD
	echo "NetBackup request daemon started." > /dev/console
else
	echo "NetBackup request daemon not started." > /dev/console
fi


# if nbdbd is installed, try to start up nbdbd and visd
if [ -x "${NBDBDMON}" ]; then
    # Wait a little for nbdbd to come up, before starting visd
    wait=0
    $BPPS > $TMPF
    nbdbd=`grep nbdbd $TMPF`
    while [ ${wait} -lt 3 -a "${nbdbd}" = "" ]
    do
        sleep 5
        wait=`expr ${wait} + 1`
        $BPPS > $TMPF
        nbdbd=`grep nbdbd $TMPF`
    done
    /bin/rm -f $TMPF

    # start visd if present
    if [ -x "${VISD}" ]; then
        if [ "${nbdbd}" != "" ]; then
            ${VISD} > /dev/null 2>/dev/null
            if [ $? != 0 ]; then
                echo "Global Data Manager daemon not started."
            else
                echo "Global Data Manager daemon started."
            fi
        else
            echo "Global Data Manager daemon not started."
        fi
    fi
fi

exit 0
