Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeeWX starts before clock correct when using ntp #946

Closed
ps-crawford opened this issue Mar 31, 2024 · 12 comments
Closed

WeeWX starts before clock correct when using ntp #946

ps-crawford opened this issue Mar 31, 2024 · 12 comments

Comments

@ps-crawford
Copy link

Now that the WeeWX code runs as a systemd service there is an assumption that it will get the correct time using the 'Requires=time-sync.target' statement. However, that is not necessarily true if ntp is in use instead and that is very apparent on devices like a Raspberry PI that lacks a real-time clock to set time on boot.

A fix I found it to edit the systemd service /lib/systemd/system/weewx.service and adding ntp-wait to the pre-start list, with '-' preceding it so failure is ignored (which might be the case if no network at all, or ntp removed). So you should then have something like:

[Service]
ExecStartPre=-ntp-wait -v -s 2 -n 60
ExecStart=weewxd /etc/weewx/weewx.conf
@tkeffer
Copy link
Contributor

tkeffer commented Mar 31, 2024

But, that won't work if systemd-timesyncd is in use, which is the default on an RPi.

@ps-crawford
Copy link
Author

I think it will just quietly fail and due to the leading '-' continue anyway. It did on my machine when I mistyped the command at first!

@tkeffer
Copy link
Contributor

tkeffer commented Mar 31, 2024

Most users are going to use the default, which works.

If a user wants to use ntp, then some modifications should be expected.

@tkeffer tkeffer closed this as completed Mar 31, 2024
@ps-crawford
Copy link
Author

I just tried to add a note to https://github.com/weewx/weewx/wiki/Time-services/#ntp to reference this case, but seems I can't edit this. Or I have missed something obvious.

@tkeffer
Copy link
Contributor

tkeffer commented Mar 31, 2024

You have to be logged into GitHub. Other than that, I don't think there are any requirements to edit anything in the wiki.

@ps-crawford
Copy link
Author

OK I tried it again and it seems to have worked. Maybe last time I forgot to add a note about the change or similar, as the 'save' button went greyed out as if doing something but it never completed.

@duane-nepa
Copy link

duane-nepa commented Mar 31, 2024 via email

@ps-crawford
Copy link
Author

The NTP vs Chrony vs OpenNTPD debate is kind of irrelevant as none of them are properly detected by systemd's built-in time check. I don't know if chrony has an equivalent wait-for-sync command to the ntp-wait that I used.

However it all comes back to the same point: if time matters before WeeWX is started, which is the case, you need to take extra steps to make sure it has been synchronised by whatever system you have chosen whenever it is not systemd's built-in choice.

@duane-nepa
Copy link

duane-nepa commented Apr 1, 2024 via email

@evilbunny2008
Copy link
Contributor

Doesn't the RPi5 come with a RTC? Pretty sure you just need to supply a battery.

@duane-nepa
Copy link

duane-nepa commented Apr 1, 2024 via email

@ps-crawford
Copy link
Author

Thanks for the RTC suggestions, it is a Pi 3B I am using. I have one which has a GPS board with RTC though the RTC side never seemed to work.

However, this is missing the point! The WeeWX package should be waiting for time-sync before starting so that ought to be a secondary consideration (after all the RTC could be wrong) and if you are using systemd's own method that works.

My point was if you use NTP or something else you need to modify the weewx.service file to put in a synchronisation check that actually works with your choice of time-sync method. Mine was NTP hence the use of ntp-wait, but for other systems you will need to check what does the same to have the same guarantee of clock correctness on starting WeeWX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants