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).
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.
+21 -11
View File
@@ -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
}
+3 -3
View File
@@ -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{
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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
}