Skip to content

Restart chrony/ntp service on interfaces-config restart#69

Open
anamehra wants to merge 1 commit intosonic-net:masterfrom
anamehra:anamehra/chrony_ztp_restart
Open

Restart chrony/ntp service on interfaces-config restart#69
anamehra wants to merge 1 commit intosonic-net:masterfrom
anamehra:anamehra/chrony_ztp_restart

Conversation

@anamehra
Copy link

@anamehra anamehra commented Nov 13, 2025

Restart NTP service when interfaces-config restarts

Problem

When ZTP restarts the interfaces-config service (during link scan or periodic restarts), it causes issues with the NTP service if management VRF is configured.

Why this happens:

  • When management VRF is set up, NTP needs to bind to the correct VRF context
  • Restarting interfaces-config changes the network namespace and VRF configuration
  • If NTP is not restarted after this, it stays bound to the old network context and stops working
  • This breaks time synchronization during the ZTP provisioning process

Solution

Added logic to detect which NTP service is running (chrony or ntp) and restart it around the interfaces-config restart:

  1. Stop the NTP service (releases the old VRF binding)
  2. Restart interfaces-config (applies new network/VRF config)
  3. Start the NTP service (rebinds to the correct VRF context)

This ensures NTP continues working correctly in the management VRF after network reconfigurations.

Changes

  • ztp-engine.py: Added get_ntp_service_name() function to detect which service is available, and __restart_network_services() method to handle the restart sequence
  • ztp-profile.sh: Added get_ntp_service() function and updated install/remove sections to stop/start NTP around interfaces-config restarts

Why detect the service?

Different SONiC releases use different NTP implementations (ntp vs chrony), so we check which one is actually running instead of hardcoding it. The code checks in priority order: chrony first, then ntp.

Signed-off-by: Anand Mehra (anamehra) <anamehra@cisco.com>
@mssonicbld
Copy link

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@anamehra anamehra marked this pull request as ready for review December 22, 2025 06:27
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.

2 participants