changeset 3276:c16708f4ea04 draft

Add support for Chrony, fixes [03943daba7].
author Roy Marples <roy@marples.name>
date Mon, 07 Sep 2015 10:58:04 +0000
parents a96ee36b8905
children 088f81e0cd0c
files configure dhcpcd-hooks/50-ntp.conf
diffstat 2 files changed, 53 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Fri Sep 04 11:41:18 2015 +0000
+++ b/configure	Mon Sep 07 10:58:04 2015 +0000
@@ -1160,10 +1160,23 @@
 	NTPD=$(_which ntpd)
 	if [ -n "$NTPD" ]; then
 		echo "$NTPD (50-ntp.conf)"
-		HOOKS="$HOOKS${HOOKS:+ }50-ntp.conf"
 	else
 		echo "not found"
 	fi
+	printf "Checking for chronyd ... "
+	CHRONYD=$(_which chronyd)
+	if [ -n "$CHRONYD" ]; then
+		echo "$CHRONYD (50-ntp.conf)"
+	else
+		echo "not found"
+	fi
+	if [ -n "$NTPD" -o -n "$CHRONYD" ]; then
+		HOOKS="$HOOKS${HOOKS:+ }50-ntp.conf"
+	fi
+	# Warn if both are detected
+	if [ -n "$NTPD" -a -n "$CHRONYD" ]; then
+		echo "NTP will default to $NTPD"
+	fi
 
 	printf "Checking for ypbind ... "
 	YPBIND=$(_which ypbind)
--- a/dhcpcd-hooks/50-ntp.conf	Fri Sep 04 11:41:18 2015 +0000
+++ b/dhcpcd-hooks/50-ntp.conf	Mon Sep 07 10:58:04 2015 +0000
@@ -1,32 +1,55 @@
-# Sample dhcpcd hook script for ntp
+# Sample dhcpcd hook script for NTP
+# It will configure either one of NTP, OpenNTP or Chrony (in that order)
+# and will default to NTP if no default config is found.
+
 # Like our resolv.conf hook script, we store a database of ntp.conf files
 # and merge into /etc/ntp.conf
 
-# You can set the env var NTP_CONF to another file like this
+# You can set the env var NTP_CONF to override the derived default on
+# systems with >1 NTP client installed.
+# Here is an example for OpenNTP
 #   dhcpcd -e NTP_CONF=/usr/pkg/etc/ntpd.conf
+# or by adding this to /etc/dhcpcd.conf
+#   env NTP_CONF=/usr/pkg/etc/ntpd.conf
 # or by adding this to /etc/dhcpcd.enter-hook
 #   NTP_CONF=/usr/pkg/etc/ntpd.conf
-# to use OpenNTPD instead of the default NTP.
+# To use Chrony instead, simply change ntpd.conf to chrony.conf in the
+# above examples.
+
+: ${ntp_confs:=ntp.conf ntpd.conf chrony.conf}
+: ${ntp_conf_dirs=/etc /usr/pkg/etc /usr/local/etc}
+ntp_conf_dir="$state_dir/ntp.conf"
 
-if type invoke-rc.d >/dev/null 2>&1; then
-	# Debian has a seperate file for DHCP config to avoid stamping on
-	# the master.
+# If NTP_CONF is not set, work out a good default
+if [ -z "$NTP_CONF" ]; then
+	for d in ${ntp_conf_dirs}; do
+		for f in ${ntp_confs}; do
+			if [ -e "$d/$f" ]; then
+				NTP_CONF="$d/$f"
+				break 2
+			fi
+		done
+	done
+	[ -e "$NTP_CONF" ] || NTP_CONF=/etc/ntp.conf
+fi
+
+# Derive service name from configuration
+if [ -z "$ntp_service" ]; then
+	case "$NTP_CONF" in
+	*chrony.conf)		ntp_service=chronyd;;
+	*)			ntp_service=ntpd;;
+	esac
+fi
+
+# Debian has a seperate file for DHCP config to avoid stamping on
+# the master.
+if [ "$ntp_service" = ntpd ] && type invoke-rc.d >/dev/null 2>&1; then
 	[ -e /var/lib/ntp ] || mkdir /var/lib/ntp
 	: ${ntp_service:=ntp}
 	: ${NTP_DHCP_CONF:=/var/lib/ntp/ntp.conf.dhcp}
 fi
 
-: ${ntp_service:=ntpd}
 : ${ntp_restart_cmd:=service_condcommand $ntp_service restart}
-ntp_conf_dir="$state_dir/ntp.conf"
-
-# If we have installed OpenNTPD but not NTP then prefer it
-# XXX If both exist then update both?
-if [ -z "$NTP_CONF" -a -e /etc/ntpd.conf -a ! -e /etc/ntp.conf ]; then
-	: ${NTP_CONF:=/etc/ntpd.conf}
-else
-	: ${NTP_CONF:=/etc/ntp.conf}
-fi
 
 ntp_conf=${NTP_CONF}
 NL="