Repository navigation
recipes: install-service in the user's systemd manager with SERVICE_SCOPE=user - #69
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The watchdog’s shared fallback counter allows cross-user interference, and user-scope services lack retries after startup failures, potentially leaving recipes down when the watchdog is disabled.
2 open issues
What changed in this PR
This PR extends recipe services to use the existing SERVICE_SCOPE=user setting, allowing installation in the serving user's systemd manager without sudo.
Changes:
- Adds user-scoped unit installation, service control, lingering, and startup hints while preserving system-scope output.
- Routes watchdog checks and restarts through the user manager and stores counters in the user runtime directory.
- Adds tests and updates user documentation, generated CLI help, and the changelog.
| File | Description |
|---|---|
internal/cli/recipeservice.go |
Adds scope-aware installation, unit rendering, and service control. |
internal/cli/recipeservice_internal_test.go |
Tests user-scoped units, lingering, paths, and user validation. |
internal/cli/recipehealth.go |
Adds user-scoped watchdog commands and counter paths. |
internal/cli/recipehealth_internal_test.go |
Tests watchdog scope handling and runtime paths. |
docs/reference/cli/recipes/install-service.md |
Updates generated help for user-scoped installation. |
docs/multi-node.md |
Documents installation without sudo and lingering behavior. |
CHANGELOG.md |
Records recipe service support for SERVICE_SCOPE. |
Review effort: Balanced
Comment on lines
+75
to
+78
| if dir == "" { | ||
| dir = os.TempDir() | ||
| } | ||
| return filepath.Join(dir, strings.TrimSuffix(unit, ".service")+"-misses") |
| func renderRecipeSystemdUnit(u recipeSystemdUnit) string { | ||
| after, userLine, wantedBy := "network-online.target docker.service", "User="+u.User+"\n", "multi-user.target" | ||
| if u.UserScope { | ||
| after, userLine, wantedBy = "network-online.target", "", "default.target" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

recipes install-servicealways wrote to/etc/systemd/systemand ransudo systemctl, so a machine where the serving user has no sudo could not keep a recipe up across reboots.The single-model unit already supports
SERVICE_SCOPE=user; this brings the recipe unit in line.What changes
SERVICE_SCOPEconfig key. There is no new flag.SERVICE_SCOPE=user:~/.config/systemd/user(honoursXDG_CONFIG_HOME) and are driven withsystemctl --user.User=line, does not order againstdocker.service, and isWantedBy=default.target.loginctl enable-lingerso the units start at boot without a login. If that fails it prints a note with thesudo loginctl enable-lingercommand and carries on.--usernaming someone other than$USERis rejected, since a user manager can only run units as its own user.systemctl --usertoo, which is whereSERVICE_SCOPE=userputs that unit.systemctl --user enable --now ....--user-scopeflag onrecipes health-check. It checks and restarts the unit through the user manager and keeps its miss count under$XDG_RUNTIME_DIRinstead of/run.Not changed
migrate/upgradeRecipeUnitsstill only look in/etc/systemd/system.A user-scope unit installed by this release already names its profile, so it has nothing to upgrade.
Checks
gofmt -l .,go vet ./...,npx prettier@3.9.6 --check .go test -race ./...passes exceptinternal/detectTestProbeReportsThisMachine, which fails the same way onmainin this workspace (it depends on free RAM).tools/recipediff: vet and tests pass.go run ./scripts/gendocs.