#!/bin/sh
#
# Start/stops the winbindd daemon.
#
#

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

[ -r /etc/default/winbind ] && . /etc/default/winbind

DAEMON=/usr/sbin/winbindd

# clear conflicting settings from the environment
unset TMPDIR

# See if the daemon is there
test -x $DAEMON || exit 0

. /lib/lsb/init-functions

case "$1" in
	start)
		log_daemon_msg "Starting the Winbind daemon" "winbind"

		mkdir -p /var/run/samba/winbindd_privileged || return 1
		chgrp winbindd_priv /var/run/samba/winbindd_privileged/ || return 1
		chmod 0750 /var/run/samba/winbindd_privileged/ || return 1
		start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- $WINBINDD_OPTS

		log_end_msg $?
		;;

	stop)
		log_daemon_msg "Stopping the Winbind daemon" "winbind"
		start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
		log_end_msg $?
		;;

	restart|force-reload)
		$0 stop && sleep 2 && $0 start
		;;

	*)
		echo "Usage: /etc/init.d/winbind {start|stop|restart|force-reload}"
		exit 1
		;;
esac
