From 354e64f4274281c0a7ddcc0525c8009c597da93b Mon Sep 17 00:00:00 2001 From: Daniel Theophanes Date: Mon, 1 Jun 2015 14:38:33 -0700 Subject: [PATCH] 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. --- service.go | 14 ++++++++------ service_darwin.go | 13 ++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/service.go b/service.go index a545062..cd4326a 100644 --- a/service.go +++ b/service.go @@ -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. diff --git a/service_darwin.go b/service_darwin.go index fa87023..7386c0f 100644 --- a/service_darwin.go +++ b/service_darwin.go @@ -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 = ` {{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