[PATCH 2/2] Make ntpd.service finish after setting the time
Richard Maw
richard.maw at codethink.co.uk
Thu Nov 29 11:46:48 UTC 2012
This also includes a cleanup of the ntpd-set.sh script.
It used recursion unnecessarily, when a for loop with seq would work.
This has the side effect of making the attempts to start unconfigured
network interfaces more alarming, as they appear as FAILURE in the
boot log.
---
scripts/ntpd-set.sh | 27 +++++++++++----------------
systemd-units/ntpd.service.in | 4 +++-
2 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/scripts/ntpd-set.sh b/scripts/ntpd-set.sh
index 3581d24..d6fd8f2 100755
--- a/scripts/ntpd-set.sh
+++ b/scripts/ntpd-set.sh
@@ -1,30 +1,25 @@
#!/bin/sh
max_attempts=4
-try_count=0
# This script takes a list of ntp servers and passes them to ntpd to set the
# system time. If a /etc/ntpd.conf file exists, the servers there are used,
# if not, some default values are passed
set_time() {
- ntpd -n -p $1;
- return $?
+ # -q flag makes ntpd exit after setting the time once
+ ntpd -q -n -p "$1"
}
check_time() {
- for arg ; do
- echo $arg
- if set_time $arg ; then
- return 0
- fi
- done
- # In case we are doing this before the network is up, try again
- let try_count=try_count+1
- if [ $try_count -lt $max_attempts ] ; then
+ for attempt in $(seq "$max_attempts"); do
+ for arg ; do
+ echo $arg
+ if set_time "$arg" ; then
+ return 0
+ fi
+ done
sleep 2
- check_time $@
- else
- return 1
- fi
+ done
+ return 1
}
if [ -f /etc/ntpd.conf ]; then
diff --git a/systemd-units/ntpd.service.in b/systemd-units/ntpd.service.in
index 1abc4f3..96ce5ac 100644
--- a/systemd-units/ntpd.service.in
+++ b/systemd-units/ntpd.service.in
@@ -1,6 +1,8 @@
[Unit]
-Description=Service to use ntpd to set the date and time
+Description=Network Time Protocol client
+Before=network.target
[Service]
+Type=oneshot
ExecStart=/usr/bin/ntpd-set.sh
RemainAfterExit=true
--
1.7.5.4
More information about the busybox
mailing list