Skip to content

Commit

Permalink
replace sntp with chronyd
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Nov 1, 2017
1 parent 9518f60 commit 9ba073c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
18 changes: 8 additions & 10 deletions src/clients/ntp-client_proposal.rb
Expand Up @@ -362,7 +362,7 @@ def Write(param)
return :success if param["write_only"]

# One-time adjusment without running the ntp daemon
# Meanwhile, ntpdate was replaced by sntp
# Meanwhile, ntpdate was replaced by sntp and later by chrony
ntpdate_only = param["ntpdate_only"]

required_package = "chrony"
Expand All @@ -388,26 +388,24 @@ def Write(param)
# Only if network is running try to synchronize the ntp server
Popup.ShowFeedback("", _("Synchronizing with NTP server..."))

Builtins.y2milestone("Running sntp to sync with %1", ntp_server)
Builtins.y2milestone("Running ont time sync with %1", ntp_server)

# -S: do set the system time
# -q: set system time and quit
# -t 5: timeout of 5 seconds
# -K /dev/null: use /dev/null as KoD history file (if not specified,
# /var/db/ntp-kod will be used and it doesn't exist)
# -l <file>: log to a file to not mess text mode installation
# -c: causes all IP addresses to which ntp_server resolves to be queried in parallel
ret = SCR.Execute(
path(".target.bash"),
"/usr/sbin/sntp -S -K /dev/null -l /var/log/YaST2/sntp.log " \
"-t 5 -c '#{String.Quote(ntp_server)}'"
path(".target.bash_output"),
# TODO: ensure that we can use always pool instead of server?
"/usr/sbin/chronyd -q -t 5 'pool #{String.Quote(ntp_server)} iburst'"
)
Builtins.y2milestone("'sntp %1' returned %2", ntp_server, ret)
Builtins.y2milestone("'one-time chrony for %1' returned %2", ntp_server, ret)
Popup.ClearFeedback
end

return :ntpdate_failed if ret != 0

# User wants to more than running sntp (synchronize on boot)
# User wants to more than running one time sync (synchronize on boot)
WriteNtpSettings(ntp_servers, ntp_server, run_service) if !ntpdate_only

:success
Expand Down
25 changes: 7 additions & 18 deletions src/modules/NtpClient.rb
Expand Up @@ -803,36 +803,25 @@ def Summary
# @param [String] server string host name or IP address of the NTP server
# @return [Boolean] true if NTP server answers properly
def reachable_ntp_server?(server)
sntp_test(server) || sntp_test(server, 6)
ntp_test(server) || ntp_test(server, 6)
end

# Test NTP server answer for a given IP version.
# @param [String] server string host name or IP address of the NTP server
# @param [Fixnum] integer ip version to use (4 or 6)
# @return [Boolean] true if stderr does not include lookup error and exit
# code is 0
def sntp_test(server, ip_version = 4)
def ntp_test(server, ip_version = 4)
output = SCR.Execute(
path(".target.bash_output"),
# -K /dev/null: use /dev/null as KoD history file (if not specified,
# /var/db/ntp-kod will be used and it doesn't exist)
# -c: concurrently query all IPs; -t 5: five seconds of timeout
"LANG=C /usr/sbin/sntp -#{ip_version} -K /dev/null -t 5 -c #{server}"
# -t 5: five seconds of timeout
# -Q: print only offset, if failed exit is non-zero
"LANG=C /usr/sbin/chronyd -#{ip_version} -t 5 -Q 'pool #{server} iburst'"
)

Builtins.y2milestone("sntp test response: #{output}")
Builtins.y2milestone("chronyd test response: #{output}")

return false if output["exit"] != 0
# sntp returns always 0 if not called with option -S or -s (set system time)
# so this is a workaround at least to return false in case server is not
# reachable.
return false if output["stderr"].include?("lookup error")
# this happens for valid address, but without ntp server. If it breaks in the
# future start complaining to sntp maintainer to not return 0 in this case.
# customer case: bsc#972842
return false if output["stdout"] =~ /no (U|B)CST/

true
output["exit"] == 0
end

# Handle UI of NTP server test answers
Expand Down

0 comments on commit 9ba073c

Please sign in to comment.