#!/usr/bin/env /lib/runit/invoke-run
set -e

NAME="ntp"
DAEMON=/usr/sbin/ntpd

# Exit service if DAEMON is not installed
if [ ! -x $DAEMON ]; then
	exit 161
fi

# Load defaults
[ -r /etc/default/ntp ] && . /etc/default/ntp

if [ "$IGNORE_DHCP" != "yes" ] && [ -e /run/ntp.conf.dhcp ]; then
	NTPD_OPTS="$NTPD_OPTS -c /run/ntp.conf.dhcp"
fi

# Getting user:group of ntp user
UGID=$(getent passwd ntp | cut -f 3,4 -d:)
if [ -z "$UGID" ]; then
    exit 161
fi
NTPD_OPTS="$NTPD_OPTS -u $UGID"

#~ # stop other daemons
#~ pkill "ntpd"

exec 2>&1

exec $DAEMON -n ${NTPD_OPTS} >/dev/null 
