#!/bin/sh
# Copyright (c) 2005-2006 Novell, Inc.  All rights reserved.
#
# Author: Ryan Okelberry
#
# /etc/init.d/novell-bcc
#
#   and its symbolic link
#
# /usr/sbin/rcnovell-bcc
#
### BEGIN INIT INFO
# Provides:       novell-bcc
# Required-Start: $network $syslog novell-ncs namcd sfcb
# Required-Stop:  $null
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Start Novell Business Continuity Cluster Services
### END INIT INFO

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num>
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
. /etc/rc.status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
# 
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.

NOVELL_BCCD=/opt/novell/bcc/sbin/bccd

# To load BCC in debug (verbose) mode, add the -v switch to NOVELL_BCCD_ARGS
# To load BCC in tracing mode, add the -t switch to NOVELL_BCCD_ARGS
# For example:
# NOVELL_BCCD_ARGS=-v
# NOVELL_BCCD_ARGS=-t
# NOVELL_BCCD_ARGS=-vt
# Note: BCC should not be ran permanently in debug or tracing mode.
NOVELL_BCCD_ARGS=

# Enabling core dumps can be very helpful when logging support instances.
# Uncomment the following five lines to enabled core generation when BCCD crashes.
#CORE_FILE_DIR="/tmp/corefiles"
#CORE_FILE_PATTERN="%h-%e-%t.core" # see manual page core(5) for pattern details
#mkdir -p $CORE_FILE_DIR
#echo "${CORE_FILE_DIR}/${CORE_FILE_PATTERN}" > /proc/sys/kernel/core_pattern
#ulimit -c unlimited

case "$1" in
    start)
		echo -n "Starting service Novell Business Continuity Cluster"
		# Is bcc already running? If so, exit gracefully?
		checkproc $NOVELL_BCCD && echo -n -e "\nService Novell Business Continuity Cluster is already running" && \
		rc_status -v && rc_exit
	
		$NOVELL_BCCD $NOVELL_BCCD_ARGS
	
		rc_status -v
		;;

    stop)
		echo -n "Shutting down service Novell Business Continuity Cluster"
		killproc -t 15 -TERM $NOVELL_BCCD
	
		rc_status -v
		;;

    restart)
		echo "Restarting service Novell Business Continuity Cluster"
		$0 stop
		$0 start

		rc_status
		;;

    status)
		echo -n "Checking for service Novell Business Continuity Cluster: "
		## Check status with checkproc(8), if process is running
		## checkproc will return with exit status 0.

		# Status has a slightly different for the status command:
		# 0 - service running
		# 1 - service dead, but /var/run/  pid  file exists
		# 2 - service dead, but /var/lock/ lock file exists
		# 3 - service not running

		# NOTE: checkproc returns LSB compliant status values.
		checkproc $NOVELL_BCCD
		rc_status -v
		;;

    *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
	;;
esac
rc_exit

