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