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

@@ -17,6 +17,7 @@ After=network.target
[Service]
Type=simple
User={{.ServiceUser}}
ExecStart={{.ExecStart}}
ExecStop={{.ExecStop}}
Restart=on-failure
@@ -49,6 +50,7 @@ type templateData struct {
Unit config.Unit
ExecStart string
ExecStop string
ServiceUser string
}
// ServiceName returns the systemd service name for a unit, with optional prefix/suffix.
@@ -57,7 +59,7 @@ func ServiceName(u config.Unit, prefix, suffix string) string {
}
// Generate produces the .service file content for a unit.
func Generate(u config.Unit, prefix, suffix string) (string, error) {
func Generate(u config.Unit, prefix, suffix, serviceUser string) (string, error) {
execStart, execStop := buildExecCommands(u)
data := templateData{
@@ -65,6 +67,7 @@ func Generate(u config.Unit, prefix, suffix string) (string, error) {
Unit: u,
ExecStart: execStart,
ExecStop: execStop,
ServiceUser: serviceUser,
}
tmplStr := systemUnitTemplate