Skip to content

Commit

Permalink
Fix init system ServiceEnvironment functions (#40)
Browse files Browse the repository at this point in the history
- replace backtick quotes with double quotes in `ServiceEnvironmentContent` so the trailing `\n` is translated to a newline
- always call `DaemonReload` after updating the service environment file (this is needed for systemd to pick up changes when it previously already knew about the service)

Signed-off-by: erdii <[email protected]>
  • Loading branch information
erdii authored Aug 23, 2021
1 parent a5204b7 commit f9fcf4c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion os/initsystem/openrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (i OpenRC) ServiceEnvironmentPath(h Host, s string) (string, error) {
func (i OpenRC) ServiceEnvironmentContent(env map[string]string) string {
var b strings.Builder
for k, v := range env {
_, _ = fmt.Fprintf(&b, `%s=%s\n`, k, strconv.Quote(v))
_, _ = fmt.Fprintf(&b, "%s=%s\n", k, strconv.Quote(v))
}

return b.String()
Expand Down
2 changes: 1 addition & 1 deletion os/initsystem/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (i Systemd) ServiceEnvironmentContent(env map[string]string) string {
var b strings.Builder
fmt.Fprintln(&b, "[Service]")
for k, v := range env {
_, _ = fmt.Fprintf(&b, `Environment=%s=%s\n`, k, strconv.Quote(v))
_, _ = fmt.Fprintf(&b, "Environment=%s=%s\n", k, strconv.Quote(v))
}

return b.String()
Expand Down
7 changes: 6 additions & 1 deletion os/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ func (c Linux) UpdateServiceEnvironment(h Host, s string, env map[string]string)
if err != nil {
return err
}
return c.WriteFile(h, fp, is.ServiceEnvironmentContent(env), "0660")
err = c.WriteFile(h, fp, is.ServiceEnvironmentContent(env), "0660")
if err != nil {
return err
}

return c.DaemonReload(h)
}

// CleanupEnvironment removes environment variable configuration
Expand Down

0 comments on commit f9fcf4c

Please sign in to comment.