Skip to content

Conversation

@changlei-li
Copy link
Contributor

xsconsole can set ntp to Use DHCP NTP Servers or Use Default NTP Servers, Provide NTP Servers Manually. This is so-called dhcp default and manual mode.

When switching from other modes to DHCP, the DHCP-provided NTP servers should be added to the Chrony sources. Conversely, they should be removed when switching away from DHCP.

In XS9, the ntp-dhcp server path is outdated as the chrony version update, comparing to XS8.
xs8-chrony: version 3.2, the server file with dhclient is /var/lib/dhclient/chrony.servers.$interface
xs9-chrony: version 4.6.1, the server file with dhclient is /run/chrony-dhcp/$interface.sources

It takes effect by write server $source iburst prefer to /run/chrony-dhcp/$interface.sources and /run/chrony-dhcp is sourcedir in /etc/chrony.conf.

xsconsole can set ntp to Use DHCP NTP Servers or Use Default NTP
Servers, Provide NTP Servers Manually. This is so-called dhcp
default and manual mode.

When switching from other modes to DHCP, the DHCP-provided NTP
servers should be added to the Chrony sources. Conversely, they
should be removed when switching away from DHCP.

In XS9, the ntp-dhcp server path is outdated as the chrony version
update, comparing to XS8.
xs8-chrony: version 3.2, the server file with dhclient is
/var/lib/dhclient/chrony.servers.$interface
xs9-chrony: version 4.6.1, the server file with dhclient is
/run/chrony-dhcp/$interface.sources
So the path should be updated.

Signed-off-by: Changlei Li <[email protected]>
@changlei-li
Copy link
Contributor Author

Test:
Before the fix
switch ntp mode from dhcp to default, the DHCP NTP server is not removed.

# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^? connected.by.freedominte>     0   8     0     -     +0ns[   +0ns] +/-    0ns
^? leontp3.office.panq.nl        0   9     0     -     +0ns[   +0ns] +/-    0ns
^? leontp1.office.panq.nl        0   9     0     -     +0ns[   +0ns] +/-    0ns
^? connected.by.freedominte>     0   9     0     -     +0ns[   +0ns] +/-    0ns
^* lcylab02-controller           5   7   377   114    +11us[+7418ns] +/-   95ms

After the fix
switch from dhcp to default

# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^? time.cloudflare.com           0   8     0     -     +0ns[   +0ns] +/-    0ns
^? arethusa.tweakers.net         0   8     0     -     +0ns[   +0ns] +/-    0ns
^? host-miq.as15435-c.v4.df>     0   8     0     -     +0ns[   +0ns] +/-    0ns
^? 77-175-129-186.fixed.kpn>     0   8     0     -     +0ns[   +0ns] +/-    0ns

switch form default to dhcp

# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* lcylab02-controller           5   6     7     1    +65ns[ +498us] +/-   95ms

os.chmod("/etc/dhcp/dhclient.d/chrony.sh", newPermissions)

getstatusoutput("rm -f /var/lib/dhclient/chrony.servers.*")
getstatusoutput("rm -f /run/chrony-dhcp/*.sources")
Copy link
Collaborator

@liulinC liulinC Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is removed,
what happens if user want to change back to dhcp mode? (without interface configure update, e.g: chrony.sh has no chance to run to regenerate the file)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See L605 above in AddDHCPNTP, the file will be created and filled.

@changlei-li changlei-li merged commit 93cce09 into xapi-project:master Sep 26, 2025
1 check passed
@changlei-li changlei-li deleted the private/changleli/update-dhcp-chrony-config-file branch September 26, 2025 07:04
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

Successfully merging this pull request may close these issues.

5 participants