User avatar
buja
Posts: 541
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

System time not synchonizing with time servers

Sun Jan 12, 2020 9:25 pm

I just started up a Pi 2B to an apt update, but it failed because the system time was wrong: 25 December.
That was strange because it should have updated the system date during boot.
A similar thing happened a couple of weeks ago on a PC and the solution was to restart the systemd time synchronization daemon. However, that resulted in the error below:

Code: Select all

sudo systemctl restart systemd-timesyncd.service
[sudo] password for wwx: 
Warning: The unit file, source configuration file or drop-ins of systemd-timesyncd.service changed on disk.
Run 'systemctl daemon-reload' to reload units.
I followed that advice, no messages, should be okay right? No, it was not, time did not update.
I set the time manually (sudo date -s "12 JAN 2020 22:04:00"), so I could do apt update & upgrade, but I can still see the time is off and is not updating.

So the question is: now what?

ktb
Posts: 1447
Joined: Fri Dec 26, 2014 7:53 pm

Re: System time not synchonizing with time servers

Mon Jan 13, 2020 2:31 am

Hello,
buja wrote:I followed that advice, no messages, should be okay right?
That SHOULD be OK without knowing anything else. A daemon-reload is required after changes have been made to a unit file. That is normal provided the unit file was modified for a legitimate reason. However, if this message was returned to you after you tried to restart a specific service, it means that your request to restart that service did not use the most recent version of the unit file. In your case, after running sudo systemctl restart systemd-timesyncd.service, you would likely want to run sudo systemctl daemon-reload and then run sudo systemctl restart systemd-timesyncd.service again so that the most recent version of the systemd-timesyncd.service unit file is used when restarting the service.


If that isn't the only problem, then it would be helpful to see the contents of the unit file being used. Will you please simply post the output of the following commands here in this thread?

The following output is from Raspbian Buster on a RPi4B:

Code: Select all

sudo systemctl status systemd-timesyncd
Example:

Code: Select all

[email protected]:~ $ sudo systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
           └─disable-with-time-daemon.conf
   Active: active (running) since Sun 2020-01-12 21:04:55 EST; 29s ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 3084 (systemd-timesyn)
   Status: "Synchronized to time server for the first time 208.76.1.123:123 (0.debian.pool.ntp.org)."
    Tasks: 2 (limit: 3968)
   Memory: 1.2M
   CGroup: /system.slice/systemd-timesyncd.service
           └─3084 /lib/systemd/systemd-timesyncd

Jan 12 21:04:55 raspberrypi systemd[1]: Starting Network Time Synchronization...
Jan 12 21:04:55 raspberrypi systemd[1]: Started Network Time Synchronization.
Jan 12 21:04:55 raspberrypi systemd-timesyncd[3084]: Synchronized to time server for the first time 208.76.1.123:123 (0.debia

Code: Select all

cat /lib/systemd/system/systemd-timesyncd.service
Example:

Code: Select all

[email protected]:~ $ cat /lib/systemd/system/systemd-timesyncd.service
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Network Time Synchronization
Documentation=man:systemd-timesyncd.service(8)
ConditionCapability=CAP_SYS_TIME
ConditionVirtualization=!container
DefaultDependencies=no
After=systemd-remount-fs.service systemd-sysusers.service
Before=time-sync.target sysinit.target shutdown.target
Conflicts=shutdown.target
Wants=time-sync.target

[Service]
AmbientCapabilities=CAP_SYS_TIME
CapabilityBoundingSet=CAP_SYS_TIME
ExecStart=!!/lib/systemd/systemd-timesyncd
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
PrivateDevices=yes
PrivateTmp=yes
ProtectControlGroups=yes
ProtectHome=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
ProtectSystem=strict
Restart=always
RestartSec=0
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
RuntimeDirectory=systemd/timesync
StateDirectory=systemd/timesync
SystemCallArchitectures=native
SystemCallErrorNumber=EPERM
[email protected] @clock
Type=notify
User=systemd-timesync
WatchdogSec=3min

[Install]
WantedBy=sysinit.target
Alias=dbus-org.freedesktop.timesync1.service

And in case you added your own custom unit file at /etc/systemd/system/systemd-timesyncd.service, run this too:

Code: Select all

cat /etc/systemd/system/systemd-timesyncd.service
Example:

Code: Select all

[email protected]:~ $ cat /etc/systemd/system/systemd-timesyncd.service
cat: /etc/systemd/system/systemd-timesyncd.service: No such file or directory

Code: Select all

cat /etc/systemd/timesyncd.conf
Example:

Code: Select all

[email protected]:/etc/systemd $ cat /etc/systemd/timesyncd.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.

[Time]
#NTP=
#FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

User avatar
buja
Posts: 541
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: System time not synchonizing with time servers

Mon Jan 13, 2020 5:51 am

Thanks!
I kept the system running overnight and did sudo systemctl status systemd-timesyncd this morning with the following result:

Code: Select all

● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
           └─disable-with-time-daemon.conf
   Active: active (running) since Sun 2020-01-12 22:42:16 CET; 7h ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 253 (systemd-timesyn)
   Status: "Synchronized to time server for the first time 109.201.133.100:123 (0.debian.pool.ntp.org)."
    Tasks: 2 (limit: 2200)
   Memory: 3.7M
   CGroup: /system.slice/systemd-timesyncd.service
           └─253 /lib/systemd/systemd-timesyncd

Jan 12 23:31:14 rpi202 systemd-timesyncd[253]: Timed out waiting for reply from 89.20.185.72:123 (2.debian.pool.ntp.org).
Jan 12 23:31:24 rpi202 systemd-timesyncd[253]: Timed out waiting for reply from 45.32.4.67:123 (2.debian.pool.ntp.org).
Jan 12 23:31:34 rpi202 systemd-timesyncd[253]: Timed out waiting for reply from 136.144.184.203:123 (3.debian.pool.ntp.org).
Jan 12 23:31:44 rpi202 systemd-timesyncd[253]: Timed out waiting for reply from 95.211.120.4:123 (3.debian.pool.ntp.org).
Jan 12 23:31:55 rpi202 systemd-timesyncd[253]: Timed out waiting for reply from 83.98.155.30:123 (3.debian.pool.ntp.org).
Jan 12 23:32:05 rpi202 systemd-timesyncd[253]: Timed out waiting for reply from 109.201.133.2:123 (3.debian.pool.ntp.org).
Jan 12 23:49:09 rpi202 systemd-timesyncd[253]: Synchronized to time server for the first time 45.159.204.28:123 (0.debian.pool.ntp.org).
Jan 13 01:17:53 rpi202 systemd-timesyncd[253]: Timed out waiting for reply from 45.159.204.28:123 (0.debian.pool.ntp.org).
Jan 13 01:18:03 rpi202 systemd-timesyncd[253]: Timed out waiting for reply from 37.252.127.156:123 (0.debian.pool.ntp.org).
Jan 13 01:18:03 rpi202 systemd-timesyncd[253]: Synchronized to time server for the first time 109.201.133.100:123 (0.debian.pool.ntp.org).
This shows several failed attempts to synchronize the time, but in the end it worked out and the time is the same as my PC.
So it seems to work for now, I will check the other file later.

User avatar
buja
Posts: 541
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: System time not synchonizing with time servers (solved)

Mon Jan 13, 2020 6:52 pm

Update: after the check this morning I powered the Pi down and went to work. When I came back home in the afternoon I started the Pi up again, time was set at this morning. I left home again and when I returned later the time was updated correctly about 15 minutes after boot.
I can also see the Pi tries to synchronize time every 10 seconds, so my preliminary conclusion is that the time system works well, but there might be a connection problem (WiFi).
I will try to be more patient and consider the matter solved for now.

Return to “Raspbian”