#!/bin/sh
#
# chkconfig:	345 91 35
# description:	Starts and stops the Samba smbd and nmbd daemons \
#		used to provide SMB network services.
#
# config:	/etc/samba/smb.conf
# config:	/etc/samba/lmhosts

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

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

# Source networking configuration.
. /etc/sysconfig/network

# Demon specified configuration.
. /etc/sysconfig/samba

# Check that networking is up.
if is_no "${NETWORKING}"; then
        msg_Network_Down smb
        exit 1
fi

TMPDIR="/tmp"; export TMPDIR

# Check that smb.conf exists.
[ -f /etc/samba/smb.conf ] || exit 0

# See how we were called.
case "$1" in
  start)
        # Check if the service is already running?
        if [ ! -f /var/lock/subsys/smb ]; then
                msg_starting smbd
                daemon $NICELEVEL smbd -D
                msg_starting nmbd
                daemon $NICELEVEL nmbd -D
		if [ "$WINBINDD" = "yes" ]; then
			msg_starting winbindd
			daemon $NICELEVEL winbindd
		fi
                RETVAL=$?
                [ $RETVAL -eq 0 ] && touch /var/lock/subsys/smb
        else
                msg_Already_Running smb
                exit 1
        fi
	;;
  stop)
        # Stop daemons.
        if [ -f /var/lock/subsys/smb ]; then
                msg_stopping smbd
                killproc smbd
                msg_stopping nmbd
		killproc nmbd
		if [ "$WINBINDD" = "yes" ]; then
			msg_stopping winbindd
			killproc winbindd
		fi
                rm -f /var/lock/subsys/smb >/dev/null 2>&1
        else
                msg_Not_Running smb
                exit 1
        fi
	;;
  status)
	status smbd
	status nmbd
	status winbindd
	smbstatus
	exit $?
	;;
  restart)
	$0 stop
	$0 start
	;;
  reload)
	if [ -f /var/lock/subsys/smb ]; then
	        msg_reloading smb
	        killproc smbd -HUP
	else
	        msg_Not_Running smb
	        exit 1
        fi
	;;
  *)
	msg_Usage "$0 {start|stop|restart|reload|status}"
	exit 1
esac

exit $RETVAL
