service: on darwin add ServiceCreate option.

OS X launchd doesn't create a full session for most services.
This may be a performance or security decision. Regardless
in order to create a full user session for a service set
this option to true. Leaving as false as this is the os
and historical default.
This commit is contained in:
Daniel Theophanes
2015-06-01 14:38:33 -07:00
parent 8af7c18877
commit 354e64f427
2 changed files with 16 additions and 11 deletions
+8 -6
View File
@@ -70,12 +70,14 @@ import (
)
const (
optionKeepAlive = "KeepAlive"
optionKeepAliveDefault = true
optionRunAtLoad = "RunAtLoad"
optionRunAtLoadDefault = false
optionUserService = "UserService"
optionUserServiceDefault = false
optionKeepAlive = "KeepAlive"
optionKeepAliveDefault = true
optionRunAtLoad = "RunAtLoad"
optionRunAtLoadDefault = false
optionUserService = "UserService"
optionUserServiceDefault = false
optionSessionCreate = "SessionCreate"
optionSessionCreateDefault = false
)
// Config provides the setup for a Service. The Name field is required.
+8 -5
View File
@@ -5,6 +5,7 @@
package service
import (
"errors"
"fmt"
"os"
"os/signal"
@@ -13,7 +14,6 @@ import (
"syscall"
"text/template"
"time"
"errors"
)
const maxPathSize = 32 * 1024
@@ -134,11 +134,13 @@ func (s *darwinLaunchdService) Install() error {
Path string
KeepAlive, RunAtLoad bool
SessionCreate bool
}{
Config: s.Config,
Path: path,
KeepAlive: s.Option.bool(optionKeepAlive, optionKeepAliveDefault),
RunAtLoad: s.Option.bool(optionRunAtLoad, optionRunAtLoadDefault),
Config: s.Config,
Path: path,
KeepAlive: s.Option.bool(optionKeepAlive, optionKeepAliveDefault),
RunAtLoad: s.Option.bool(optionRunAtLoad, optionRunAtLoadDefault),
SessionCreate: s.Option.bool(optionSessionCreate, optionSessionCreateDefault),
}
functions := template.FuncMap{
@@ -229,6 +231,7 @@ var launchdConfig = `<?xml version='1.0' encoding='UTF-8'?>
{{if .UserName}}<key>UserName</key><string>{{html .UserName}}</string>{{end}}
{{if .ChRoot}}<key>RootDirectory</key><string>{{html .ChRoot}}</string>{{end}}
{{if .WorkingDirectory}}<key>WorkingDirectory</key><string>{{html .WorkingDirectory}}</string>{{end}}
<key>SessionCreate</key><{{bool .SessionCreate}}/>
<key>KeepAlive</key><{{bool .KeepAlive}}/>
<key>RunAtLoad</key><{{bool .RunAtLoad}}/>
<key>Disabled</key><false/>