twekkel / htpdate

HTTP Time protocol
https://www.vervest.org/htp
Other
48 stars 12 forks source link

Chrony not working as expected following https://www.vervest.org/htp/?ntppool #27

Closed aii-shanker-jj closed 1 year ago

aii-shanker-jj commented 1 year ago

Environment

htpdate service environment file contents

HTP_PROXY="-P 192.18.170.12:3128"
HTP_SERVERS="-s http://jjy.nict.go.jp/"
HTP_OPTIONS="-Dx -p 7 -f /var/lib/chrony/chrony.drift"

htpdate service status

● htpdate.service - HTTP based time synchronization tool
     Loaded: loaded (/lib/systemd/system/htpdate.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-09-22 12:17:57 JST; 38min ago
       Docs: man:htpdate
    Process: 3881 ExecStart=/usr/sbin/htpdate $HTP_OPTIONS $HTP_PROXY -i /run/htpdate.pid $HTP_SERVERS (code=exited, status=0/SUCCESS)
   Main PID: 3885 (htpdate)
      Tasks: 1 (limit: 76811)
     Memory: 244.0K
     CGroup: /system.slice/htpdate.service
             └─3885 /usr/sbin/htpdate -Dx -p 7 -f /etc/htpdate.drift -P 192.18.170.12 3128 -i /run/htpdate.pid -s http://jjy.nict.go.jp/

Sep 22 12:17:57 s-master systemd[1]: Starting HTTP based time synchronization tool...
Sep 22 12:17:57 s-master htpdate[3881]: Error reading frequency from /etc/htpdate.drift
Sep 22 12:17:57 s-master htpdate[3885]: htpdate version 1.3.6 started
Sep 22 12:17:57 s-master systemd[1]: htpdate.service: Supervising process 3885 which is not our child. We'll most likely not notice when it exits.
Sep 22 12:17:57 s-master systemd[1]: Started HTTP based time synchronization tool.
Sep 22 12:17:59 s-master htpdate[3885]: Setting 0.016 seconds
Sep 22 12:17:59 s-master htpdate[3885]: Set time: Thu Sep 22 12:17:59 2022
Sep 22 12:47:58 s-master htpdate[3885]: sleep for 1800 s

Looking for inputs on resolving "Error reading frequency from /etc/htpdate.drift"

Added below lines in /etc/chrony/chrony.conf

local stratum 5
driftfile /etc/htpdate.drift

On execution of chronyc sourcestats -v, it returns a empty list.

                             .- Number of sample points in measurement set.
                            /    .- Number of residual runs with same sign.
                           |    /    .- Length of measurement set (time).
                           |   |    /      .- Est. clock freq error (ppm).
                           |   |   |      /           .- Est. error in freq.
                           |   |   |     |           /         .- Est. offset.
                           |   |   |     |          |          |   On the -.
                           |   |   |     |          |          |   samples. \
                           |   |   |     |          |          |             |
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================

Exepecting localhost will be displayed.

On execution of chronyc activity, it returns a 0 sources. I was expecting 1 source as localhost.

200 OK
0 sources online
0 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address

Looking for some guidance/inputs to sync between htpdate and chrony.

twekkel commented 1 year ago

Try the -F option, as htpdate does double forking, which systemd doesn't understand.

twekkel commented 1 year ago

Please let me know if below startup option solve the issue

HTP_OPTIONS="-DFx -p 7 -f /var/lib/chrony/chrony.drift"

Please also have a look at the example in scripts/htpdate.service

shan100github commented 1 year ago

referred to scripts/htpdate.service and updated Type=forking to Type=exec Also modified HTP_OPTIONS to included -F.

but still doesn't look sync

> chronyc tracking

Reference ID    : 7F7F0101 ()
Stratum         : 5
Ref time (UTC)  : Wed Sep 28 06:46:00 2022
System time     : 0.000000000 seconds fast of NTP time
Last offset     : +0.000000000 seconds
RMS offset      : 0.000000000 seconds
Frequency       : 0.000 ppm slow
Residual freq   : +0.000 ppm
Skew            : 0.000 ppm
Root delay      : 0.000000000 seconds
Root dispersion : 0.000000000 seconds
Update interval : 0.0 seconds
Leap status     : Normal

> chronyc clients

Hostname                      NTP   Drop Int IntL Last     Cmd   Drop Int  Last
===============================================================================
502 Invalid command
twekkel commented 1 year ago

Only now I get what you are trying to do, I think. Ntpd, chrony and htpdate all use drift files, but thier content isn't compatible. Htpdate is only storing the frequency as a number, nothing more.

Having two programs writing to the same file is asking for trouble (race conditions) anyway,

shan100github commented 1 year ago

I have updated HTP_OPTIONS="-Dx -p 7 -f /var/lib/chrony/chrony.drift" with HTP_OPTIONS="-Dx -p 7 -f /etc/htpdate.drift" and still no change in chronyc tracking or chronyc clients results.

twekkel commented 1 year ago

Seems like a chronyc issue than.... htpdate doesn't know about chrony and the other way around... they are complete separate entities. Even without htpdate installed/running, chrony probably doesn't work in your case, please check.

aii-shanker-jj commented 1 year ago

oh ok. for now, I shall close this ticket and get back after verification. thank you @twekkel