Date/Time synchronization
-
Hi all,
In my config, I have a service which should log its starting date and time in a log file.
All is ok but the time is not correct. It seems to be about the last shutdown time + 5 sec.I read that the Raspberry doens't have a RTC (Real Time Clock) and that is why, the time is not synchronize at boot. But after few second, the time is correct.
I'm connected to internet. Does the Rasperry synchronize its time at boot ? and how ?
Is it just magic ^^ ??Thanks for your lights.
Joe. -
@joecool said in Date/Time synchronization:
I'm connected to internet. Does the Rasperry synchronize its time at boot ? and how ?
It uses NTP to synchronize it's date/time using the internet.
-
@mitu Ha ? I saw that ntd was not use anymore and maybe timedatectl was used in place.
-
@joecool timedatectl is only setting/reading the date, does not speak NTP. You're probably thinking about
systemd-timesyncd
, but I don't think that's installed in Raspbian. -
@mitu You're probably right. My problem is to know how this sync works. I'm sorry, but there is a blur in my mind about that time sync.
Concretely, can we list, please, each step (init.d, service, etc...) responsible to the sync time process during the Raspbian start ?
I will be nice for me ;) !
-
@joecool said in Date/Time synchronization:
My problem is to know how this sync works.
Via NTP (either using
ntpd
orsystemd-timesyncd
, both speak the same protocol). I don't have a PI at hand to check, but I think you can check the list ofsystemd
running services and see ifntpd
is enabled. -
@mitu yep, only systemd-timesyncd.service is enabled...
Could I say to my new service to wait for the launch of systemd-timesyncd.service ? -
@joecool said in Date/Time synchronization:
Could I say to my new service to wait for the launch of systemd-timesyncd.service ?
Yes.
-
@mitu Add "After=systemd-timesyncd.service" (in the [Unit] section) into my <blabla>.service file, right ?
I will try now... -
@joecool said in Date/Time synchronization:
@mitu Add "After=systemd-timesyncd.service" (in the [Unit] section) into my <blabla>.service file, right ?
I will try now...It does not seem to work (with After=...). I tried with systemd-timesyncd.service, time-sync.target and sysinit.targetbut no one works... Strange !!
The time is always the last known... that at the moment of the shutdown.
I continue to search... If you have any idea, will be cool.
-
Instead of strictly depending on the timesyncd service, try making your service depending on the
network
target , otherwise the time service doesn't have a chance to do any synchronisation. Add a delay before the service starts using theExecStartPre
to runsleep
for 2-3 seconds. -
@mitu said in Date/Time synchronization:
epending on the timesyncd service
Good idea, I'm going to try that. Thanks.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.