#! /bin/sh
#
# bareos       This shell script takes care of starting and stopping
#	       the bareos File daemon.
#
# chkconfig: 2345 91 9
# description: Backup Archiving REcovery Open Sourced.
#
#  For Bareos release 17.2.4 (21 Sep 2017) -- redhat
#

# Source function library
. /etc/rc.d/init.d/functions

FD_USER=root
FD_GROUP=bareos
FD_OPTIONS=''
OS=`uname -s`

# if /lib/tls exists, force Bareos to use the glibc pthreads instead
if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then
     export LD_ASSUME_KERNEL=2.4.19
fi

# pull in any user defined FD_OPTIONS, FD_USER, FD_GROUP
[ -f /etc/sysconfig/bareos ] && . /etc/sysconfig/bareos

#
# Disable Glibc malloc checks, it doesn't help and it keeps from getting
#   good dumps
MALLOC_CHECK_=0
export MALLOC_CHECK_

RETVAL=0
case "$1" in
    start)
       if [ "${FD_GROUP}" != '' ]; then
	  FD_OPTIONS="${FD_OPTIONS} -g ${FD_GROUP}"
       fi
       echo -n "Starting Bareos File services: "
       daemon --user ${FD_USER} /usr/sbin/bareos-fd $2 ${FD_OPTIONS}
       RETVAL=$?
       echo
       [ $RETVAL -eq 0 ] && touch /var/lock/bareos-fd
       ;;
    stop)
       echo -n "Stopping Bareos File services: "
       killproc /usr/sbin/bareos-fd
       RETVAL=$?
       echo
       [ $RETVAL -eq 0 ] && rm -f /var/lock/bareos-fd
       ;;
    restart)
       $0 stop
       sleep 5
       $0 start
       ;;
    status)
       status /usr/sbin/bareos-fd
       RETVAL=$?
       ;;
    *)
       echo "Usage: $0 {start|stop|restart|status}"
       exit 1
       ;;
esac
exit $RETVAL
