Skip to content

Enable ntp if autodetect ntpd or timesyncd#597

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

Enable ntp if autodetect ntpd or timesyncd#597
ColinMcInnes wants to merge 5 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

Warning

Rate limit exceeded

@ColinMcInnes has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 30 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 7 minutes and 30 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 01a45ba4-d4ba-44c2-98bd-2931d3a465b4

📥 Commits

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

📒 Files selected for processing (1)
  • configure

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
Introduce NTPD and TIMESYNCD variables and CLI options (--enable-ntpd, --disable-ntpd, --enable-timesyncd, --disable-timesyncd); validate mutual exclusion (abort if both enabled); restrict time-service detection to when NTPno; probe for ntpd/chronyd only if NTPD unset and for systemd-timesyncd only if TIMESYNCD unset; set NTP=yes on detection and emit service-specific messages; choose hook file based on selectors (50-ntp.conf when NTPD=yes, else 50-timesyncd.conf when TIMESYNCD=yes); write UNCOMMENT_NTP=yes when enabling NTP, 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 clearly summarizes the main change: enabling NTP when ntpd or timesyncd is autodetected, which matches the changeset's core functionality.
Description check ✅ Passed The description accurately relates to the changeset, covering the main points: conditional NTP enablement, hook selection logic, mutual exclusivity validation, and autodetection behavior.
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.
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.

1 participant