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
+2
View File
@@ -76,6 +76,8 @@ const (
optionRunAtLoadDefault = false optionRunAtLoadDefault = false
optionUserService = "UserService" optionUserService = "UserService"
optionUserServiceDefault = false optionUserServiceDefault = false
optionSessionCreate = "SessionCreate"
optionSessionCreateDefault = false
) )
// Config provides the setup for a Service. The Name field is required. // Config provides the setup for a Service. The Name field is required.
+4 -1
View File
@@ -5,6 +5,7 @@
package service package service
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
@@ -13,7 +14,6 @@ import (
"syscall" "syscall"
"text/template" "text/template"
"time" "time"
"errors"
) )
const maxPathSize = 32 * 1024 const maxPathSize = 32 * 1024
@@ -134,11 +134,13 @@ func (s *darwinLaunchdService) Install() error {
Path string Path string
KeepAlive, RunAtLoad bool KeepAlive, RunAtLoad bool
SessionCreate bool
}{ }{
Config: s.Config, Config: s.Config,
Path: path, Path: path,
KeepAlive: s.Option.bool(optionKeepAlive, optionKeepAliveDefault), KeepAlive: s.Option.bool(optionKeepAlive, optionKeepAliveDefault),
RunAtLoad: s.Option.bool(optionRunAtLoad, optionRunAtLoadDefault), RunAtLoad: s.Option.bool(optionRunAtLoad, optionRunAtLoadDefault),
SessionCreate: s.Option.bool(optionSessionCreate, optionSessionCreateDefault),
} }
functions := template.FuncMap{ 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 .UserName}}<key>UserName</key><string>{{html .UserName}}</string>{{end}}
{{if .ChRoot}}<key>RootDirectory</key><string>{{html .ChRoot}}</string>{{end}} {{if .ChRoot}}<key>RootDirectory</key><string>{{html .ChRoot}}</string>{{end}}
{{if .WorkingDirectory}}<key>WorkingDirectory</key><string>{{html .WorkingDirectory}}</string>{{end}} {{if .WorkingDirectory}}<key>WorkingDirectory</key><string>{{html .WorkingDirectory}}</string>{{end}}
<key>SessionCreate</key><{{bool .SessionCreate}}/>
<key>KeepAlive</key><{{bool .KeepAlive}}/> <key>KeepAlive</key><{{bool .KeepAlive}}/>
<key>RunAtLoad</key><{{bool .RunAtLoad}}/> <key>RunAtLoad</key><{{bool .RunAtLoad}}/>
<key>Disabled</key><false/> <key>Disabled</key><false/>