1

Is it possible to programmatically know if systemd-timesyncd;

  • Can access to the NTP servers?
  • Has synced the system time with the server?

The reason is I have an application depends on precise time information and must be started after system time is updated. Or is there any other method without using systemd?

Thanks.

2 Answers2

2

From this link ( systemd-timesyncd.service man page):

/var/lib/systemd/timesync/clock

The modification time ("mtime") of this file indicates the timestamp of the last successful synchronization (or at least the systemd build date, in case synchronization was not possible). It is used to ensure that the system clock remains roughly monotonic across reboots, in case no local RTC is available.

/run/systemd/timesync/synchronized

A file that is touched on each successful synchronization, to assist systemd-time-wait-sync and other applications to detecting synchronization with accurate reference clocks.

BHP
  • 463
0
 systemctl status systemd-timesyncd
 * systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-10-25 11:36:40 CEST; 52min ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 881 (systemd-timesyn)
   Status: "Synchronized to time server 91.189.91.157:123 (ntp.ubuntu.com)."
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/systemd-timesyncd.service
           `-881 /lib/systemd/systemd-timesyncd

Oct 25 11:36:40 computername systemd[1]: Starting Network Time Synchronization...
Oct 25 11:36:40 computername systemd[1]: Started Network Time Synchronization.
Oct 25 11:37:11 Computername systemd-timesyncd[881]: Synchronized to time server 91.189.91.157:123 (ntp.ubuntu.com).
nobody
  • 5,792