Skip to content

Add Service.SetEnvironment and Service.DaemonReload - #315

Merged
kke merged 3 commits into
mainfrom
service-set-environment
Apr 21, 2026
Merged

kke merged 3 commits into
mainfrom
service-set-environment

Conversation

@kke

@kke kke commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Expose service environment management and explicit daemon-reload on rig.Service, wiring up the existing initsystem.ServiceEnvironmentManager and ServiceManagerReloader interfaces.

SetEnvironment writes env variable overrides to the init system's path and creates parent directories as needed, then triggers daemon-reload when required.

DaemonReload is an explicit public call for callers that write unit files outside of rig.

A narrow serviceFS interface (MkdirAll + WriteFile) avoids coupling Service to the full remotefs.FS

Part of the rig v2 last-mile effort. Breaking API is not a concern as rig v2 is not in use yet.

@kke kke added the enhancement New feature or request label Apr 21, 2026
@kke
kke requested a review from Copilot April 21, 2026 11:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR exposes service environment override management and explicit init-system daemon reloads on rig.Service, wiring the existing initsystem.ServiceEnvironmentManager and initsystem.ServiceManagerReloader capabilities into the public rig API.

Changes:

  • Add Service.SetEnvironment(ctx, env) to write init-system-specific env override files (creating parent dirs) and trigger daemon reload when supported.
  • Add Service.DaemonReload(ctx) as an explicit public call.
  • Thread a narrow filesystem dependency (MkdirAll + WriteFile) into Service via Client.Service(), plus add unit tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
service.go Adds serviceFS plumbing plus SetEnvironment and DaemonReload APIs and related errors.
client.go Ensures Client.Service() wires filesystem access into Service for SetEnvironment.
service_test.go Adds tests covering success/error paths for the new Service methods (currently via mocks).
todo Adds a repo-level migration plan / TODO list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread service.go Resolved
Comment thread service.go Resolved
Comment thread service.go Resolved
Comment thread service.go Resolved
Comment thread service_test.go Resolved
Comment thread todo Resolved
@kke
kke requested a review from Copilot April 21, 2026 12:00
@kke
kke force-pushed the service-set-environment branch from ca888ff to ff467df Compare April 21, 2026 12:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread service.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread initsystem/openrc.go Resolved
Comment thread initsystem/systemd.go Resolved
kke added 3 commits April 21, 2026 15:21
Expose service environment management and explicit daemon-reload on
rig.Service, wiring up the existing initsystem.ServiceEnvironmentManager
and ServiceManagerReloader interfaces.

SetEnvironment writes env variable overrides to the init system's
designated path (systemd drop-in, openrc /etc/conf.d), creating parent
directories as needed, then triggers daemon-reload when required.
DaemonReload is an explicit public call for callers that write unit
files outside of rig. Enable and Disable already auto-reload.

A narrow serviceFS interface (MkdirAll + WriteFile) avoids coupling
Service to the full remotefs.FS; Client.Service() passes c.FS() to
satisfy it automatically.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
- Fix systemd ServiceEnvironmentPath: s+"service.d" → s+".service.d"
  (was producing mysvcservice.d instead of mysvc.service.d)
- Write env file with mode 0600 instead of 0644 (env files may contain
  secrets and should not be world-readable)
- Sort map keys in Systemd and OpenRC ServiceEnvironmentContent so the
  generated file is deterministic across runs
- Rename local var path→scriptPath in Service.ScriptPath to avoid
  shadowing the path package import
- Add initsystem/env_test.go with tests for path generation and content
  formatting against the real Systemd and OpenRC implementations

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Systemd: ServiceEnvironmentPath now always writes to
/etc/systemd/system/<unit>.service.d/env.conf instead of deriving
the dir from FragmentPath. FragmentPath may point to vendor dirs
(/usr/lib/systemd/system/) which are not writable and get overwritten
by package updates. The /etc/systemd/system/ drop-in location is
always correct for local admin overrides regardless of where the
unit file lives.

OpenRC: ServiceEnvironmentContent now uses shellescape.Quote on
key=value pairs, matching systemd's behaviour. Previously values
with spaces or shell metacharacters would produce broken lines
when the file was sourced by the init system.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@kke
kke force-pushed the service-set-environment branch from ff467df to 3bb16f4 Compare April 21, 2026 12:21
@kke
kke requested a review from Copilot April 21, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kke
kke marked this pull request as ready for review April 21, 2026 12:41
@kke
kke merged commit 73aca7d into main Apr 21, 2026
15 checks passed
@kke
kke deleted the service-set-environment branch April 21, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants