#!/bin/sh
#
# bacula	Network based backup program: director part
#
# chkconfig: - 90 21
# description:	It comes by night and sucks the vital essence from your \
# computers..
# processname: bacula-dir
# config: /etc/bacula/bacula-dir.conf
# pidfile: /var/run/bacula/bacula-dir.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

PIDFILE=/var/run/bacula/bacula-dir.pid
LOCKFILE=/var/lock/subsys/bacula-dir
LOGFILE=/var/log/bacula/log
RETVAL=0
DIRPATH=`readlink -e /usr/sbin/bacula-dir`
OPTS="-u bacula -g bacula -v -c /etc/bacula/bacula-dir.conf"

start()
{
	if [ ! -f $LOGFILE ]; then
	 touch $LOGFILE
	 chown bacula.bacula $LOGFILE
	 chmod 660 $LOGFILE
	fi
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user bacula --displayname bacula-dir -- $DIRPATH $OPTS
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user bacula --displayname bacula-dir -- $DIRPATH
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading bacula-dir
	stop_daemon --pidfile "$PIDFILE" --expect-user bacula --displayname bacula-dir -HUP -- $DIRPATH
	RETVAL=$?
	return $RETVAL
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user bacula --displayname bacula-dir -- $DIRPATH
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
