#!/sbin/openrc-run

name=dccd
_le=/var/dcc/libexec
command="$_le/start-grey"
pidfile="/run/dcc/$name.pid"
dcc_conf="/var/dcc/dcc_conf"

depend() {
	use logger
	need net          
	before mta dccifd dccm
	after firewall
}

start_pre() {
	# start-grey runs its own checks
	if [ ! -f "$command" ]; then
		ewarn "dcc-dccd is not installed"
		return 1
	fi
	if [ ! -f "$dcc_conf" ]; then            
		ewarn "Configuration file $dcc_conf not found"
		return 1
	fi 
	if [ -z $(grep "^SRVR_ID=" "$dcc_conf" | sed "s/.*=//") ]; then
		ewarn "SRVR_ID must be set in $dcc_conf"
		return 1
	fi
	if ! grep -q "^DCCD_ENABLE=on" "$dcc_conf"; then
		ewarn "DCCD_ENABLE is not set to on in $dcc_conf"
		return 1
	fi
	return 0
}

stop() {
	$_le/stop-$name -G -S
	eend $?
}

