Skip to content

optimize systemctl commands#531

Merged
creativeprojects merged 9 commits intomasterfrom
optimise-systemctl-commands
Jul 28, 2025
Merged

optimize systemctl commands#531
creativeprojects merged 9 commits intomasterfrom
optimise-systemctl-commands

Conversation

@creativeprojects
Copy link
Copy Markdown
Owner

@creativeprojects creativeprojects commented Jul 26, 2025

Optimize systemd scheduler with deferred daemon-reload and consolidated commands

This PR optimizes systemd scheduling operations through several key improvements:

Performance Optimizations:

  • Consolidate systemctl operations: Use systemctl enable --now and systemctl disable --now to combine enable/start and stop/disable operations into single commands
  • Defer daemon-reload: Only call systemctl daemon-reload when explicitly requested via --reload flag or when removing jobs, avoiding unnecessary reloads during job creation

Enhanced --reload Flag Support:

  • Add --reload flag support to schedule command
  • Implement reload hooks system to batch daemon-reload calls until handler close
  • Update documentation and command completion for the new flag

Code Structure Improvements:

  • Extract disableJob() and removeJobFiles() helper methods for better maintainability
  • Add comprehensive tests for reload flag functionality

These changes reduce the number of systemctl invocations and improve performance when managing systemd units, while maintaining backward compatibility and proper error handling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 26, 2025

Walkthrough

The Go module version in go.mod is updated from 1.24.3 to 1.24.5. The HandlerSystemd implementation in schedule/handler_systemd.go is refactored to modularise systemd unit operations by adding helper methods for disabling and removing units, unify systemctl command execution with support for extra arguments, and conditionally reload systemd based on job flags. The schedule and unschedule commands gain a new --reload flag to force a systemctl daemon-reload after file setup or removal, documented accordingly. Test completions for the schedule command are updated to include the new --reload flag. The systemd schedule reading test is extended to cover jobs with the reload flag. Additional documentation clarifies scheduling command behaviours and the new reload flag. Minor documentation improvements are made to the random key generation tool description.

Changes

File(s) Change Summary
go.mod Updated Go module version from 1.24.3 to 1.24.5.
schedule/handler_systemd.go Refactored systemd unit lifecycle management: added disableJob and removeJobFiles helpers, renamed and extended runSystemctlCommand to runSystemctlOnUnit with extra argument support, consolidated enable/start calls, and added conditional reload logic on close.
commands.go Added --reload flag to schedule command flags to force systemctl daemon-reload after setting up files (systemd only, since v0.32.0).
commands_schedule.go Added handling of --reload flag in createSchedule to set the reload flag on all jobs.
docs/content/schedules/commands.md Updated documentation for schedule and unschedule commands to clarify usage, group scheduling behaviour, and include the new --reload flag with description.
docs/content/usage/keyfile.md Revised description of the random key generation tool for clarity and detailed platform-specific random source information.
complete_test.go Updated TestCompleter to include the new --reload flag in expected completions for the schedule command.
schedule/handler_systemd_test.go Extended TestReadingSystemdScheduled with test cases for jobs including the reload flag; added TestCloseHandlerRunsDaemonReload to verify daemon-reload on close; ensured flags are cleared before appending to expected results.
commands_schedule_test.go Updated test to include --reload and --no-start flags in schedule creation command arguments.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant HandlerSystemd
    participant systemctl

    Caller->>HandlerSystemd: CreateJob(job, schedules, permission)
    HandlerSystemd->>HandlerSystemd: Get timer filename
    alt Conflicting units exist
        HandlerSystemd->>HandlerSystemd: disableJob(job, unitType, timerFile)
        HandlerSystemd->>HandlerSystemd: removeJobFiles(job, unitType, timerFile, serviceFile)
    end
    HandlerSystemd->>HandlerSystemd: Write unit files
    HandlerSystemd->>HandlerSystemd: runSystemctlOnUnit(timerName, "enable", unitType, silent, extraArgs)
    HandlerSystemd->>HandlerSystemd: runSystemctlOnUnit(timerName, "start", unitType, silent, extraArgs)
    alt reload flag set
        HandlerSystemd->>systemctl: daemon-reload
    end

    Caller->>HandlerSystemd: RemoveJob(job, permission)
    HandlerSystemd->>HandlerSystemd: disableJob(job, unitType, timerFile)
    HandlerSystemd->>HandlerSystemd: removeJobFiles(job, unitType, timerFile, serviceFile)
    alt reload flag set
        HandlerSystemd->>systemctl: daemon-reload
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5a3030 and 7e2b364.

📒 Files selected for processing (3)
  • commands.go (1 hunks)
  • commands_schedule_test.go (1 hunks)
  • schedule/handler_systemd_test.go (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • commands.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • schedule/handler_systemd_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: build
  • GitHub Check: Build and test (1.24, macos-latest)
  • GitHub Check: Build and test (1.24, ubuntu-latest)
  • GitHub Check: Build and test (1.24, windows-latest)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
commands_schedule_test.go (1)

266-266: LGTM! Proper test coverage for new --reload flag.

The addition of --reload and --no-start flags to the test arguments properly covers the new reload functionality introduced in this PR. This ensures the schedule command is tested with the new flag combinations and validates the integration of the reload logic.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch optimise-systemctl-commands

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (1)
schedule/handler_systemd.go (1)

234-261: Consider collecting all removal errors.

The removeJobFiles method handles file removal well, but currently only logs errors without returning them. Consider collecting all errors to provide comprehensive feedback.

 func (h *HandlerSystemd) removeJobFiles(job *Config, unitType systemd.UnitType, timerFile, serviceFile string) error {
 	var err error
+	var errors []error
 	unit := systemd.NewUnit(user.Current())
 	systemdPath := systemd.GetSystemDir()
 	if unitType == systemd.UserUnit {
 		systemdPath, err = unit.GetUserDir()
 		if err != nil {
 			return nil
 		}
 	}
 
 	dropInDir := systemd.GetServiceFileDropInDir(job.ProfileName, job.CommandName)
 	timerDropInDir := systemd.GetTimerFileDropInDir(job.ProfileName, job.CommandName)
 
 	obsoletes := []string{
 		path.Join(systemdPath, timerFile),
 		path.Join(systemdPath, serviceFile),
 		path.Join(systemdPath, timerDropInDir),
 		path.Join(systemdPath, dropInDir),
 	}
 
 	for _, pathToRemove := range obsoletes {
 		if err = os.RemoveAll(pathToRemove); err != nil {
 			clog.Errorf("failed removing %q, error: %s. Please remove this path", pathToRemove, err.Error())
+			errors = append(errors, fmt.Errorf("failed to remove %s: %w", pathToRemove, err))
 		}
 	}
-	return nil
+	if len(errors) > 0 {
+		return fmt.Errorf("failed to remove %d file(s)", len(errors))
+	}
+	return nil
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63dee21 and ea0d7a8.

📒 Files selected for processing (2)
  • go.mod (1 hunks)
  • schedule/handler_systemd.go (7 hunks)
🧰 Additional context used
🧠 Learnings (2)
go.mod (1)

Learnt from: creativeprojects
PR: #425
File: schedule/handler_windows.go:97-118
Timestamp: 2025-02-04T14:38:07.701Z
Learning: The shell.SplitArguments function in the resticprofile project returns only []string and does not return any error.

schedule/handler_systemd.go (1)

Learnt from: creativeprojects
PR: #425
File: systemd/read.go:87-91
Timestamp: 2025-02-04T21:32:13.942Z
Learning: In systemd package, error handling for integer conversion from service files is unnecessary since these files are generated programmatically by the software itself, ensuring clean data.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build and test (1.24, macos-latest)
  • GitHub Check: Build and test (1.24, windows-latest)
  • GitHub Check: Build and test (1.24, ubuntu-latest)
  • GitHub Check: Analyze (go)
🔇 Additional comments (7)
go.mod (1)

3-3: Go version confirmed as valid
The module specifies go 1.24.5, which is the latest stable release as of July 2025 and is recommended for production. No changes required.

schedule/handler_systemd.go (6)

118-118: Good refactoring - early variable assignment improves readability.

Moving the timerFile assignment to the beginning of the method reduces repeated calls to systemd.GetTimerFile and makes the code cleaner.


130-137: Well-structured separation of concerns.

The refactoring to use disableJob and removeJobFiles helper methods improves modularity and makes the code more maintainable. The error messages clearly indicate the specific operation that failed.


173-179: Excellent optimisation - combining enable and start operations.

The use of --quiet reduces verbose output and --now efficiently combines the enable and start operations into a single systemctl call, aligning perfectly with the PR objectives.


191-222: Clean refactoring with proper systemd notification.

The refactored RemoveJob method now properly separates concerns and explicitly calls daemon-reload to ensure systemd is aware of the configuration changes. This is a significant improvement in reliability.


224-232: Efficient implementation of the disable operation.

The disableJob helper method efficiently combines stop and disable operations using the --now flag, reducing the number of systemctl calls as intended by the PR objectives.


388-421: Excellent refactoring of systemctl command execution.

The renamed runSystemctlOnUnit function with variadic extraArgs provides a flexible and unified interface for all systemctl operations. This improves code consistency throughout the file.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 27, 2025

Codecov Report

❌ Patch coverage is 72.13115% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.27%. Comparing base (63dee21) to head (7e2b364).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
schedule/handler_systemd.go 69.64% 13 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #531      +/-   ##
==========================================
- Coverage   79.29%   79.27%   -0.02%     
==========================================
  Files         136      136              
  Lines       13264    13295      +31     
==========================================
+ Hits        10517    10539      +22     
- Misses       2326     2337      +11     
+ Partials      421      419       -2     
Flag Coverage Δ
unittests 79.27% <72.13%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 082fe06 and a2b5f46.

📒 Files selected for processing (1)
  • schedule/handler_systemd.go (6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
schedule/handler_systemd.go (3)
systemd/generate.go (7)
  • GetTimerFile (279-281)
  • SystemUnit (71-71)
  • UserUnit (70-70)
  • GetServiceFile (264-266)
  • Config (93-113)
  • UnitType (66-66)
  • NewUnit (120-125)
schedule/config.go (1)
  • Config (10-27)
user/user_other.go (1)
  • Current (11-41)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build and test (1.24, ubuntu-latest)
  • GitHub Check: Build and test (1.24, windows-latest)
  • GitHub Check: Analyze (go)
  • GitHub Check: build
🔇 Additional comments (7)
schedule/handler_systemd.go (7)

118-119: LGTM! Good caching optimisation.

Caching the timer file name early avoids repeated calls to systemd.GetTimerFile() throughout the method, improving readability and performance.


172-179: LGTM! Conditional reload implementation is correct.

The conditional systemd reload based on the "reload" flag provides users with control over when daemon-reload is executed, which aligns with the PR objectives to make this operation optional.


180-194: Excellent consolidation of enable and start operations.

The refactoring successfully combines the enable and start operations using the --now flag when no-start is not set, reducing the number of systemctl invocations as intended by the PR objectives.


213-232: LGTM! Clean refactoring of RemoveJob method.

The method now properly uses the helper methods disableJob and removeJobFiles, and includes conditional reload behaviour. The logic flow is clear and maintains proper error handling.


234-242: LGTM! Well-implemented disableJob helper method.

The method correctly combines stop and disable operations using the --now flag with --quiet for cleaner output, aligning with the PR objectives.


244-271: LGTM! Proper file cleanup implementation.

The removeJobFiles method correctly handles the removal of timer files, service files, and drop-in directories. The error logging for failed removals is appropriate, allowing the operation to continue even if some files cannot be removed.


398-431: LGTM! Enhanced function signature with variadic arguments.

The renamed runSystemctlOnUnit function now accepts variadic extra arguments, providing the flexibility needed for different systemctl operations whilst maintaining backward compatibility with existing calls.

Comment thread schedule/handler_systemd.go
…andler

- Implemented the --reload flag in createSchedule to set the reload flag for jobs.
- Updated the systemd handler to manage reload hooks and execute daemon-reload when necessary.
- Improved documentation for keyfile generation and schedule commands for clarity.
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: 0

♻️ Duplicate comments (1)
schedule/handler_systemd.go (1)

236-273: Address inconsistent error handling in helper methods.

The removeJobFiles method logs errors but always returns nil, whilst disableJob propagates errors. This inconsistency makes it difficult to diagnose failures during unit removal.

Based on the past review feedback, apply these fixes:

-func (h *HandlerSystemd) removeJobFiles(job *Config, unitType systemd.UnitType, timerFile, serviceFile string) error {
+func (h *HandlerSystemd) removeJobFiles(job *Config, unitType systemd.UnitType, timerFile, serviceFile string) error {
    // ... existing code ...
    for _, pathToRemove := range obsoletes {
-       if err = os.RemoveAll(pathToRemove); err != nil {
-           clog.Errorf("failed removing %q, error: %s. Please remove this path", pathToRemove, err.Error())
-       }
+       if err := os.RemoveAll(pathToRemove); err != nil {
+           return fmt.Errorf("failed to remove %q: %w", pathToRemove, err)
+       }
    }
    return nil
}

func (h *HandlerSystemd) disableJob(job *Config, unitType systemd.UnitType, timerFile string) error {
-   err := runSystemctlOnUnit(timerFile, systemctlDisable, unitType, job.removeOnly, flagNow, flagQuiet)
-   if err != nil {
-       return err
-   }
+   if err := runSystemctlOnUnit(timerFile, systemctlDisable, unitType, job.removeOnly, flagNow, flagQuiet); err != nil {
+       return fmt.Errorf("failed to disable unit %q: %w", timerFile, err)
+   }
    return nil
}
🧹 Nitpick comments (2)
docs/content/usage/keyfile.md (1)

10-14: Improve readability by varying sentence structure.

The static analysis tool correctly identifies repetitive sentence beginnings with "On" which creates monotonous reading. Consider restructuring for better flow.

- On Linux, FreeBSD, Dragonfly, and Solaris, Reader uses `getrandom(2)`.
- On legacy Linux (< 3.17), it uses `/dev/urandom`.
- On macOS, and OpenBSD Reader, uses `arc4random_buf(3)`.
- On NetBSD, Reader uses the kern.arandom sysctl.
- On Windows, Reader uses the ProcessPrng API.
+ Linux, FreeBSD, Dragonfly, and Solaris use `getrandom(2)`.
+ Legacy Linux (< 3.17) uses `/dev/urandom`.
+ macOS and OpenBSD use `arc4random_buf(3)`.
+ NetBSD uses the `kern.arandom` sysctl.
+ Windows uses the ProcessPrng API.
docs/content/schedules/commands.md (1)

14-14: Consider using "before" instead of "prior to" for conciseness.

The static analysis tool suggests that "prior to" might be wordy.

- In versions prior to `0.29.0`, the `--name` flag for a group scheduled all profiles in the group individually, as if the schedule command was run on each profile.
+ In versions before `0.29.0`, the `--name` flag for a group scheduled all profiles in the group individually, as if the schedule command was run on each profile.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2b5f46 and b5a3030.

📒 Files selected for processing (4)
  • commands_schedule.go (1 hunks)
  • docs/content/schedules/commands.md (2 hunks)
  • docs/content/usage/keyfile.md (1 hunks)
  • schedule/handler_systemd.go (10 hunks)
🧰 Additional context used
🧠 Learnings (2)
schedule/handler_systemd.go (1)

Learnt from: creativeprojects
PR: #425
File: systemd/read.go:87-91
Timestamp: 2025-02-04T21:32:13.942Z
Learning: In systemd package, error handling for integer conversion from service files is unnecessary since these files are generated programmatically by the software itself, ensuring clean data.

docs/content/schedules/commands.md (1)

Learnt from: creativeprojects
PR: #459
File: schtasks/schtasks.go:29-30
Timestamp: 2025-02-14T22:53:42.689Z
Learning: In the schtasks package, tasksPath is defined as a constant with value \resticprofile backup\ in taskscheduler.go. It's used as a prefix for managing task paths in the Windows Task Scheduler.

🪛 LanguageTool
docs/content/schedules/commands.md

[style] ~14-~14: ‘prior to’ might be wordy. Consider a shorter alternative.
Context: ...otice style="warning" %}} In versions prior to 0.29.0, the --name flag for a group...

(EN_WORDINESS_PREMIUM_PRIOR_TO)

docs/content/usage/keyfile.md

[style] ~12-~12: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...nux (< 3.17), it uses /dev/urandom. - On macOS, and OpenBSD Reader, uses `arc4ra...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[style] ~13-~13: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...BSD Reader, uses arc4random_buf(3). - On NetBSD, Reader uses the kern.arandom sy...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


[uncategorized] ~13-~13: Possible missing article found.
Context: ... uses arc4random_buf(3). - On NetBSD, Reader uses the kern.arandom sysctl. - On Wind...

(AI_HYDRA_LEO_MISSING_THE)


[style] ~14-~14: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... Reader uses the kern.arandom sysctl. - On Windows, Reader uses the ProcessPrng AP...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Build and test (1.24, ubuntu-latest)
  • GitHub Check: Build and test (1.24, macos-latest)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build and test (1.24, windows-latest)
  • GitHub Check: build
🔇 Additional comments (8)
docs/content/usage/keyfile.md (1)

8-8: Documentation clarity improved.

The rephrasing from the previous verbose description to a more concise form improves readability whilst maintaining accuracy.

commands_schedule.go (1)

59-63: LGTM! Consistent implementation of the reload flag.

The implementation correctly follows the established pattern used for the --no-start flag, ensuring consistent behaviour across command-line arguments. The flag is properly propagated to all scheduled jobs.

docs/content/schedules/commands.md (1)

38-38: Excellent documentation of the new reload flag.

The addition clearly explains the purpose of the --reload flag, its availability from version 0.32.0, and the specific systemd issue it addresses. This will help users understand when to use this flag.

schedule/handler_systemd.go (5)

74-83: Good implementation of deferred daemon-reload mechanism.

The addition of the Close() method with deferred daemon-reload hooks effectively addresses the PR objective of making daemon-reload conditional. This reduces unnecessary systemctl calls whilst ensuring reloads happen when needed.


188-197: Excellent consolidation of systemctl commands.

The use of --now flag with enable/disable operations effectively achieves the PR objective of reducing systemctl command calls by combining start/stop with enable/disable operations.


180-186: Conditional reload implementation looks good.

The conditional reload based on the job's "reload" flag is well-implemented and allows immediate reloading when explicitly requested, complementing the deferred reload mechanism.


406-439: Well-designed unified systemctl command execution.

The runSystemctlOnUnit function with variadic extraArgs parameter provides flexible command execution whilst maintaining consistency. This is a good abstraction that supports both the consolidated commands and various flag combinations.


358-362: Clean implementation of reload hook management.

The addReloadHook method correctly prevents duplicate entries using slices.Contains, ensuring each unit type is only reloaded once during cleanup.

@sonarqubecloud
Copy link
Copy Markdown

@creativeprojects creativeprojects merged commit 859da21 into master Jul 28, 2025
12 checks passed
@creativeprojects creativeprojects deleted the optimise-systemctl-commands branch July 28, 2025 15:00
@creativeprojects creativeprojects added this to the v0.32.0 milestone Jul 28, 2025
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