]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add support for Chrony, fixes [03943daba7].
authorRoy Marples <roy@marples.name>
Mon, 7 Sep 2015 10:58:04 +0000 (10:58 +0000)
committerRoy Marples <roy@marples.name>
Mon, 7 Sep 2015 10:58:04 +0000 (10:58 +0000)
configure
dhcpcd-hooks/50-ntp.conf

index 95ed9f07a65b85a1e53044a48cd82908adade27d..86bcfca1bb1fcd7a8ad1f4f0868459bb59831c38 100755 (executable)
--- a/configure
+++ b/configure
@@ -1160,10 +1160,23 @@ if ! $HOOKSET; then
        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)
index 551c5befdde20d990869476a53c63ad318cfdf4e..7480503961d3c40bed0b5b9dd7280e9b7a0d6fab 100644 (file)
@@ -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 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
 
-if type invoke-rc.d >/dev/null 2>&1; then
-       # Debian has a seperate file for DHCP config to avoid stamping on
-       # the master.
+# 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="