Mini Shell

Direktori : /opt/dell/srvadmin/sbin/
Upload File :
Current File : //opt/dell/srvadmin/sbin/srvadmin-services.sh

#!/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.
#
# Abstract/Purpose:
#
#   This Script will start/stop/restart/status all the services installed
#   by Systems Management.
#
###############################################################################

# ensure sbin utilities are available in path, so that su will also work
export PATH="/usr/kerberos/sbin:/usr/local/sbin:/sbin:/usr/sbin:${PATH}"
exit_status=0

# Include CheckSystemType so that support for server generation can be checked

if [ ! -f "/opt/dell/srvadmin/sbin/CheckSystemType" ]; then
echo "File /opt/dell/srvadmin/sbin/CheckSystemType not found"
exit 1
fi

. "/opt/dell/srvadmin/sbin/CheckSystemType"

# Server Administrator package prefix
SRVADMIN_STR="Server Administrator"

# checks if OS init system is systemd or initd
IS_SYSTEMD=1
ps --no-headers -o comm 1 | grep -i systemd >/dev/null 2>&1
if [ $? -ne 0 ]; then
	IS_SYSTEMD=0
fi

# list of services start and status
# Maintain the order of the services
if [ ${IS_SYSTEMD} -eq 1 ]; then
	arrayStart=(instsvcdrv dsm_sa_eventmgrd dsm_sa_datamgrd dsm_sa_snmpd dsm_om_connsvc)
	arrayStatus=(instsvcdrv dsm_sa_datamgrd dsm_sa_eventmgrd dsm_sa_snmpd dsm_om_connsvc)
else
	arrayStart=(instsvcdrv dataeng dsm_om_connsvc)
	arrayStatus=(instsvcdrv dataeng dsm_om_connsvc)
fi

# list of services to stop
arrayStop=($(printf '%s\n' "${arrayStart[@]}" | tac | tr '\n' ' '))


# include DSM SA Shared service in start/stop/status array when it is enabled
checkDSMSharedService()
{
	if [ ${IS_SYSTEMD} -eq 1 ]; then
		systemctl is-enabled dsm_om_shrsvc.service >/dev/null 2>&1
	else
		if [ -x /sbin/chkconfig ]; then
			/sbin/chkconfig dsm_om_shrsvc >/dev/null 2>&1
		fi
	fi

	if [ $? -eq 0 ]; then
		arrayStart+=('dsm_om_shrsvc')
		arrayStop+=('dsm_om_shrsvc')
		arrayStatus+=('dsm_om_shrsvc')
	fi
}

#
# start/stop/status for multiple services
#
serviceAction()
{
	action=$1
	shift
	services=$@
	status=0
	for svc in $services; do
		if [ ${IS_SYSTEMD} -eq 1 ]; then
			systemctl list-unit-files $svc.service | grep $svc.service >/dev/null 2>&1
			#systemctl is-enabled $svc.service >/dev/null 2>&1
			if [ $? -eq 0 ]; then
				systemctl $action $svc.service
			fi
		elif [ -e /etc/init.d/$svc ] && [ -x /sbin/chkconfig ]; then
			/sbin/chkconfig $svc >/dev/null 2>&1
			if [ $? -eq 0 ]; then
				/etc/init.d/$svc $action
			fi
		fi

		if [ $? -ne 0 ]; then
			status=1;
		fi
	done

	# status is 1 if any service action exit code is not 0 else 0
	return $status
}

#
# enable/disable multiple services
#
serviceCtl ()
{
	ctl=$1
	shift
	services=$@
	status=0
	for svc in $services
	do
		case $ctl in
			enable|disable)
				systemctl $ctl $svc.service >/dev/null 2>&1
				;;
			on|off)
				/sbin/chkconfig $svc $ctl >/dev/null 2>&1
				;;
			status)
				if [ ${IS_SYSTEMD} -eq 1 ]; then
					systemctl is-enabled $svc.service >/dev/null 2>&1
				else
					/sbin/chkconfig $svc >/dev/null 2>&1
				fi
				if [ $? -eq 0 ]; then
					echo "$svc: enabled"
				else
					status=1
					echo "$svc: disabled"
				fi
				;;
			*)
				;;
		esac
	done

	# status is 1 if any service is disabled else 0
	return $status
}

##
## Usage
##
Usage()
{
	cat << EOF
Usage: srvadmin-services.sh {start|stop|status|restart|enable|disable|is-enabled|help}
Options:
start      : starts ${SRVADMIN_STR} services
stop       : stops ${SRVADMIN_STR} services
status     : display status of ${SRVADMIN_STR} services
restart    : restart ${SRVADMIN_STR} services
enable     : enable ${SRVADMIN_STR} services in runlevels 2, 3 and 5
disable    : disable ${SRVADMIN_STR} services in runlevels 2, 3 and 5
is-enabled : checks whether ${SRVADMIN_STR} services is enabled or not
help       : displays this help text
EOF
}

# make sure services dont busy out any mountpoints
pushd / >/dev/null 2>&1

# check for root privileges
if [ ${UID} -ne 0 ]; then
	echo "This utility requires root privileges"
	popd >/dev/null 2>&1
	exit 1
fi

# add or remove shared service from list
checkDSMSharedService

action=$1
shift

# Note the ${@:- ... } set up this way so that we either stop/start/etc full
# set of services, or specific service if passed. ${@} is set to cmdline
# params. If these are not set, then the stuff after :- is used as a default.
case $action in
	start)
	    IsThisSupportedGeneration
        retVal=$?
        if [ $retVal -eq 2 ] 
        then
	      echo "Unsupported Server... ${SRVADMIN_STR} Services not started"
          exit_status=1
        else
		  serviceAction start ${@:-${arrayStart[*]}}
        fi
		;;
	stop)
		serviceAction stop ${@:-${arrayStop[*]}}
		;;
	status)
		serviceAction status ${@:-${arrayStatus[*]}}
		exit_status=$?
		;;
	restart)
		IsThisSupportedGeneration
        retVal=$?
        if [ $retVal -eq 2 ] 
        then
	      echo "Unsupported Server... ${SRVADMIN_STR} Services not restarted"
          serviceAction stop ${@:-${arrayStop[*]}}
          exit_status=1
        else
		  serviceAction stop ${@:-${arrayStop[*]}}
		  serviceAction start ${@:-${arrayStart[*]}}
        fi
		;;
	enable)
		arrayStatus=( "${arrayStatus[*]#dsm_om_shrsvc}" )
		if [ ${IS_SYSTEMD} -eq 1 ]; then
	        serviceCtl enable ${@:-${arrayStatus[*]}}
		else
			serviceCtl on ${@:-${arrayStatus[*]}}
		fi
		;;
	disable)
		arrayStatus=( "${arrayStatus[*]#dsm_om_shrsvc}" )
		if [ ${IS_SYSTEMD} -eq 1 ]; then
			serviceCtl disable ${@:-${arrayStatus[*]}}
		else
			serviceCtl off ${@:-${arrayStatus[*]}}
		fi
		;;
	is-enabled)
		arrayStatus=( "${arrayStatus[*]#dsm_om_shrsvc}" )
		serviceCtl status ${@:-${arrayStatus[*]}}
		exit_status=$?
		;;
	help)
		Usage
		;;
	*)
		[ -z "${action}" ] || echo -e "Invalid option '${action}', please see the usage below\n"
		Usage
		exit_status=1
		;;
esac

popd >/dev/null 2>&1
exit $exit_status


Zerion Mini Shell 1.0