Repository navigation
Add Service.SetEnvironment and Service.DaemonReload - #315
Conversation
There was a problem hiding this comment.
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) intoServiceviaClient.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.
ca888ff to
ff467df
Compare
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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>
ff467df to
3bb16f4
Compare
There was a problem hiding this comment.
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.
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.