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