#!/usr/bin/openrc-run

. /opt/etc/functions.openrc

command="winbindd"
command_args="${WINBINDD_ARGS}"
pidfile="/var/run/winbindd-monitor.pid"
extra_started_commands="reload"
MONITOR="/opt/bin/autorestart"

depend()
{
	use nmbd
	need net ntp dns
	provide ${SVCNAME}
}

do_start() {
	start-stop-daemon --background --pidfile ${pidfile} --make-pidfile \
			--start --exec ${MONITOR} -- ${command} 1 3 --- ${command_args}
}

do_stop() {
	if [ -f ${pidfile} ]; then
		start-stop-daemon --stop --exec ${MONITOR} --retry SIGTERM/5 --pidfile ${pidfile}
		[ -f ${pidfile} ] && rm ${pidfile}
		killem ${command} 'init.d'
	fi
}

start() {
	local _rd="/var/run/samba/winbindd"
	ebegin "Starting \"${SVCNAME}\""
	[ -d ${_rd} ] || mkdir -p ${_rd}
	do_start
	_rc=$?
	eend ${_rc}
	return ${_rc}
}

stop() {
	ebegin "Stopping service \"${SVCNAME}\""
	do_stop
	eend 0
	return 0
}

reload() {
	kill -HUP $(cat ${pidfile})
}

hardkick() {
	do_stop
	do_start
}
