#!/sbin/openrc-run

name="$SVCNAME"
description="Name service cache daemon for musl"
command="/usr/sbin/nscd"
command_args="$NSCD_OPTS"

supervisor="supervise-daemon"
respawn_delay=2
respawn_max=5
respawn_period=60

depend() {
	use logger
}

start_pre() {
	# -d forks into the background, which supervise-daemon sees as a crash;
	# -p is redundant, supervise-daemon tracks the process itself.
	# Both were common with the previous init script, so check instead of failing later.
	local opt
	for opt in $NSCD_OPTS; do
		case "$opt" in
		-d|-p|-p*)
			eerror "Remove '-d' and '-p <file>' from NSCD_OPTS in /etc/conf.d/nscd:"
			eerror "nscd runs under supervise-daemon and must stay in the foreground"
			return 1
			;;
		esac
	done

	# musl's client connects to /var/run/nscd/socket (compiled in)
	checkpath -d -m 0755 /var/run/nscd
}
