Skip to content
Snippets Groups Projects
Commit 0ccbff2e authored by Florent Thiery's avatar Florent Thiery
Browse files

support timedatectl conf file

parent 90ef573a
No related branches found
No related tags found
No related merge requests found
......@@ -14,9 +14,13 @@ import imp
if os.path.isfile('/usr/bin/ntpq'):
cmd = "LANG=C ntpq -pd"
expected = "remote"
ntpconf = '/etc/ntp.conf'
ntpconf_expected = 'server '
else:
cmd = "LANG=C timedatectl"
expected = 'NTP synchronized'
ntpconf = '/etc/systemd/timesyncd.conf'
ntpconf_expected = 'NTP='
print("Running %s" % cmd)
status = subprocess.getoutput(cmd)
......@@ -34,14 +38,14 @@ if os.path.isfile('../utils.py'):
conf = es_utils.load_conf()
NTP_SERVER = conf.get('NTP_SERVER') or 'ntp.ubuntu.com'
with open('/etc/ntp.conf', 'r') as f:
with open(ntpconf, 'r') as f:
d = f.read()
servers = list()
for l in d.split('\n'):
if l.startswith('server '):
servers.append(l.split('server ')[1])
if l.startswith(ntpconf_expected):
servers.append(l.split(ntpconf_expected)[1])
if not 'server %s' % NTP_SERVER in d:
print('Expected NTP server %s not found in /etc/ntp.conf, found %s instead' % (NTP_SERVER, servers))
print('Expected NTP server %s not found in %s, found %s instead' % (NTP_SERVER,ntpconf, servers))
sys.exit(1)
else:
print('Expected NTP server %s found in configuration (total servers: %s)' % (NTP_SERVER, len(servers)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment