Skip to content

Commit

Permalink
service: create a new front end api option. Allow backends to be conf…
Browse files Browse the repository at this point in the history
…igured.
  • Loading branch information
kardianos committed May 28, 2014
1 parent f3ac4f8 commit 782c783
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
27 changes: 26 additions & 1 deletion service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,32 @@ import "bitbucket.org/kardianos/osext"
// name. The description is an arbitrary string used to describe the
// service.
func NewService(name, displayName, description string) (Service, error) {
return newService(name, displayName, description)
return newService(&Config{
Name: name,
DisplayName: displayName,
Description: description,
})
}

// Alpha API. Do not yet use.
type Config struct {
Name, DisplayName, Description string

UserName string // Run as username.
Arguments []string // Run with arguments.

DependsOn []string // Other services that this depends on.
WorkingDirectory string // Service working directory.
ChRoot string
UserService bool // Install as a current user service.

// System specific parameters.
KV map[string]interface{}
}

// Alpha API. Do not yet use.
func NewServiceConfig(c *Config) (Service, error) {
return newService(c)
}

// Represents a generic way to interact with the system's service.
Expand Down
10 changes: 5 additions & 5 deletions service_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (

const maxPathSize = 32 * 1024

func newService(name, displayName, description string) (s *darwinLaunchdService, err error) {
func newService(c *Config) (s *darwinLaunchdService, err error) {
s = &darwinLaunchdService{
name: name,
displayName: displayName,
description: description,
name: c.Name,
displayName: c.DisplayName,
description: c.Description,
}

s.logger, err = syslog.New(syslog.LOG_INFO, name)
s.logger, err = syslog.New(syslog.LOG_INFO, c.Name)
if err != nil {
return nil, err
}
Expand Down
18 changes: 12 additions & 6 deletions service_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,29 @@ const (
initSystemd
)

func newService(name, displayName, description string) (Service, error) {
const systemOs = "linux"

func getFlavor() initFlavor {
flavor := initSystemV
if isUpstart() {
flavor = initUpstart
}
if isSystemd() {
flavor = initSystemd
}
return flavor
}

func newService(c *Config) (Service, error) {
s := &linuxService{
flavor: flavor,
name: name,
displayName: displayName,
description: description,
flavor: getFlavor(),
name: c.Name,
displayName: c.DisplayName,
description: c.Description,
}

var err error
s.logger, err = syslog.New(syslog.LOG_INFO, name)
s.logger, err = syslog.New(syslog.LOG_INFO, s.name)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions service_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"code.google.com/p/winsvc/svc"
)

func newService(name, displayName, description string) (*windowsService, error) {
func newService(c *Config) (*windowsService, error) {
return &windowsService{
name: name,
displayName: displayName,
description: description,
name: c.Name,
displayName: c.DisplayName,
description: c.Description,
}, nil
}

Expand Down

0 comments on commit 782c783

Please sign in to comment.