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