diff --git a/service_darwin.go b/service_darwin.go index 8379714..727ef2c 100644 --- a/service_darwin.go +++ b/service_darwin.go @@ -290,46 +290,58 @@ func (s *darwinLaunchdService) SystemLogger(errs chan<- error) (Logger, error) { return newSysLogger(s.Name, errs) } -var launchdConfig = ` - - - +var launchdConfig = ` + + + + Disabled + + {{- if .EnvVars}} EnvironmentVariables - {{range $k, $v := .EnvVars -}} - {{html $k}} - {{html $v}} - {{end -}} + {{- range $k, $v := .EnvVars}} + {{html $k}} + {{html $v}} + {{- end}} - Label - {{html .Name}} - ProgramArguments - - {{html .Path}} - {{range .Config.Arguments}} - {{html .}} - {{end}} - - {{if .UserName}}UserName - {{html .UserName}}{{end}} - {{if .ChRoot}}RootDirectory - {{html .ChRoot}}{{end}} - {{if .WorkingDirectory}}WorkingDirectory - {{html .WorkingDirectory}}{{end}} - SessionCreate - <{{bool .SessionCreate}}/> - KeepAlive - <{{bool .KeepAlive}}/> - RunAtLoad - <{{bool .RunAtLoad}}/> - Disabled - - - {{if .StandardOutPath}}StandardOutPath - {{html .StandardOutPath}}{{end}} - {{if .StandardErrorPath}}StandardErrorPath - {{html .StandardErrorPath}}{{end}} - + {{- end}} + KeepAlive + <{{bool .KeepAlive}}/> + Label + {{html .Name}} + ProgramArguments + + {{html .Path}} + {{- if .Config.Arguments}} + {{- range .Config.Arguments}} + {{html .}} + {{- end}} + {{- end}} + + {{- if .ChRoot}} + RootDirectory + {{html .ChRoot}} + {{- end}} + RunAtLoad + <{{bool .RunAtLoad}}/> + SessionCreate + <{{bool .SessionCreate}}/> + {{- if .StandardErrorPath}} + StandardErrorPath + {{html .StandardErrorPath}} + {{- end}} + {{- if .StandardOutPath}} + StandardOutPath + {{html .StandardOutPath}} + {{- end}} + {{- if .UserName}} + UserName + {{html .UserName}} + {{- end}} + {{- if .WorkingDirectory}} + WorkingDirectory + {{html .WorkingDirectory}} + {{- end}} + ` diff --git a/service_openrc_linux.go b/service_openrc_linux.go index 72eaba4..c678e3a 100644 --- a/service_openrc_linux.go +++ b/service_openrc_linux.go @@ -230,6 +230,10 @@ command_args="{{range .Arguments}}{{.}} {{end}}" name=$(basename $(readlink -f $command)) supervise_daemon_args="--stdout {{.LogDirectory}}/${name}.log --stderr {{.LogDirectory}}/${name}.err" +{{range $k, $v := .EnvVars -}} +export {{$k}}={{$v}} +{{end -}} + {{- if .Dependencies }} depend() { {{- range $i, $dep := .Dependencies}} diff --git a/service_sysv_linux.go b/service_sysv_linux.go index 4865040..5a98a51 100644 --- a/service_sysv_linux.go +++ b/service_sysv_linux.go @@ -207,6 +207,10 @@ pid_file="/var/run/$name.pid" stdout_log="{{.LogDirectory}}/$name.log" stderr_log="{{.LogDirectory}}/$name.err" +{{range $k, $v := .EnvVars -}} +export {{$k}}={{$v}} +{{end -}} + [ -e /etc/sysconfig/$name ] && . /etc/sysconfig/$name get_pid() { diff --git a/service_windows.go b/service_windows.go index 7a2aa33..6db1d7c 100644 --- a/service_windows.go +++ b/service_windows.go @@ -149,11 +149,11 @@ func (l WindowsLogger) NInfof(eventID uint32, format string, a ...interface{}) e var interactive = false func init() { - var err error - interactive, err = svc.IsAnInteractiveSession() + isService, err := svc.IsWindowsService() if err != nil { panic(err) } + interactive = !isService } func (ws *windowsService) String() string { @@ -241,6 +241,10 @@ func lowPrivSvc(m *mgr.Mgr, name string) (*mgr.Service, error) { } func (ws *windowsService) setEnvironmentVariablesInRegistry() error { + if len(ws.EnvVars) == 0 { + return nil + } + k, _, err := registry.CreateKey( registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Services\`+ws.Name, registry.QUERY_VALUE|registry.SET_VALUE|registry.CREATE_SUB_KEY)