#!/bin/sh

##############################################################################
#                                                                            #
# Copyright (c) 2011 by Idera All rights reserved                            #
#                                                                            #
##############################################################################
#
# chkconfig: 2345 99 99
# description: Righteous Software Linux Backup Agent
# processname: cdp
# config: /etc/r1soft/agent_config

### BEGIN INIT INFO
# Provides:          cdp-agent
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts R1Soft CDP Agent
# Description:       Starts R1Soft CDP Agent
# Options:           start), stop), restart), status)
### END INIT INFO

ERROR=0
case "$@" in
  start|stop|status|restart)
	OPTION=$@
	;;
  *)
	OPTION="help"
	;;
esac

INITSYSTEM=$(ps -p 1 -o comm=)
if [ "$INITSYSTEM" = "systemd" ] && [ -f /etc/systemd/system/sbm-agent.service ]; then
	systemctl --no-pager $OPTION sbm-agent.service && ERROR=0 || ERROR=1
else 
	/usr/sbin/r1soft/service-scripts/agent-service $OPTION && ERROR=0 || ERROR=1
fi
exit $ERROR
