#!/usr/bin/openrc-run

# TODO: code cleanup, ensure clock sync on start

command="/usr/bin/ntpd"
command_args="${OPENNTPD_ARGS}"
pidfile="/run/${SVCNAME}.pid"

depend() {
	need net
	provide ${SVCNAME} ntp
}

start()
{
	ebegin "Starting \"${SVCNAME}\""
        [ -d /var/lib/ntp ] || mkdir -p /var/lib/ntp
	start-stop-daemon --start --exec "${command}" --make-pidfile \
		--pidfile "${pidfile}" --background -- "${command_args}"
	eend $?
	return $?
}

stop()
{
	ebegin "Stopping \"${SVCNAME}\""
	start-stop-daemon --stop --exec "${command}" --retry SIGTERM/10 \
		--pidfile "${pidfile}"
	eend $?
}
