Skip to content

Enable ntp if autodetect ntpd or timesyncd#597

Open
ColinMcInnes wants to merge 6 commits intoNetworkConfiguration:masterfrom
ColinMcInnes:ntpd_hooks
Open

Enable ntp if autodetect ntpd or timesyncd#597
ColinMcInnes wants to merge 6 commits intoNetworkConfiguration:masterfrom
ColinMcInnes:ntpd_hooks

Conversation

@ColinMcInnes
Copy link
Copy Markdown
Contributor

If --enable-ntpd or --enable-timesyncd, assume --enable-ntp and
choose the appropriate hook file.

Will complain if --enable-ntpd or --enable-timesyncd are both set,
allows override of autodetect.

Autodetect will enable ntp functionality unless explicitly told not
to via --disable-ntp. If --disable-ntp is used, no time hooks
are installed.

Addresses #574

If --enable-ntpd or --enable-timesyncd, assume --enable-ntp and
choose the appropriate hook file.

Will complain if --enable-ntpd or --enable-timesyncd are both set,
allows override of autodetect.

Autodetect will enable ntp functionality unless explicitly told not
to via --disable-ntp. If --disable-ntp is used, no time hooks
are installed.

Addresses NetworkConfiguration#574
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

Walkthrough

Add explicit time-service flags (--enable-ntpd, --enable-timesyncd) and selector variables (NTPD, TIMESYNCD); enforce mutual exclusivity; conditionally auto-detect ntpd/chronyd/systemd-timesyncd; and adjust hook selection and final NTP configuration logic in the configure script.

Changes

Cohort / File(s) Summary
Configure script
configure
Add NTPD and TIMESYNCD selector variables and CLI options (--enable-ntpd, --disable-ntpd, --enable-timesyncd, --disable-timesyncd); extend argument parsing so enabling either timeservice can also set NTP=yes; validate mutual exclusivity and abort if conflicting; only auto-detect ntpd/chronyd when NTPD is unset and only auto-detect systemd-timesyncd when TIMESYNCD is unset; set NTP=yes on detection and emit service-specific messages; select hook file by selector (50-ntp.conf if NTPD=yes, 50-timesyncd.conf if TIMESYNCD=yes); write UNCOMMENT_NTP=yes only when NTP is yes, otherwise report NTP disabled.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: enabling NTP when ntpd or timesyncd is autodetected or explicitly enabled.
Description check ✅ Passed The description is directly related to the changeset, detailing the behavior when --enable-ntpd or --enable-timesyncd are used and how autodetection works.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
configure (2)

1711-1728: Autodetection runs even when service is explicitly enabled.

When --enable-ntpd is passed, NTPD is already yes, but the script still runs ntpd/chronyd detection. This is redundant and produces confusing output (e.g., "not found" messages even though the service was explicitly enabled).

Consider skipping autodetection when the service flag is already set:

Proposed refactor
-        printf "Checking for ntpd ... "
-        NTPD_PATH=$(_which ntpd)
-        if [ -n "$NTPD_PATH" ]; then
-            NTPD=yes
-            NTP=yes
-            echo "$NTPD_PATH (Selecting 50-ntp.conf)"
-        else
-            echo "not found"
-        fi
+        if [ "$NTPD" != "yes" ]; then
+            printf "Checking for ntpd ... "
+            NTPD_PATH=$(_which ntpd)
+            if [ -n "$NTPD_PATH" ]; then
+                NTPD=yes
+                NTP=yes
+                echo "$NTPD_PATH (Selecting 50-ntp.conf)"
+            else
+                echo "not found"
+            fi
+        fi

Apply similar logic to chronyd and timesyncd detection blocks.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@configure` around lines 1711 - 1728, The ntpd/chronyd autodetection runs
unconditionally even when the service is explicitly enabled, causing confusing
"not found" output; modify the detection blocks that set NTPD_PATH and
CHRONYD_PATH to first check the NTPD flag (e.g., test if NTPD is empty or not
"yes") and skip calling _which and the echo "not found" branch when NTPD is
already set, so only run the detection logic when NTPD is unset and preserve
setting NTPD=yes, NTP=yes and the "(Selecting 50-ntp.conf)" message only when a
binary is actually found.

42-44: CHRONYD variable is initialized but never used.

The script uses CHRONYD_PATH to store the detected path and sets NTPD=yes when chronyd is found, making the CHRONYD variable dead code. Consider removing it or using it consistently with NTPD and TIMESYNCD.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@configure` around lines 42 - 44, The CHRONYD variable is declared but never
used; either remove CHRONYD entirely or make it consistent with the other
toggles by setting and using it when chronyd is detected. Update the detection
block that currently sets CHRONYD_PATH and NTPD=yes to also set CHRONYD=yes (or
remove the CHRONYD declaration at the top and any references) and ensure any
later logic that checks NTPD or TIMESYNCD uses the correct variable(s) (CHRONYD,
NTPD, TIMESYNCD) consistently so there is no dead/unreferenced variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@configure`:
- Around line 1731-1733: The script currently echoes a warning only when both
NTPD_PATH and CHRONYD_PATH are set; add a similar warning when either NTPD_PATH
or CHRONYD_PATH is set together with TIMESYNCD_PATH so users know 50-ntp.conf
will be chosen over 50-timesyncd.conf. Locate the block referencing NTPD_PATH
and CHRONYD_PATH and insert a check like "if [ -n \"$TIMESYNCD_PATH\" ] && ([ -n
\"$NTPD_PATH\" ] || [ -n \"$CHRONYD_PATH\" ])" and echo a clear warning
indicating both an ntp implementation and timesyncd were detected and that
50-ntp.conf will be preferred over 50-timesyncd.conf.
- Around line 1706-1710: The mutual-exclusivity check for NTPD vs TIMESYNCD is
currently nested inside the HOOKSET conditional and gets skipped when
HOOKSET/--with-hooks is set; relocate the check that tests NTP, NTPD and
TIMESYNCD (the if ! [ "$NTP" = "no" ]; then ... if [ "$NTPD" = "yes" ] && [
"$TIMESYNCD" = "yes" ]; then ... exit 1 fi fi block) so it runs unconditionally
after option parsing (or immediately after the code that sets HOOKSET), ensuring
that the conflict between --enable-ntpd and --enable-timesyncd is detected even
when HOOKSET/--with-hooks is used.

---

Nitpick comments:
In `@configure`:
- Around line 1711-1728: The ntpd/chronyd autodetection runs unconditionally
even when the service is explicitly enabled, causing confusing "not found"
output; modify the detection blocks that set NTPD_PATH and CHRONYD_PATH to first
check the NTPD flag (e.g., test if NTPD is empty or not "yes") and skip calling
_which and the echo "not found" branch when NTPD is already set, so only run the
detection logic when NTPD is unset and preserve setting NTPD=yes, NTP=yes and
the "(Selecting 50-ntp.conf)" message only when a binary is actually found.
- Around line 42-44: The CHRONYD variable is declared but never used; either
remove CHRONYD entirely or make it consistent with the other toggles by setting
and using it when chronyd is detected. Update the detection block that currently
sets CHRONYD_PATH and NTPD=yes to also set CHRONYD=yes (or remove the CHRONYD
declaration at the top and any references) and ensure any later logic that
checks NTPD or TIMESYNCD uses the correct variable(s) (CHRONYD, NTPD, TIMESYNCD)
consistently so there is no dead/unreferenced variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3426624c-6f24-4fc2-815d-38dab692f874

📥 Commits

Reviewing files that changed from the base of the PR and between 0edb765 and 7ce500c.

📒 Files selected for processing (1)
  • configure

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@configure`:
- Around line 1713-1734: The autodetect block currently sets NTPD=yes when NTPD
is unset, which lets ntpd/chronyd detection override an explicit TIMESYNCD=yes;
modify the logic in the detection around the _which checks (ntpd and chronyd) so
they only set NTPD and NTP when TIMESYNCD is not explicitly set to yes (i.e.
guard the assignments to NTPD/NTP behind a check of TIMESYNCD and/or NTPD being
empty), and ensure the hook selection later still respects explicit TIMESYNCD by
not changing NTPD when TIMESYNCD=yes or when NTPD was explicitly set by the
user. Ensure you reference and update the detection code that uses _which, the
NTPD/NTP assignments, and the branch that chooses 50-ntp.conf so explicit
TIMESYNCD is preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8e43cb4d-a39c-4d83-b17e-5c54e24c4590

📥 Commits

Reviewing files that changed from the base of the PR and between b33ce6a and 5b5a103.

📒 Files selected for processing (1)
  • configure

enabled ntpd/chrony, timesyncd, or other HOOKSCRIPT method.
Service selection should disable autodetect of the other service.
@perkelix
Copy link
Copy Markdown
Contributor

perkelix commented Apr 7, 2026

Why would it complain if both --enable-ntpd and --enable-timesyncd are set? A distro might ship both hooks.

@ColinMcInnes
Copy link
Copy Markdown
Contributor Author

ColinMcInnes commented Apr 7, 2026

Why would it complain if both --enable-ntpd and --enable-timesyncd are set? A distro might ship both hooks.

I was focusing on fixing the autodetect, but that's a good point, you might not know at compile time which one you'd end up with at the end point, so if --enable is used it should not complain and allow both.

@perkelix if it's configured for both, I see that timesyncd.conf will exit if it's not present at runtime, but I don't see ntpd.conf doing the same, is that ok? that might result in it complaining loudly if timesyncd is installed on the target system.

./configure --enable-ntpd
configure args: --enable-ntpd
Deriving operating system from ... x86_64-unknown-linux
...
Testing for dlopen ... yes
Checking for ntpd ... selected via --enable-ntpd
Checking for timesyncd ... /usr/lib/systemd/systemd-timesyncd (Selecting 50-timesyncd.conf)
Checking for ypbind ... not found
Assuming ypbind is Linux
Enabling NTP support

   SYSCONFDIR =		/etc
   SBINDIR =		/sbin
   LIBDIR =		/lib
   LIBEXECDIR =		/libexec
   DBDIR =		/var/db/dhcpcd
   RUNDIR =		/var/run/dhcpcd
   MANDIR =		/usr/share/man
   DATADIR =		/usr/share
   HOOKSCRIPTS =	50-ntp.conf 50-timesyncd.conf
   EGHOOKSCRIPTS =	50-yp.conf
   STATUSARG =		
   PRIVSEPUSER =	dhcpcd

@ColinMcInnes ColinMcInnes marked this pull request as draft April 7, 2026 13:26
@perkelix
Copy link
Copy Markdown
Contributor

Obviously ntp.conf should also exit if it doesn't find the right daemon on the system.

@ColinMcInnes
Copy link
Copy Markdown
Contributor Author

Obviously ntp.conf should also exit if it doesn't find the right daemon on the system.

It looks like all it really does is configure/deconfigure the ntp.conf file for an ntp daemon and quietly requests the system restart the service, throwing errors to dev/null. So I think we're ok there.

exit hooks determine at runtime if the required feature is present on the target system, so allow both ntpd and timesyncd to be enabled by configure so it packages both sets of exit hooks (and likewise enables ntp support in dhcpcd)
@ColinMcInnes ColinMcInnes marked this pull request as ready for review April 13, 2026 17:17
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@configure`:
- Around line 1742-1750: The configure script only checks
/usr/lib/systemd/systemd-timesyncd when setting TIMESYNCD/TIMESYNCD_PATH/NTP,
but the runtime hook hooks/50-timesyncd.conf expects
/lib/systemd/systemd-timesyncd; update the autodetect loop in the configure
logic that sets TIMESYNCD and TIMESYNCD_PATH to probe both paths (at least
/usr/lib/systemd/systemd-timesyncd and /lib/systemd/systemd-timesyncd) and set
NTP=yes when one is executable so the hook installation decision matches the
runtime hook path check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c73d486a-0d1a-48ea-85b3-82c1914c242f

📥 Commits

Reviewing files that changed from the base of the PR and between 5b5a103 and aede596.

📒 Files selected for processing (1)
  • configure

Comment on lines +1742 to +1750
if [ -z "$TIMESYNCD" ]; then
TIMESYNCD_PATH=
for x in /usr/lib/systemd/systemd-timesyncd; do
if [ -x "$x" ]; then
TIMESYNCD=yes
TIMESYNCD_PATH=$x
NTP=yes
break
fi
Copy link
Copy Markdown

@coderabbitai coderabbitai bot Apr 13, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Check the same timesyncd path that the shipped hook uses.

The autodetect loop only probes /usr/lib/systemd/systemd-timesyncd, but hooks/50-timesyncd.conf checks /lib/systemd/systemd-timesyncd at runtime. On systems that only expose the /lib/... path, configure will miss timesyncd and skip installing the hook even though the runtime hook would work.

Proposed fix
-			for x in /usr/lib/systemd/systemd-timesyncd; do
+			for x in /lib/systemd/systemd-timesyncd \
+				 /usr/lib/systemd/systemd-timesyncd; do
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@configure` around lines 1742 - 1750, The configure script only checks
/usr/lib/systemd/systemd-timesyncd when setting TIMESYNCD/TIMESYNCD_PATH/NTP,
but the runtime hook hooks/50-timesyncd.conf expects
/lib/systemd/systemd-timesyncd; update the autodetect loop in the configure
logic that sets TIMESYNCD and TIMESYNCD_PATH to probe both paths (at least
/usr/lib/systemd/systemd-timesyncd and /lib/systemd/systemd-timesyncd) and set
NTP=yes when one is executable so the hook installation decision matches the
runtime hook path check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should update the timesyncd.conf as well, have it check both paths.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧩 Analysis chain

Good idea! Let me check the current content of 50-timesyncd.conf to propose the right fix.


🏁 Script executed:

#!/bin/bash
fd -i "timesyncd" --type f
fd -i "timesyncd" --type f | xargs cat

Length of output: 1505


@ColinMcInnes — agreed, both sides need updating. Here are the two changes:

1. configure — add /lib/systemd/systemd-timesyncd to the autodetect loop

-			for x in /usr/lib/systemd/systemd-timesyncd; do
+			for x in /lib/systemd/systemd-timesyncd \
+				 /usr/lib/systemd/systemd-timesyncd; do

2. hooks/50-timesyncd.conf — guard against both paths being absent

-if [ ! -x /lib/systemd/systemd-timesyncd ]; then
-	return
-fi
+if [ ! -x /lib/systemd/systemd-timesyncd ] && \
+   [ ! -x /usr/lib/systemd/systemd-timesyncd ]; then
+	return
+fi

This keeps configure's detection and the hook's runtime guard in sync — both will accept either installation path. On systems that merge /lib into /usr/lib (e.g. via a symlink), the loop in configure will naturally find it under whichever path exists first, and the hook will do the same.

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