From 32ddaae7a5bb331822ffbd3560c4096c36992b1a Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Tue, 10 May 2016 11:00:51 +0100 Subject: [PATCH] replace chronyd with sntpc, sync every 15s not 15m Signed-off-by: Justin Cormack --- alpine/Dockerfile | 6 +- alpine/packages/chronyd/etc/init.d/chronyd | 73 ---------------------- alpine/packages/docker/etc/init.d/docker | 1 - alpine/packages/sntpc/etc/conf.d/sntpc | 2 + alpine/packages/sntpc/etc/init.d/sntpc | 35 +++++++++++ 5 files changed, 40 insertions(+), 77 deletions(-) delete mode 100755 alpine/packages/chronyd/etc/init.d/chronyd create mode 100644 alpine/packages/sntpc/etc/conf.d/sntpc create mode 100755 alpine/packages/sntpc/etc/init.d/sntpc diff --git a/alpine/Dockerfile b/alpine/Dockerfile index ed52e428a..839064631 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -9,7 +9,7 @@ RUN \ apk update && apk upgrade && \ apk add \ e2fsprogs \ - chrony \ + sntpc \ git \ xz \ iptables \ @@ -62,7 +62,7 @@ COPY packages/hvtools/hv_get_dhcp_info /sbin/ COPY packages/hvtools/hv_get_dns_info /sbin/ COPY packages/hvtools/hv_set_ifconfig /sbin/ COPY packages/hvtools/hvtools.tar.gz /usr/share/src/ -COPY packages/chronyd/etc /etc/ +COPY packages/sntpc/etc /etc/ COPY packages/userns/etc /etc/ COPY packages/userns/groupadd /usr/sbin COPY packages/userns/useradd /usr/sbin @@ -82,7 +82,7 @@ RUN \ rc-update add syslog boot && \ rc-update add networking boot && \ rc-update add acpid default && \ - rc-update add chronyd default && \ + rc-update add sntpc default && \ rc-update add cron default && \ rc-update add savecache shutdown && \ rc-update add killprocs shutdown && \ diff --git a/alpine/packages/chronyd/etc/init.d/chronyd b/alpine/packages/chronyd/etc/init.d/chronyd deleted file mode 100755 index 5cd0d5df6..000000000 --- a/alpine/packages/chronyd/etc/init.d/chronyd +++ /dev/null @@ -1,73 +0,0 @@ -#!/sbin/openrc-run -# Copyright 1999-2007 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/net-misc/chrony/files/chronyd.rc,v 1.8 2007/03/22 14:32:09 tove Exp $ - -description="NTP daemon" - -depend() { - need net - after firewall - provide ntp-client ntp-server - use dns -} - -checkconfig() { - # Note that /etc/chrony/chrony.keys is *NOT* checked. This - # is because the user may have specified another key - # file, and we don't want to force the user to use that - # exact name for the key file. - if [ ! -f "${CFGFILE}" ] ; then - eerror "Please create ${CFGFILE} and the" - eerror "chrony key file (usually /etc/chrony/chrony.keys)" - eerror "by using the" - eerror "" - eerror " chrony.conf.example" - eerror " chrony.keys.example" - eerror "" - eerror "files (from the documentation directory)" - eerror "as templates." - return 1 - else - # Actually, I tried it, and chrony seems to ignore the pidfile - # option. I'm going to leave it here anyway, since you never - # know if it might be handy - PIDFILE=`awk '/^ *pidfile/{print $2}' "${CFGFILE}"` - fi - return 0 -} - -setxtrarg() { - if [ -c /dev/rtc ]; then - grep -q '^rtcfile' "${CFGFILE}" && ARGS="${ARGS} -s" - fi - grep -q '^dumponexit$' "${CFGFILE}" && ARGS="${ARGS} -r" - return 0 -} - -start() { - [ -d /sys/bus/vmbus ] && exit 0 - checkconfig || return $? - setxtrarg - - [ -n "${PIDFILE}" ] || PIDFILE=/var/run/chronyd.pid - - ebegin "Starting chronyd" - start-stop-daemon --start --quiet \ - --exec /usr/sbin/chronyd \ - --pidfile "${PIDFILE}" \ - -- -f "${CFGFILE}" ${ARGS} - eend $? "Failed to start chronyd" -} - -stop() { - [ -d /sys/bus/vmbus ] && exit 0 - checkconfig || return $? - - [ -n "${PIDFILE}" ] || PIDFILE=/var/run/chronyd.pid - - ebegin "Stopping chronyd" - start-stop-daemon --stop --quiet \ - --pidfile "${PIDFILE}" - eend $? "Failed to stop chronyd" -} diff --git a/alpine/packages/docker/etc/init.d/docker b/alpine/packages/docker/etc/init.d/docker index 4de8d0e6d..3e166eddd 100755 --- a/alpine/packages/docker/etc/init.d/docker +++ b/alpine/packages/docker/etc/init.d/docker @@ -3,7 +3,6 @@ depend() { after transfused - before chronyd } start() diff --git a/alpine/packages/sntpc/etc/conf.d/sntpc b/alpine/packages/sntpc/etc/conf.d/sntpc new file mode 100644 index 000000000..6b7f51fc3 --- /dev/null +++ b/alpine/packages/sntpc/etc/conf.d/sntpc @@ -0,0 +1,2 @@ +SNTPC_INTERVAL=15 +SNTPC_HOST=0.pool.ntp.org diff --git a/alpine/packages/sntpc/etc/init.d/sntpc b/alpine/packages/sntpc/etc/init.d/sntpc new file mode 100755 index 000000000..b3ec1b171 --- /dev/null +++ b/alpine/packages/sntpc/etc/init.d/sntpc @@ -0,0 +1,35 @@ +#!/sbin/openrc-run + +NAME=sntpc +DAEMON=/usr/sbin/$NAME + +depend() { + need net + after firewall +} + +start() { + # Windows has pvclock, not needed + [ -d /sys/bus/vmbus ] && exit 0 + + local msg opts + if [ "$SNTPC_INTERVAL" = "0" ]; then + msg="Setting time from NTP source" + else + msg="Starting ${NAME}" + opts="-d" + fi + ebegin "$msg" + start-stop-daemon --start --quiet --name sntpc \ + --exec ${DAEMON} -- \ + -i ${SNTPC_INTERVAL} $opts ${SNTPC_HOST} + eend $? +} + +stop() { + [ -d /sys/bus/vmbus ] && exit 0 + ebegin "Stopping ${NAME}" + start-stop-daemon --stop --quiet \ + --exec ${DAEMON} + eend $? +}