4695cf0
#!/bin/bash
4695cf0
#
4695cf0
# bacula-dir    This shell script takes care of starting and stopping
4695cf0
#               the bacula-dir daemon, the backup director controling
4695cf0
#               the backup jobs.
4695cf0
#
4695cf0
# chkconfig: - 80 20
4695cf0
# description: Bacula-dir is the Backup-server, which is the program \
4695cf0
#              that schedules backups and controls the bacula-client and \
4695cf0
#              the bacula-storage daemons.
4695cf0
# processname: bacula-dir
4695cf0
# config: /etc/bacula/bacula-dir.conf
4695cf0
# pidfile: /var/run/bacula-dir.9101.pid
4695cf0
4695cf0
# Source function library.
4695cf0
. /etc/init.d/functions
4695cf0
4695cf0
# Source configuration.
4695cf0
if [ -f /etc/sysconfig/bacula-dir ] ; then
4695cf0
        . /etc/sysconfig/bacula-dir
4695cf0
fi
4695cf0
4695cf0
RETVAL=0
4695cf0
prog="bacula-dir"
4695cf0
CONFIG="/etc/bacula/bacula-dir.conf"
4695cf0
OPTS="-c $CONFIG"
4695cf0
4695cf0
checkconf() {
4695cf0
	# Check if we still have our @@PLACEHOLDERS@@ in the config.
4695cf0
	# If yes, refuse to start, the user has never touched the config.
4695cf0
	grep -q '^[^#].*_PASSWORD@@' $CONFIG
4695cf0
	if [ $? -eq 0 ]; then
4695cf0
		echo -n "Error: Not been configured"
4695cf0
		echo_failure
4695cf0
		echo
4695cf0
		exit 1
4695cf0
	fi
4695cf0
}
4695cf0
4695cf0
4695cf0
checkdatabase() {
4695cf0
	# First, get the currently selected database backend from the
4695cf0
	# alternatives system.
4695cf0
	DB=$(LANG=C alternatives --display bacula-dir | grep 'link currently points to' | awk -F. '{ print $2 }')
4695cf0
	case "$DB" in
4695cf0
		sqlite)
4695cf0
			# No check needed to see if the Database is running
4695cf0
			;;
4695cf0
		mysql)
4695cf0
			# Check if mysqld is running
4695cf0
			service mysqld status > /dev/null 2>&1
4695cf0
			if [ $? -ne 0 ]; then
4695cf0
				echo -n "Error: MySQL not running"
4695cf0
				echo_failure
4695cf0
				echo
4695cf0
				exit 1
4695cf0
			fi
4695cf0
			;;
4695cf0
		postgresql)
4695cf0
			# Check if postgresql is running
4695cf0
			service postgresql status > /dev/null 2>&1
4695cf0
			if [ $? -ne 0 ]; then
4695cf0
				echo -n "Error: PostgreSQL not running"
4695cf0
				echo_failure
4695cf0
				echo
4695cf0
				exit 1
4695cf0
			fi
4695cf0
			;;
4695cf0
		*)
4695cf0
			echo -n "Error: Unknown database backend"
4695cf0
			echo_failure
4695cf0
			echo
4695cf0
			exit 1
4695cf0
			;;
4695cf0
	esac
4695cf0
}
4695cf0
4695cf0
start() {
4695cf0
	echo -n "Starting $prog: "
4695cf0
	checkconf
4695cf0
#	Removed for now, as the db might not be on localhost
4695cf0
#	checkdatabase
4695cf0
	daemon $prog $OPTS
4695cf0
	RETVAL=$?
4695cf0
	echo
4695cf0
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
4695cf0
	return $RETVAL
4695cf0
}	
4695cf0
4695cf0
stop() {
4695cf0
	echo -n "Shutting down $prog: "
4695cf0
	killproc $prog
4695cf0
	RETVAL=$?
4695cf0
	echo
4695cf0
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
4695cf0
	return $RETVAL
4695cf0
}
4695cf0
4695cf0
case "$1" in
4695cf0
    start)
4695cf0
		start
4695cf0
		;;
4695cf0
    stop)
4695cf0
		stop
4695cf0
		;;
4695cf0
    status)
4695cf0
		status $prog
4695cf0
		;;
4695cf0
    restart)
4695cf0
    	stop
4695cf0
		start
4695cf0
		RETVAL=$?
4695cf0
		;;
4695cf0
    reload)
4695cf0
		;;
4695cf0
    condrestart)
4695cf0
		if [ -f /var/lock/subsys/$prog ]; then
4695cf0
			stop
4695cf0
			start
4695cf0
			RETVAL=$?
4695cf0
		fi
4695cf0
		;;
4695cf0
    *)
4695cf0
	echo "Usage: $prog {start|stop|status|reload|restart}"
4695cf0
	exit 1
4695cf0
	;;
4695cf0
esac
4695cf0
exit $?