Skip to content

refactor(daemon): share systemctl command helper - #1589

Merged
skevetter merged 1 commit into
mainfrom
refactor/daemon-systemctl-helper
Oct 19, 2026
Merged

skevetter merged 1 commit into
mainfrom
refactor/daemon-systemctl-helper

Conversation

@skevetter

@skevetter skevetter commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add runSystemctl, runServiceAction, and systemctlErr helpers in pkg/daemon/agent/daemon.go; runSystemctl is the only exec.Command("systemctl", ...) call.
  • Migrate all six sites: is-active, daemon-reload (x2), enable, restart, start, stop/disable via systemctlIgnoringNotLoaded.
  • Extract isMissingUnitOutput (pure "not loaded" / "does not exist" check) and cover it with TestIsMissingUnitOutput.
  • Error text, log messages, fallback-to-startFallbackDaemon behaviour and the active trim check are unchanged.

Why

Six call sites repeated exec.Command(...).CombinedOutput(), the same systemctl X: %s: %w error format and a per-site //nolint:gosec. One helper makes the command boundary and its error format a single place, and the not-loaded classification becomes testable without real systemctl.

Validation

  • mise run cli:format (ran; no changes)
  • mise run cli:lint:ci (ran; only executes golangci-lint config verify, 0 issues)
  • golangci-lint run --new-from-rev=origin/main ./pkg/daemon/... (0 issues)
  • golangci-lint run ./pkg/daemon/... (4 issues, all in pkg/daemon/platform, untouched by this PR)
  • go test ./pkg/daemon/... (pass)
  • go test ./pkg/daemon/agent/ -run TestIsMissingUnitOutput -v (pass)
  • GOOS=linux go build ./... and GOOS=windows go build ./pkg/daemon/... (pass)
  • Added-comment scan of git diff origin/main -U0

CodeRabbit CLI

coderabbit review --agent --committed failed twice with Connection failed: WebSocket closed (server-side). No findings were produced. The GitHub CodeRabbit review still gates.

Auto-merge

Eligible: no (strict reading). Behaviour-preserving, size cap met: 63 changed non-test lines in 1 file (34 added, 29 removed). The one blocker is the policy's "no //nolint added": runSystemctl carries one new //nolint:gosec, replacing five existing systemctl nolints (file total 7 to 3).

Next

None.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error reporting for service management operations, including clearer details when commands fail.
    • Service removal now handles already-missing services without reporting them as errors.

@skevetter skevetter added the auto-refactor Automated refactor PR label Oct 19, 2026
@netlify

netlify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit 19fc88a
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6ad624572b0cbdd2aff69a96

@netlify

netlify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit 19fc88a
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6ad62457b8cbe0e9c2cb042d

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cffe3108-4c31-45ed-a0f8-f406d7be93c8
📥 Commits

Reviewing files that changed from the base of the PR and between d710ebb and 19fc88a.

📒 Files selected for processing: 2
  • pkg/daemon/agent/daemon.go
  • pkg/daemon/agent/daemon_test.go
📝 Walkthrough

Systemd commands now use shared helpers that return command output and include it in errors. Service-running checks and unit lifecycle operations use these helpers. Removal treats output indicating a missing unit as a no-op, with tests covering missing-unit and other output.

Changes: Systemd command handling

Layer / File(s) Summary
Shared command helpers
pkg/daemon/agent/daemon.go
Added helpers to run systemd commands, run service actions, and format errors with command output. The service-running check uses the shared helpers and trims output before checking for active.
Install and service lifecycle
pkg/daemon/agent/daemon.go
Unit installation and service enable, restart, and start operations use the shared helpers. Existing restart and start conditions remain unchanged.
Removal and missing-unit handling
pkg/daemon/agent/daemon.go, pkg/daemon/agent/daemon_test.go
Removal uses the shared helpers for stop, disable, and daemon reload. Missing-unit output remains a no-op; tests cover missing-unit, access-denied, and empty output.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 19fc8

The shared systemd helpers preserve the existing command and lifecycle behavior. No actionable merge-blocking risk is established by the reviewed changes.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description explains the implementation, rationale, validation results, and known lint limitation, but it does not follow the required template. It omits the required Type of change, AI assistance… Rewrite the description using the repository template. Include the What and why section with an issue reference or 'none', select the Refactor type, complete the AI assistance disclosure and required attestations, complete the Testing secti…
Docstring Coverage Warning Docstring coverage is 38.46% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: sharing the systemctl command helper in the daemon.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the implementation, rationale, validation results, and known lint limitation, but it does not follow the required template. It omits the required Type of change, AI assistance, Testing, Checklist, and Notes for reviewers sections, plus the required issue reference and checklist confirmations.

Resolution

Rewrite the description using the repository template. Include the What and why section with an issue reference or 'none', select the Refactor type, complete the AI assistance disclosure and required attestations, complete the Testing section with integration-test applicability and manual verification, and complete the Checklist. Preserve the existing implementation and validation details in the appropriate sections.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@skevetter
skevetter marked this pull request as ready for review October 19, 2026 18:01
@mergify

mergify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@skevetter
skevetter merged commit db3b204 into main Oct 19, 2026
199 of 201 checks passed
@skevetter
skevetter deleted the refactor/daemon-systemctl-helper branch October 19, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-refactor Automated refactor PR size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant