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