#! /bin/sh
### BEGIN INIT INFO
# Provides:          sfcb
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Start sfcb
# Description: Start and Stop the Small Footprint CIM Broker (SFCB)
### END INIT INFO

# Author: Thierry Carrez <thierry.carrez@ubuntu.com>

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin

DESC="the small footprint CIM broker (SFCB)"
NAME=sfcb
DAEMON=/usr/sbin/sfcbd

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

if [ -z $SFCB_COMPONENT_TRACE ]; then
	OPTS="-d"
else
	OPTS="-t $SFCB_COMPONENT_TRACE -d"
fi
export SFCB_TRACE SFCB_TRACE_FILE SBLIM_TRACE SBLIM_TRACE_FILE
unset TMPDIR

# Define LSB log_* functions.
. /lib/lsb/init-functions

case "$1" in
	start)
		log_daemon_msg "Starting $DESC"
		start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- $OPTS
		log_end_msg $?
		;;

	stop)
		log_daemon_msg "Stopping $DESC"
		start-stop-daemon --stop --quiet --oknodo --retry=TERM/5/KILL/5 --exec $DAEMON
		log_end_msg $?
		;;
	status)
		status_of_proc $DAEMON $NAME && exit 0 || exit $?
		;;

	restart|force-reload)
		$0 stop && sleep 2 && $0 start
		;;

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