Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support systemd user-specific config #118

Merged
merged 8 commits into from
Feb 3, 2025
Merged

Conversation

WasinWatt
Copy link
Collaborator

@WasinWatt WasinWatt commented Feb 1, 2025

Description

WIP

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced systemd service management with improved user mode support.
    • Refined Linux service templates for more flexible configuration.
  • Improvements

    • Streamlined integration test workflow by removing the need for elevated privileges.
    • Updated service file generation to support user-specific configurations.
    • Simplified command execution for systemd operations.
  • Bug Fixes

    • Resolved potential privilege escalation issues in service management.

Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

Walkthrough

This pull request introduces modifications to systemd service management and Linux service templates, focusing on user-specific service handling and workflow configuration. The changes primarily involve updating the GitHub Actions integration test workflow to remove sudo privileges, refactoring the systemd service creation process to support user-mode services, and adjusting service template constants to accommodate new argument structures and environment variable settings.

Changes

File Change Summary
.github/workflows/integration-tests.yml Removed sudo from integration test command execution
service/systemd.go - Added user mode support for systemd services
- Introduced new fields user and userMode
- Added methods for user service prerequisites
- Refactored systemctl and service file handling
service/template.go - Updated template comments and argument structures
- Modified environment variable settings
- Adjusted service template constants

Possibly related PRs

  • Ubuntu systemctl support & Fix relayer l2 flow #10: The changes in the main PR, which modify the command for running integration tests without sudo, are related to the retrieved PR's updates to the Create method in service/systemd.go, where the handling of service paths and commands is adjusted to eliminate the need for elevated privileges.

Suggested reviewers

  • Benzbeeb
  • traviolus

Poem

🐰 A Rabbit's Ode to Systemd Delight
Sudo's gone, user mode takes flight,
Services dance with newfound might,
Templates shift, workflows align,
No privileges needed, all's so fine!
Hop along, code's journey bright! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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
Contributor

@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 (2)
service/systemd.go (2)

17-18: Consider making service paths configurable
Currently, these const paths are hard-coded; offering configuration might help accommodate non-standard setups.


28-32: Avoid swallowing the error from user.Current()
Logging or returning the error could help diagnose unexpected runtime environments. For example:

 func NewSystemd(commandName CommandName) *Systemd {
 	currentUser, err := user.Current()
 	if err != nil {
+		fmt.Fprintf(os.Stderr, "Warning: unable to retrieve current user: %v\n", err)
 		return &Systemd{commandName: commandName}
 	}
 	return &Systemd{commandName: commandName, user: currentUser, userMode: currentUser.Uid != "0"}
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a17fd22 and 8bef567.

📒 Files selected for processing (3)
  • .github/workflows/integration-tests.yml (1 hunks)
  • service/systemd.go (4 hunks)
  • service/template.go (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run Integration Tests on Ubuntu
🔇 Additional comments (28)
service/systemd.go (21)

23-24: Struct additions look good
Storing user details and mode flag is clear and beneficial for user-specific logic.


47-78: Prerequisite checks appear thorough
Enabling lingering and setting environment variables is appropriate for user-mode systemd usage. Consider adding debug logs if enabling lingering fails frequently in certain environments.


Line range hint 80-104: Initialization logic seems correct
App home resolution and binary path selection for each command type is consistent.


105-127: User-level vs. system-level service logic is well-handled
This approach cleanly separates user-mode from root-mode.


137-138: Prerequisite call ensures environment is set
Carrying out a final check before proceeding is a robust defensive measure.


148-148: Explicit daemon reload
A straightforward systemctl call is appropriate after creating or modifying the unit file.


157-158: Enable service
Straightforward approach to enable the service upon creation.


160-168: Centralized systemctl helper
This method nicely reduces duplication, handling user-wide vs. system-wide calls in one place.


170-175: Dynamic service directory selection
Returning either the user or system location is clear.


179-181: Double-check environment prerequisites before fetching logs
Ensures journald commands have the right environment.


187-188: Log tailing
Adequate solution for streaming logs in real time.


190-196: Flexible journalctl helper
Mirrors the systemctl approach for user/system.


203-205: Prerequisite call before log pruning
Consistent usage helps ensure correct environment.


210-210: Vacuum logs
Prunes older logs effectively for the targeted unit.


214-216: Check environment before service start
Ensures the user environment is prepped.


221-221: Starting service
Simple call; logic is straightforward.


225-227: Check environment before stopping
Maintains consistency with other lifecycle methods.


232-232: Stop command
Appropriate direct call to systemctl.


236-238: Check environment before restarting
Keeps usage consistent across commands.


243-243: Service restart
In line with the overall pattern established here.


252-252: Returning computed service file path
Utilizes the user or system path logic effectively.

service/template.go (6)

242-242: Clarified parameter order in comment
Documenting the new injection order helps maintain clarity.


250-252: User field injection for upgradable Cosmovisor
Appending %[5]s for user-level control is a neat approach.


263-275: Removed user specification for non-upgradable Cosmovisor
Simplifies the template and matches the user-mode approach.


284-294: Binary template adjustments
The home directory and LD_LIBRARY_PATH usage align with the newly outlined arguments.


301-311: OPinitBot template
Parameter order updates and usage of [3]s for service name is consistent with the new approach.


318-326: Relayer template
Removal of explicit user references aligns well with user-mode logic.

.github/workflows/integration-tests.yml (1)

30-30: No more sudo
Dropping sudo aligns with the new user-mode handling in systemd.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 1, 2025
Copy link
Contributor

@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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8bef567 and 2802bdb.

📒 Files selected for processing (1)
  • service/template.go (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run Integration Tests on Ubuntu
🔇 Additional comments (4)
service/template.go (4)

252-256: Verify environment variable paths.

The environment variable paths have been updated to use %[4]s (appHome) instead of the previous path. Ensure this change is consistent with the systemd user configuration requirements.

Consider adding a comment explaining why these paths are using appHome and how they relate to user-specific configuration.


284-285: LGTM! Clear and descriptive template name.

The rename from LinuxRunBinaryTemplate to LinuxRunMinitiaBinaryTemplate improves clarity about the template's purpose.


338-338: LGTM! Consistent template mapping.

The template map has been correctly updated to use the renamed LinuxRunMinitiaBinaryTemplate.


242-242: Verify the UserField parameter usage.

The template comment indicates UserField as the 5th parameter, which is used to prefix the ExecStart command. This is likely for user-specific systemd configuration, but the usage needs to be verified.

Run the following script to check how UserField is constructed and used:

Also applies to: 250-250

✅ Verification successful

UserField Usage in LinuxRunUpgradableCosmovisorTemplate Verified

  • The template comment at line 242 indicates that the argument order is [binaryName, binaryPath, serviceName, appHome, UserField]
  • The placeholder %[5]s is present in the ExecStart definition (line 250) to prefix the command with the provided UserField value.
  • Searches confirm that no conflicting usage exists in the file.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how UserField is constructed and used in the codebase

# Search for UserField construction
rg -A 5 "UserField.*=.*"

# Search for template usage with UserField
ast-grep --pattern 'fmt.Sprintf($_, LinuxRunUpgradableCosmovisorTemplate, $$$)'

Length of output: 108


Script:

#!/bin/bash
# Description: Verify the usage of the UserField parameter and its associated %5$s usage in LinuxRunUpgradableCosmovisorTemplate within service/template.go

echo "Searching for 'UserField' in service/template.go:"
rg -n "UserField" service/template.go

echo -e "\nSearching for '%[5]s' in service/template.go:"
rg -n "%\[5\]s" service/template.go

echo -e "\nSearching for 'LinuxRunUpgradableCosmovisorTemplate' in service/template.go:"
rg -n "LinuxRunUpgradableCosmovisorTemplate" service/template.go

Length of output: 1666

service/template.go Show resolved Hide resolved
service/template.go Show resolved Hide resolved
service/template.go Show resolved Hide resolved
Copy link
Collaborator

@traviolus traviolus left a comment

Choose a reason for hiding this comment

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

LGTM

@traviolus traviolus merged commit d9b8ebe into main Feb 3, 2025
5 checks passed
@traviolus traviolus deleted the fix/user-config-systemd branch February 3, 2025 04:10
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