crosmax
Posts: 31
Joined: Tue May 08, 2018 1:30 pm

Wrong date every booting

Fri Jul 19, 2019 3:06 pm

Hi all!
I need to get real date when boot because I run a custom logrotate service for my apps log. I've a RTC on my raspberry, but the correct date setting just happend after few seconds and the logrotate service think that today is another day and rotate files.
On every booting I get Nov 3 18:16:45 as date

Anyone knows why this date and how raspberry boot with correct date ?
Thanks

User avatar
scruss
Posts: 2359
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Wrong date every booting

Fri Jul 19, 2019 3:41 pm

what's the systemd target for your RTC? If it's called hwclock-sync.service, put this line in the Unit section of your logrotate service file:

Code: Select all

After=hwclock-sync.service
If you were using network time sync, waiting for time-sync.target will cause problems as that returns after time sync has started, not once the system clock is correct.

Alternatively, put a big ol' sleep 30 in your logrotate start script and hope that the clock has come up more quickly than 30 s after boot …
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

crosmax
Posts: 31
Joined: Tue May 08, 2018 1:30 pm

Re: Wrong date every booting

Fri Jul 19, 2019 4:37 pm

scruss wrote: what's the systemd target for your RTC? If it's called hwclock-sync.service, put this line in the Unit section of your logrotate service file:

Code: Select all

After=hwclock-sync.service
If you were using network time sync, waiting for time-sync.target will cause problems as that returns after time sync has started, not once the system clock is correct.

Alternatively, put a big ol' sleep 30 in your logrotate start script and hope that the clock has come up more quickly than 30 s after boot …
Thanks!
I not have hwclock-sync.service and I don't use NTP but put a sleep is always a effective solution. I'm boring with that problem so add sleep is the better fix for me now.

alphanumeric
Posts: 1921
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Wrong date every booting

Fri Jul 19, 2019 8:01 pm

Is the battery in your RTC OK?

crosmax
Posts: 31
Joined: Tue May 08, 2018 1:30 pm

Re: Wrong date every booting

Wed Jul 24, 2019 8:08 am

alphanumeric wrote:Is the battery in your RTC OK?
Yes, of course. If type

Code: Select all

sudo hwclock -r
after poweroff during a few minutes without 5V power connection, the hwclock date is correct. The problem is during first seconds when booting, because the OS don't get the date first of all.

User avatar
Imperf3kt
Posts: 2554
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: Wrong date every booting

Wed Jul 24, 2019 8:14 am

How does that work? You turn the Pi off and remove 5v (pull the plug?) then wait a few minutes and type on the terminal of a turned off Pi?

Or have I interpreted your statement incorrectly?
55:55:44:44:4C
52:4C:52:42:41

crosmax
Posts: 31
Joined: Tue May 08, 2018 1:30 pm

Re: Wrong date every booting

Wed Jul 24, 2019 8:29 am

Imperf3kt wrote:
Wed Jul 24, 2019 8:14 am
How does that work? You turn the Pi off and remove 5v (pull the plug?) then wait a few minutes and type on the terminal of a turned off Pi?

Or have I interpreted your statement incorrectly?
Hehehe. Maybe obvious, maybe not... I turn the Pi ON and when the OS finished boot, I logged in and type

Code: Select all

sudo hwclock -r
. In this moment, date is correct, and if I open syslog file I can find the moment when OS change the date while booting, always when write

Code: Select all

Time has been changed"

User avatar
Imperf3kt
Posts: 2554
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: Wrong date every booting

Wed Jul 24, 2019 10:30 pm

That doesn't guarantee the battery is fine, but it does clear up the confusion.


So your problem is that the Pi is not getting its time from the RTC until a few seconds after boot?
55:55:44:44:4C
52:4C:52:42:41

crosmax
Posts: 31
Joined: Tue May 08, 2018 1:30 pm

Re: Wrong date every booting

Mon Aug 05, 2019 10:28 am

Imperf3kt wrote: That doesn't guarantee the battery is fine, but it does clear up the confusion.


So your problem is that the Pi is not getting its time from the RTC until a few seconds after boot?
Yes, after every boot, the first system log messages have wrong date, even my application that boot from systemd, his first log messages has wrong date too.

I get this log messages from daemon.log file:

Code: Select all

Jul 30 06:20:34 host-19010 systemd[1]: Time has been changed
Jul 30 06:20:34 host-19010 systemd[576]: Time has been changed
Jul 30 06:20:34 host-19010 systemd[1]: apt-daily.timer: Adding 8h 58min 6.381826s random time.
Jul 30 06:20:34 host-19010 systemd[1]: apt-daily-upgrade.timer: Adding 33min 32.797934s random time.
Jul 30 06:20:34 host-19010 rc.local[456]: hwclock: Cannot access the Hardware Clock via any known method.
Jul 30 06:20:34 host-19010 rc.local[456]: hwclock: Use the --debug option to see the details of our search for an access method.
Jul 30 06:20:38 host-19010 wpa_supplicant[481]: wlan0: Failed to initiate sched scan

User avatar
scruss
Posts: 2359
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Wrong date every booting

Mon Aug 05, 2019 2:26 pm

hwclock: Cannot access the Hardware Clock via any known method.
though that's not an ideal message to see. Sounds like your I²C might not be set up correctly.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

alphanumeric
Posts: 1921
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Wrong date every booting

Mon Aug 05, 2019 3:11 pm

For what its worth, I just did a fresh install of Buster on a Pi 3B+ with a DS3231. I followed this guide and I get the correct date and time on my desktop on bootup right away. If there is a delay setting the correct time I haven't noticed it.
https://learn.adafruit.com/adding-a-rea ... -test-i2c

Return to “General discussion”