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