#! /bin/sh
#
# Copyright (C) 2000-2015 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# bacula       This shell script takes care of starting and stopping
#	       the bacula Storage daemon.
#
# chkconfig: 2345 90 9
# description: The Leading Open Source Backup Solution.
#
#  For Bacula release 9.0.8 (28 May 2018) -- suse
# Modified to work on SuSE 1/31/2004 D. Scott Barninger <barninger at fairfieldcomputers.com>
# Added rc.status functions 3/13/2004 D. Scott Barninger <barninger at fairfieldcomputers.com>
# Added LSB init info 10/14/2004 D. Scott Barninger <barninger at fairfieldcomputers.com>
#
### BEGIN INIT INFO
# Provides:			bacula-sd
# Required-Start:		$local_fs $network
# Required-Stop:		$local_fs $network
# Default-Start:		3 5
# Default-Stop: 	0 1 2 6
# Short-Description:	bacula storage daemon
# Description:			Bacula network backup system storage daemon
### END INIT INFO

# source process status functions
# this gives us funtion rc_status -v to tell us if we succeed or fail
. /etc/rc.status

RETVAL=0
case "$1" in
    start)
       echo -n "Starting the Bacula Storage daemon: "
       /sbin/startproc /opt/bacula/bin/bacula-sd $2 -c /opt/bacula/etc/bacula-sd.conf
       RETVAL=$?
       rc_status -v
       echo
       [ $RETVAL -eq 0 ] && touch /opt/bacula/working/bacula-sd
       ;;
    stop)
       echo -n "Stopping the Bacula Storage daemon: "
       /sbin/killproc /opt/bacula/bin/bacula-sd
       RETVAL=$?
       rc_status -v
       echo
       [ $RETVAL -eq 0 ] && rm -f /opt/bacula/working/bacula-sd
       ;;
    restart)
       $0 stop
       sleep 5
       $0 start
       RETVAL=$?
       ;;
    status)
       /sbin/checkproc /opt/bacula/bin/bacula-sd
       RETVAL=$?
       rc_status -v
       ;;
    *)
       echo "Usage: $0 {start|stop|restart|status}"
       exit 1
       ;;
esac
exit $RETVAL
