fix(systemd): include service user in service file generation

* Add ServiceUser field to Config struct for user specification.
* Update Generate and Install functions to accept service user.
* Modify tests to reflect changes in service user handling.
This commit is contained in:
Hein
2026-04-08 13:30:07 +02:00
parent e4d6f3a4a2
commit d8c90e4fff
5 changed files with 31 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ package config
import (
"fmt"
"os"
"os/user"
"path/filepath"
"gopkg.in/yaml.v3"
@@ -24,9 +25,21 @@ type Unit struct {
// Config is the root config structure.
type Config struct {
Units []Unit `yaml:"units"`
Prefix string `yaml:"prefix,omitempty"` // prepended to generated service name, e.g. "prod-"
Suffix string `yaml:"suffix,omitempty"` // appended to generated service name, e.g. "-svc"
Units []Unit `yaml:"units"`
Prefix string `yaml:"prefix,omitempty"` // prepended to generated service name, e.g. "prod-"
Suffix string `yaml:"suffix,omitempty"` // appended to generated service name, e.g. "-svc"
ServiceUser string `yaml:"service_user,omitempty"` // User= in [Service] section; defaults to "unitdore"
}
// EffectiveServiceUser returns the configured service user, or the current OS user if unset.
func (c *Config) EffectiveServiceUser() string {
if c.ServiceUser != "" {
return c.ServiceUser
}
if u, err := user.Current(); err == nil {
return u.Username
}
return "root"
}
// Load reads and parses the config file at path.