service: move UserService field to Option. Update readme. Remove beta tag.

This commit is contained in:
Daniel Theophanes
2015-05-01 08:15:06 -07:00
parent eb835b9b7e
commit 4841cf3be4
6 changed files with 30 additions and 21 deletions
+3 -4
View File
@@ -1,4 +1,4 @@
# service (BETA) # service
service will install / un-install, start / stop, and run a program as a service (daemon). 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. 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 It also can be used to detect how a program is called, from an interactive
terminal or from a service manager. 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. * 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.
+21 -11
View File
@@ -69,30 +69,40 @@ import (
"github.com/kardianos/osext" "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. // Config provides the setup for a Service. The Name field is required.
type Config struct { type Config struct {
Name string // Required name of the service. No spaces suggested. Name string // Required name of the service. No spaces suggested.
DisplayName string // Display name, spaces allowed. DisplayName string // Display name, spaces allowed.
Description string // Long description of service. Description string // Long description of service.
Dependencies []string // Array of service dependencies. UserName string // Run as username.
UserName string // Run as username. Arguments []string // Run with arguments.
Arguments []string // Run with arguments.
// Optional field to specify the executable for service. // Optional field to specify the executable for service.
// If empty the current executable is used. // If empty the current executable is used.
Executable string Executable string
// Array of service dependencies.
// Not yet implemented on Linux or OS X.
Dependencies []string
// The following fields are not supported on Windows. // The following fields are not supported on Windows.
WorkingDirectory string // Initial working directory. WorkingDirectory string // Initial working directory.
ChRoot string ChRoot string
// Install as a current user service. Only supported on OS X.
UserService bool
// System specific options. // System specific options.
// * OS X // * OS X
// - KeepAlive bool (true) // - KeepAlive bool (true)
// - RunAtLoad bool (false) // - RunAtLoad bool (false)
// - UserService bool (false) // Install as a current user service.
Option KeyValue Option KeyValue
} }
+3 -3
View File
@@ -70,7 +70,7 @@ func (s *darwinLaunchdService) String() string {
} }
func (s *darwinLaunchdService) getServiceFilePath() (string, error) { func (s *darwinLaunchdService) getServiceFilePath() (string, error) {
if s.UserService { if s.Option.bool(optionUserService, optionUserServiceDefault) {
u, err := user.Current() u, err := user.Current()
if err != nil { if err != nil {
return "", err return "", err
@@ -109,8 +109,8 @@ func (s *darwinLaunchdService) Install() error {
}{ }{
Config: s.Config, Config: s.Config,
Path: path, Path: path,
KeepAlive: s.Option.bool("KeepAlive", true), KeepAlive: s.Option.bool(optionKeepAlive, optionKeepAliveDefault),
RunAtLoad: s.Option.bool("RunAtLoad", false), RunAtLoad: s.Option.bool(optionRunAtLoad, optionRunAtLoadDefault),
} }
functions := template.FuncMap{ functions := template.FuncMap{
+1 -1
View File
@@ -46,7 +46,7 @@ func (s *systemd) String() string {
var errNoUserServiceSystemd = errors.New("User services are not supported on systemd.") var errNoUserServiceSystemd = errors.New("User services are not supported on systemd.")
func (s *systemd) configPath() (cp string, err error) { func (s *systemd) configPath() (cp string, err error) {
if s.Config.UserService { if s.Option.bool(optionUserService, optionUserServiceDefault) {
err = errNoUserServiceSystemd err = errNoUserServiceSystemd
return return
} }
+1 -1
View File
@@ -38,7 +38,7 @@ func (s *sysv) String() string {
var errNoUserServiceSystemV = errors.New("User services are not supported on SystemV.") var errNoUserServiceSystemV = errors.New("User services are not supported on SystemV.")
func (s *sysv) configPath() (cp string, err error) { func (s *sysv) configPath() (cp string, err error) {
if s.Config.UserService { if s.Option.bool(optionUserService, optionUserServiceDefault) {
err = errNoUserServiceSystemV err = errNoUserServiceSystemV
return return
} }
+1 -1
View File
@@ -47,7 +47,7 @@ func (s *upstart) String() string {
var errNoUserServiceUpstart = errors.New("User services are not supported on Upstart.") var errNoUserServiceUpstart = errors.New("User services are not supported on Upstart.")
func (s *upstart) configPath() (cp string, err error) { func (s *upstart) configPath() (cp string, err error) {
if s.Config.UserService { if s.Option.bool(optionUserService, optionUserServiceDefault) {
err = errNoUserServiceUpstart err = errNoUserServiceUpstart
return return
} }