[ntp] drop SysV init scripts (#697526, #714705)

Miroslav Lichvar mlichvar at fedoraproject.org
Wed Jul 20 11:24:19 UTC 2011


commit 8e94a9a850a063bc547b5e49ab576b6999cbe1be
Author: Miroslav Lichvar <mlichvar at redhat.com>
Date:   Wed Jul 20 12:30:36 2011 +0200

    drop SysV init scripts (#697526, #714705)

 ntp.spec        |   11 ++----
 ntpd.init       |   87 -------------------------------------------------
 ntpdate.init    |   96 -------------------------------------------------------
 ntpdate.service |    2 +-
 ntpdate.wrapper |   36 ++++++++++++++++++++
 5 files changed, 41 insertions(+), 191 deletions(-)
---
diff --git a/ntp.spec b/ntp.spec
index e0ab758..1aa5e96 100644
--- a/ntp.spec
+++ b/ntp.spec
@@ -33,12 +33,11 @@ Group: System Environment/Daemons
 Source0: http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-%{version}.tar.gz
 Source1: ntp.conf
 Source2: ntp.keys
-Source3: ntpd.init
 Source4: ntpd.sysconfig
 # http://people.redhat.com/rkeech/#ntpstat
 Source5: ntpstat-0.2.tgz
 Source6: ntp.step-tickers
-Source7: ntpdate.init
+Source7: ntpdate.wrapper
 Source8: ntp.cryptopw
 Source9: ntpdate.sysconfig
 Source10: ntp.dhclient
@@ -248,7 +247,7 @@ find $RPM_BUILD_ROOT%{ntpdocdir} -type f | xargs chmod 644
 find $RPM_BUILD_ROOT%{ntpdocdir} -type d | xargs chmod 755
 
 pushd $RPM_BUILD_ROOT
-mkdir -p .%{_sysconfdir}/{ntp/crypto,sysconfig,dhcp/dhclient.d} .%{_initrddir}
+mkdir -p .%{_sysconfdir}/{ntp/crypto,sysconfig,dhcp/dhclient.d} .%{_libexecdir}
 mkdir -p .%{_localstatedir}/{lib/ntp,log/ntpstats} ./lib/systemd/system
 touch .%{_localstatedir}/lib/ntp/{drift,sntp-kod}
 sed -e 's|VENDORZONE\.|%{vendorzone}|' \
@@ -257,8 +256,7 @@ sed -e 's|VENDORZONE\.|%{vendorzone}|' \
 	< %{SOURCE1} > .%{_sysconfdir}/ntp.conf
 touch -r %{SOURCE1} .%{_sysconfdir}/ntp.conf
 install -p -m600 %{SOURCE2} .%{_sysconfdir}/ntp/keys
-install -p -m755 %{SOURCE3} .%{_initrddir}/ntpd
-install -p -m755 %{SOURCE7} .%{_initrddir}/ntpdate
+install -p -m755 %{SOURCE7} .%{_libexecdir}/ntpdate-wrapper
 install -p -m644 %{SOURCE4} .%{_sysconfdir}/sysconfig/ntpd
 install -p -m644 %{SOURCE9} .%{_sysconfdir}/sysconfig/ntpdate
 install -p -m644 %{SOURCE6} .%{_sysconfdir}/ntp/step-tickers
@@ -331,7 +329,6 @@ fi
 %{_sbindir}/ntptime
 %{_sbindir}/sntp
 %{_sbindir}/tickadj
-%{_initrddir}/ntpd
 %config(noreplace) %{_sysconfdir}/sysconfig/ntpd
 %config(noreplace) %verify(not md5 size mtime) %{_sysconfdir}/ntp.conf
 %dir %attr(750,root,ntp) %{_sysconfdir}/ntp/crypto
@@ -364,11 +361,11 @@ fi
 %files -n ntpdate
 %defattr(-,root,root)
 %doc COPYRIGHT
-%{_initrddir}/ntpdate
 %config(noreplace) %{_sysconfdir}/sysconfig/ntpdate
 %dir %{_sysconfdir}/ntp
 %config(noreplace) %{_sysconfdir}/ntp/keys
 %config(noreplace) %verify(not md5 size mtime) %{_sysconfdir}/ntp/step-tickers
+%{_libexecdir}/ntpdate-wrapper
 %{_sbindir}/ntpdate
 %{_mandir}/man8/ntpdate.8*
 /lib/systemd/system/ntpdate.service
diff --git a/ntpdate.service b/ntpdate.service
index 8ccb3da..75e3a78 100644
--- a/ntpdate.service
+++ b/ntpdate.service
@@ -6,7 +6,7 @@ Wants=time-sync.target
 
 [Service]
 Type=oneshot
-ExecStart=/etc/init.d/ntpdate start
+ExecStart=/usr/libexec/ntpdate-wrapper
 RemainAfterExit=yes
 
 [Install]
diff --git a/ntpdate.wrapper b/ntpdate.wrapper
new file mode 100755
index 0000000..5baeab0
--- /dev/null
+++ b/ntpdate.wrapper
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+ntpconf=/etc/ntp.conf
+ntpstep=/etc/ntp/step-tickers
+
+[ "$EUID" != "0" ] && exit 4
+[ -x /usr/sbin/ntpdate ] || exit 5
+[ -f /etc/sysconfig/ntpdate ] || exit 6
+. /etc/sysconfig/ntpdate
+
+[ -f $ntpstep ] && tickers=$(sed 's/#.*//' $ntpstep) || tickers=
+
+if ! echo "$tickers" | grep -qi '[a-z0-9]' && [ -f $ntpconf ]; then
+	# the step-tickers file doesn't specify a server,
+	# use servers from ntp.conf instead
+	tickers=$(awk '$1=="peer"||$1=="server"{print $2}' $ntpconf | \
+		grep -Ev '127\.127\.[0-9]+\.[0-9]+')
+fi
+
+if ! echo "$tickers" | grep -qi '[a-z0-9]'; then
+	echo "NTP server not specified in $ntpstep or $ntpconf"
+	exit 6
+fi
+
+[ -z "$RETRIES" ] && RETRIES=2
+retry=0
+while true; do
+	/usr/sbin/ntpdate -U ntp -s -b $OPTIONS $tickers &> /dev/null
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] || [ $retry -ge "$RETRIES" ] && break
+	sleep $[10 * (1 << $retry)]
+	retry=$[$retry + 1]
+done
+
+[ $RETVAL -eq 0 ] && [ "$SYNC_HWCLOCK" = "yes" ] && /sbin/hwclock --systohc
+exit $RETVAL


More information about the scm-commits mailing list