#!/bin/sh
# Begin $rc_base/init.d/samba

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org

. /etc/sysconfig/rc
. $rc_functions

function fix_permissions() {
	local lockdir="/var/lib/samba/winbindd_privileged"

	chmod 750 "${lockdir}"
	chgrp wbpriv "${lockdir}"
}

case "$1" in
	start)
		fix_permissions

		boot_mesg "Starting nmbd..."
		loadproc /usr/sbin/nmbd -D

		boot_mesg "Starting smbd..."
		loadproc /usr/sbin/smbd -D

		boot_mesg "Starting winbind..."
		loadproc /usr/sbin/winbindd
		;;

	stop)
		boot_mesg "Stopping smbd..."
		killproc -p /var/run/smbd.pid /usr/sbin/smbd

		boot_mesg "Stopping nmbd..."
		killproc -p /var/run/nmbd.pid /usr/sbin/nmbd

		boot_mesg "Stopping winbind..."
		killproc -p /var/run/winbindd.pid /usr/sbin/winbindd
                ;;

	reload)
		boot_mesg "Reloading smbd..."
		reloadproc /usr/sbin/smbd

		boot_mesg "Reloading nmbd..."
		reloadproc /usr/sbin/nmbd

		boot_mesg "Reloading winbind..."
		reloadproc /usr/sbin/winbindd
		;;

	restart)
		$0 stop
		sleep 3
		$0 start
		;;

	status)
		statusproc /usr/sbin/nmbd
		statusproc /usr/sbin/smbd
		statusproc /usr/sbin/winbindd
		;;

	*)
		echo "Usage: $0 {start|stop|reload|restart|status}"
		exit 1
		;;
esac

# End $rc_base/init.d/samba
