From: Roy Marples Date: Mon, 7 Sep 2015 10:58:04 +0000 (+0000) Subject: Add support for Chrony, fixes [03943daba7]. X-Git-Tag: v6.9.4~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f866bc47a9c2b0541aabdf02be7afc5ffa9b0627;p=thirdparty%2Fdhcpcd.git Add support for Chrony, fixes [03943daba7]. --- diff --git a/configure b/configure index 95ed9f07..86bcfca1 100755 --- 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) diff --git a/dhcpcd-hooks/50-ntp.conf b/dhcpcd-hooks/50-ntp.conf index 551c5bef..74805039 100644 --- a/dhcpcd-hooks/50-ntp.conf +++ b/dhcpcd-hooks/50-ntp.conf @@ -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="