fix #5: only use group when specified in both dry-run and real templates

This commit is contained in:
AJ ONeal 2019-08-05 04:40:47 -06:00
parent c8453f8d54
commit c78cd82059
3 changed files with 21 additions and 12 deletions

View File

@ -27,6 +27,8 @@
{{if .User -}} {{if .User -}}
<key>UserName</key> <key>UserName</key>
<string>{{ .User }}</string> <string>{{ .User }}</string>
{{end -}}
{{if .Group -}}
<key>GroupName</key> <key>GroupName</key>
<string>{{ .Group }}</string> <string>{{ .Group }}</string>
<key>InitGroups</key> <key>InitGroups</key>

View File

@ -159,7 +159,10 @@ func stop(conf *service.Service) error {
return nil return nil
} }
// Render will create a systemd .service file using a simple the internal template
func Render(c *service.Service) ([]byte, error) { func Render(c *service.Service) ([]byte, error) {
defaultUserGroup(c)
// Create service file from template // Create service file from template
b, err := static.ReadFile("dist/etc/systemd/system/_name_.service.tmpl") b, err := static.ReadFile("dist/etc/systemd/system/_name_.service.tmpl")
if err != nil { if err != nil {
@ -181,15 +184,7 @@ func Render(c *service.Service) ([]byte, error) {
} }
func install(c *service.Service) (string, error) { func install(c *service.Service) (string, error) {
// Linux-specific config options defaultUserGroup(c)
if c.System {
if "" == c.User {
c.User = "root"
}
}
if "" == c.Group {
c.Group = c.User
}
// Check paths first // Check paths first
serviceDir := srvSysPath serviceDir := srvSysPath
@ -230,3 +225,15 @@ func install(c *service.Service) (string, error) {
return "systemd", nil return "systemd", nil
} }
func defaultUserGroup(c *service.Service) {
// Linux-specific config options
if c.System {
if "" == c.User {
c.User = "root"
}
}
if "" == c.Group {
c.Group = c.User
}
}

File diff suppressed because one or more lines are too long