diff --git a/README.md b/README.md index fbaeec8..f808e52 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# service (BETA) +# service service will install / un-install, start / stop, and run a program as a service (daemon). Currently supports Windows XP+, Linux/(systemd | Upstart | SysV), and OSX/Launchd. @@ -8,7 +8,6 @@ despite the substantial differences. It also can be used to detect how a program is called, from an interactive terminal or from a service manager. -## TODO +## BUGS + * Dependencies field is not implemented for Linux systems and Launchd. * OS X when running as a UserService Interactive will not be accurate. - * Determine if UserService should remain in main configuration. - * Hook up Dependencies field for Linux systems and Launchd. diff --git a/service.go b/service.go index af33822..a545062 100644 --- a/service.go +++ b/service.go @@ -69,30 +69,40 @@ import ( "github.com/kardianos/osext" ) +const ( + optionKeepAlive = "KeepAlive" + optionKeepAliveDefault = true + optionRunAtLoad = "RunAtLoad" + optionRunAtLoadDefault = false + optionUserService = "UserService" + optionUserServiceDefault = false +) + // Config provides the setup for a Service. The Name field is required. type Config struct { - Name string // Required name of the service. No spaces suggested. - DisplayName string // Display name, spaces allowed. - Description string // Long description of service. - Dependencies []string // Array of service dependencies. - UserName string // Run as username. - Arguments []string // Run with arguments. + Name string // Required name of the service. No spaces suggested. + DisplayName string // Display name, spaces allowed. + Description string // Long description of service. + UserName string // Run as username. + Arguments []string // Run with arguments. // Optional field to specify the executable for service. // If empty the current executable is used. Executable string + // Array of service dependencies. + // Not yet implemented on Linux or OS X. + Dependencies []string + // The following fields are not supported on Windows. WorkingDirectory string // Initial working directory. ChRoot string - // Install as a current user service. Only supported on OS X. - UserService bool - // System specific options. // * OS X - // - KeepAlive bool (true) - // - RunAtLoad bool (false) + // - KeepAlive bool (true) + // - RunAtLoad bool (false) + // - UserService bool (false) // Install as a current user service. Option KeyValue } diff --git a/service_darwin.go b/service_darwin.go index da8ae9b..5f427a5 100644 --- a/service_darwin.go +++ b/service_darwin.go @@ -70,7 +70,7 @@ func (s *darwinLaunchdService) String() string { } func (s *darwinLaunchdService) getServiceFilePath() (string, error) { - if s.UserService { + if s.Option.bool(optionUserService, optionUserServiceDefault) { u, err := user.Current() if err != nil { return "", err @@ -109,8 +109,8 @@ func (s *darwinLaunchdService) Install() error { }{ Config: s.Config, Path: path, - KeepAlive: s.Option.bool("KeepAlive", true), - RunAtLoad: s.Option.bool("RunAtLoad", false), + KeepAlive: s.Option.bool(optionKeepAlive, optionKeepAliveDefault), + RunAtLoad: s.Option.bool(optionRunAtLoad, optionRunAtLoadDefault), } functions := template.FuncMap{ diff --git a/service_systemd_linux.go b/service_systemd_linux.go index 95fb8e0..571683f 100644 --- a/service_systemd_linux.go +++ b/service_systemd_linux.go @@ -46,7 +46,7 @@ func (s *systemd) String() string { var errNoUserServiceSystemd = errors.New("User services are not supported on systemd.") func (s *systemd) configPath() (cp string, err error) { - if s.Config.UserService { + if s.Option.bool(optionUserService, optionUserServiceDefault) { err = errNoUserServiceSystemd return } diff --git a/service_sysv_linux.go b/service_sysv_linux.go index 658ce2f..bc15fab 100644 --- a/service_sysv_linux.go +++ b/service_sysv_linux.go @@ -38,7 +38,7 @@ func (s *sysv) String() string { var errNoUserServiceSystemV = errors.New("User services are not supported on SystemV.") func (s *sysv) configPath() (cp string, err error) { - if s.Config.UserService { + if s.Option.bool(optionUserService, optionUserServiceDefault) { err = errNoUserServiceSystemV return } diff --git a/service_upstart_linux.go b/service_upstart_linux.go index b3190e1..7cd17fd 100644 --- a/service_upstart_linux.go +++ b/service_upstart_linux.go @@ -47,7 +47,7 @@ func (s *upstart) String() string { var errNoUserServiceUpstart = errors.New("User services are not supported on Upstart.") func (s *upstart) configPath() (cp string, err error) { - if s.Config.UserService { + if s.Option.bool(optionUserService, optionUserServiceDefault) { err = errNoUserServiceUpstart return }