#!/bin/sh
###############################################################################
#
#          Dell Inc. PROPRIETARY INFORMATION
# This software is supplied under the terms of a license agreement or
# nondisclosure agreement with Dell Inc. and may not
# be copied or disclosed except in accordance with the terms of that
# agreement.
#
# Copyright (c) 2000-2018 Dell Inc. All Rights Reserved.
#
# Module Name:
#
#   dataeng
#
# Abstract/Purpose:
#
#   Systems Management Data Engine System V compatability script.
#   This script is only to allow backward compatabillity for consumers who
#   who still refer to sys V init scripts.
#
# Environment:
#
#   Linux
###############################################################################

# Standard status codes for commands other than "status"
STATUS_NO_ERROR=0
STATUS_GENERIC_ERROR=1
STATUS_INVALID_ARG=2
STATUS_NOT_IMPLEMENTED=3

SNMP_PLUGIN=0
rpm -q srvadmin-deng-snmp >/dev/null 2>&1
if [ $? -eq 0 ];then
	SNMP_PLUGIN=1
fi

DATAMGRD_SERVICE="dsm_sa_datamgrd.service"
EVENTMGRD_SERVICE="dsm_sa_eventmgrd.service"
SNMPD_SERVICE="dsm_sa_snmpd.service"

DENG_SERVICE_START_LIST=""
DENG_SERVICE_STOP_LIST=""

ACTION="status"
EXIT_STATUS=0

if [ $SNMP_PLUGIN -eq 1 ]; then
	DENG_SERVICE_START_LIST="$EVENTMGRD_SERVICE $DATAMGRD_SERVICE $SNMPD_SERVICE"
	DENG_SERVICE_STOP_LIST="$SNMPD_SERVICE $DATAMGRD_SERVICE $EVENTMGRD_SERVICE"
else
	DENG_SERVICE_START_LIST="$EVENTMGRD_SERVICE $DATAMGRD_SERVICE"
	DENG_SERVICE_STOP_LIST="$DATAMGRD_SERVICE $EVENTMGRD_SERVICE"
fi

serviceCtrl()
{
	for DENG_SERVICE in ${*}
	do
		systemctl $ACTION $DENG_SERVICE
		STATUS=$?
		if [ $STATUS -ne 0 ]; then
			EXIT_STATUS=$STATUS
		fi
	done
}


###############################################################################
# Check command line parameter for action to perform
###############################################################################

case "$1" in
	start)
		ACTION="start"
		serviceCtrl $DENG_SERVICE_START_LIST
		;;

	stop)
		ACTION="stop"
		serviceCtrl $DENG_SERVICE_STOP_LIST
		;;

	restart|force-reload)
		ACTION="restart"
		serviceCtrl $DENG_SERVICE_START_LIST
		;;

	status)
		ACTION="status"
		serviceCtrl $DENG_SERVICE_START_LIST
		;;

      disable-snmp)
               
               ACTION="stop"
               serviceCtrl $SNMPD_SERVICE
               ACTION="disable"
               serviceCtrl $SNMPD_SERVICE
               ;;

      enable-snmp)

              ACTION="enable"
              serviceCtrl $SNMPD_SERVICE
              ACTION="start"
              serviceCtrl $SNMPD_SERVICE
              ;;    

	*)
		echo "Usage: ${0} {start|stop|restart|force-reload|status|disable-snmp|enable-snmp}"
		EXIT_STATUS=${STATUS_NOT_IMPLEMENTED}
		;;
esac

exit ${EXIT_STATUS}


###############################################################################
# End Script
###############################################################################
