#! /bin/sh

#
# Copyright (c) 1990-2025, Dell Inc. or its subsidiaries. All Rights Reserved.
#
# All rights reserved.  This is an UNPUBLISHED work, and
# comprises proprietary and confidential information of EMC.
# Unauthorized use, disclosure, and distribution are strictly
# prohibited.  Use, duplication, or disclosure of the software
# and documentation by the U.S. Government is subject to
# restrictions set forth in a license agreement between the
# Government and EMC or other written agreement specifying
# the Government's rights to use the software and any applicable
# FAR provisions, such as FAR 52.227-19.
#

# description: EMC NetWorker Snapshot Management.
# Snapshot backup and restoration software package.

### BEGIN INIT INFO
# Provides: nsrps
# Required-Start: syslog network
# Required-Stop: syslog network
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: EMC NetWorker Snapshot Management
# Snapshot backup and restoration software package.
### END INIT INFO
result=0
XTDCLNT_PKG_HOME=`rpm -q --qf "%{INSTPREFIXES}\n" lgtoxtdclnt 2>/dev/null`
NWBINPATH=${XTDCLNT_PKG_HOME}/sbin
OUTPUT=/dev/console
PATH=$PATH:/usr/bin:/bin

case $1 in
'start')
cnt=`ps -ef | grep nsrpsd | grep -v grep | wc -l`
if [ ${cnt} -eq 0 ]; then
	(echo 'starting nsrpsd daemon:') >> ${OUTPUT}
	if [ -f ${NWBINPATH}/nsrpsd ]; then
		(${NWBINPATH}/nsrpsd) >> ${OUTPUT} 2>&1
		result=$?
		if [ ${result} -eq 0 ]; then
			(/bin/sleep 15)
			(echo ' nsrpsd') >> ${OUTPUT}
		else
			(echo ' Error: nsrpsd failed to start') | /usr/bin/tee -a ${OUTPUT}
		fi
	else
	  (echo "could not start nsrpsd daemon. ${NWBINPATH}/nsrpsd does not exist.") | /usr/bin/tee -a ${OUTPUT}
	  result=1
	fi
else
	#nsrpsd is already running. 10 is just a unique number
	result=10
fi
    ;;
'stop')
(echo 'stopping nsrpsd daemons:') >> ${OUTPUT}
if [ -f ${NWBINPATH}/nsrps_shutdown ]; then
	(${NWBINPATH}/nsrps_shutdown -q&) >> ${OUTPUT} 2>&1
	(echo ' nsrps_shutdown -q') >> ${OUTPUT}
else
    (echo "could not stop nsrpsd daemon. ${NWBINPATH}/nsrps_shutdown does not exist.") | /usr/bin/tee -a ${OUTPUT}
  result=1
fi

    ;;
'status')
CLNT_PKG_HOME=`rpm -q --qf "%{INSTPREFIXES}\n" lgtoclnt 2>/dev/null`
if [ -f ${CLNT_PKG_HOME}/sbin/nsr_shutdown ]; then
    (${CLNT_PKG_HOME}/sbin/nsr_shutdown -l nsrpsd) >> ${OUTPUT} 2>&1
    (echo ' nsr_shutdown -l nsrpsd') >> ${OUTPUT}
else
    (echo "could not determine the status of nsrpsd daemon. ${CLNT_PKG_HOME}/sbin/nsr_shutdown does not exist.") | /usr/bin/tee -a ${OUTPUT}
fi

	;;
*)
echo "usage: `basename $0` {start|stop|status}"
result=1
    ;;
esac

exit ${result}

