0

I have to read the status of systemd-timesyncd.service whether to see whetther it has synchronized with the ntp . The System clock synchronized flag is not helpful since it does not show appropriate information

0

There is a DBUS. See the developer documentation. They have this as an example:

$ gdbus introspect --system --dest org.freedesktop.timedate1 --object-path /org/freedesktop/timedate1
node /org/freedesktop/timedate1 {
  interface org.freedesktop.timedate1 {
    methods:
      SetTime(in  x usec_utc,
              in  b relative,
              in  b user_interaction);
      SetTimezone(in  s timezone,
                  in  b user_interaction);
      SetLocalRTC(in  b local_rtc,
                  in  b fix_system,
                  in  b user_interaction);
      SetNTP(in  b use_ntp,
             in  b user_interaction);
    signals:
    properties:
      readonly s Timezone = 'Europe/Berlin';
      readonly b LocalRTC = false;
      readonly b NTP = true;
  };
  interface org.freedesktop.DBus.Properties {
  };
  interface org.freedesktop.DBus.Introspectable {
  };
  interface org.freedesktop.DBus.Peer {
  };
};

That is to "set" through dbus; not to "get".

I have to read the status of systemd-timesyncd.service whether to see whether it has synchronized with the ntp

Is a whole different question though. As with most (if not all?) systemd services: they use the underlying procedure to do something. systemd-timesyncd uses ntp so your question is ... not correct. From the man page:

systemd-timesyncd will look for files with a .list extension in ntp-units.d/ directories. Each file is parsed as a list of unit names, one per line. Empty lines and lines with comments ("#") are ignored. Files are read from /usr/lib/systemd/ntp-units.d/ and the corresponding directories under /etc/, /run/, /usr/local/lib/. Files in /etc/ override files with the same name in /run/, /usr/local/lib/, and /usr/lib/. Files in /run/ override files with the same name under /usr/. Packages should install their configuration files in /usr/lib/ (distribution packages) or /usr/local/lib/ (local installs).


What you want is possible with the

timedatectl 

command.

timedatectl may be used to show the current status of time synchronization services, for example systemd-timesyncd.service.

status Show current settings of the system clock and RTC, including whether network time synchronization is active. If no command is specified, this is the implied default.

show Show the same information as status, but in machine readable form. This command is intended to be used whenever computer-parsable output is required. Use status if you are looking for formatted human-readable output.

  • timedatectl does show the synchronization status , but it only reads the kernel flag. Even if the ntp server is stopped, it still shows that the client is synchronized with the server. But on systemctl status systemd-timesyncd it correctly shows if the client has been synchronized or has timed out waiting for the connection. I want to know if this status is accessible via dbus? – Sai Achyuth Feb 17 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.