Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added config path to Service interface #255

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion linux_test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ all: sysv systemd upstart openrc clean

# compile `go test` binary statically
test:
@CGO_ENABLED=0 go test -installsuffix netgo -a -c ..
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -installsuffix netgo -a -c ..
jasmingacic marked this conversation as resolved.
Show resolved Hide resolved

clean:
-rm service.test
Expand Down
5 changes: 5 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ type Service interface {
Status() (Status, error)
}

// ConfigInfoer is an optional interface which allows for certain information to be obtained.
type ConfigInfoer interface {
ConfigPath() (string, error)
}

// ControlAction list valid string texts to use in Control.
var ControlAction = [5]string{"start", "stop", "restart", "install", "uninstall"}

Expand Down
7 changes: 7 additions & 0 deletions service_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const version = "aix-ssrc"

type aixSystem struct{}

var _ ConfigInfoer = &aixService{}

func (aixSystem) String() string {
return version
}
Expand Down Expand Up @@ -114,6 +116,11 @@ func (s *aixService) template() *template.Template {
}
}

func (s *aixService) configpath() string {
jasmingacic marked this conversation as resolved.
Show resolved Hide resolved
jasmingacic marked this conversation as resolved.
Show resolved Hide resolved
path, _ := s.configPath()
return path
}

func (s *aixService) configPath() (cp string, err error) {
cp = "/etc/rc.d/init.d/" + s.Config.Name
return
Expand Down
6 changes: 6 additions & 0 deletions service_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ type darwinLaunchdService struct {
userService bool
}

var _ ConfigInfoer = &darwinLaunchdService{}

func (s *darwinLaunchdService) ConfigPath() (string, error) {
return s.getServiceFilePath()
}

func (s *darwinLaunchdService) String() string {
if len(s.DisplayName) > 0 {
return s.DisplayName
Expand Down
7 changes: 7 additions & 0 deletions service_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type freebsdService struct {
*Config
}

var _ ConfigInfoer = &freebsdService{}

func (s *freebsdService) String() string {
if len(s.DisplayName) > 0 {
return s.DisplayName
Expand Down Expand Up @@ -87,6 +89,11 @@ func (s *freebsdService) template() *template.Template {
}
}

func (s *freebsdService) configpath() string {
jasmingacic marked this conversation as resolved.
Show resolved Hide resolved
path, _ := s.configPath()
return path
}

func (s *freebsdService) configPath() (cp string, err error) {
cp = "/usr/local/etc/rc.d/" + s.Config.Name
return
Expand Down
5 changes: 5 additions & 0 deletions service_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type linuxSystemService struct {
new func(i Interface, platform string, c *Config) (Service, error)
}

var _ ConfigInfoer = &linuxSystemService{}

func (sc linuxSystemService) String() string {
return sc.name
}
Expand All @@ -33,6 +35,9 @@ func (sc linuxSystemService) Interactive() bool {
func (sc linuxSystemService) New(i Interface, c *Config) (Service, error) {
return sc.new(i, sc.String(), c)
}
func (sc linuxSystemService) ConfigPath() (string, error) {
return "", fmt.Errorf("not implemented")
}

func init() {
ChooseSystem(linuxSystemService{
Expand Down
6 changes: 6 additions & 0 deletions service_openrc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type openrc struct {
*Config
}

var _ ConfigInfoer = &openrc{}

func (s *openrc) String() string {
if len(s.DisplayName) > 0 {
return s.DisplayName
Expand Down Expand Up @@ -77,6 +79,10 @@ func newOpenRCService(i Interface, platform string, c *Config) (Service, error)

var errNoUserServiceOpenRC = errors.New("user services are not supported on OpenRC")

func (s *openrc) ConfigPath() (string, error) {
jasmingacic marked this conversation as resolved.
Show resolved Hide resolved
return s.configPath()
}

func (s *openrc) configPath() (cp string, err error) {
if s.Option.bool(optionUserService, optionUserServiceDefault) {
err = errNoUserServiceOpenRC
Expand Down
7 changes: 7 additions & 0 deletions service_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type solarisService struct {
Prefix string
}

var _ ConfigInfoer = &solarisService{}

func (s *solarisService) String() string {
if len(s.DisplayName) > 0 {
return s.DisplayName
Expand Down Expand Up @@ -98,6 +100,11 @@ func (s *solarisService) template() *template.Template {
}
}

func (s *solarisService) configpath() string {
jasmingacic marked this conversation as resolved.
Show resolved Hide resolved
path, _ := s.configPath()
return path
}

func (s *solarisService) configPath() (string, error) {
return "/lib/svc/manifest/" + s.Prefix + "/" + s.Config.Name + ".xml", nil
}
Expand Down
6 changes: 6 additions & 0 deletions service_systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type systemd struct {
*Config
}

var _ ConfigInfoer = &systemd{}

func newSystemdService(i Interface, platform string, c *Config) (Service, error) {
s := &systemd{
i: i,
Expand All @@ -67,6 +69,10 @@ func (s *systemd) Platform() string {
return s.platform
}

func (s *systemd) ConfigPath() (string, error) {
return s.configPath()
jasmingacic marked this conversation as resolved.
Show resolved Hide resolved
}

func (s *systemd) configPath() (cp string, err error) {
if !s.isUserService() {
cp = "/etc/systemd/system/" + s.Config.Name + ".service"
Expand Down
6 changes: 6 additions & 0 deletions service_sysv_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type sysv struct {
*Config
}

var _ ConfigInfoer = &sysv{}

func newSystemVService(i Interface, platform string, c *Config) (Service, error) {
s := &sysv{
i: i,
Expand All @@ -44,6 +46,10 @@ func (s *sysv) Platform() string {

var errNoUserServiceSystemV = errors.New("User services are not supported on SystemV.")

func (s *sysv) ConfigPath() (string, error) {
return s.configPath()
}

func (s *sysv) configPath() (cp string, err error) {
if s.Option.bool(optionUserService, optionUserServiceDefault) {
err = errNoUserServiceSystemV
Expand Down
6 changes: 6 additions & 0 deletions service_upstart_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type upstart struct {
*Config
}

var _ ConfigInfoer = &upstart{}

func newUpstartService(i Interface, platform string, c *Config) (Service, error) {
s := &upstart{
i: i,
Expand All @@ -61,6 +63,10 @@ func (s *upstart) Platform() string {
// Upstart will be replaced by systemd in most cases anyway.
var errNoUserServiceUpstart = errors.New("User services are not supported on Upstart.")

func (s *upstart) ConfigPath() (string, error) {
jasmingacic marked this conversation as resolved.
Show resolved Hide resolved
return s.configPath()
}

func (s *upstart) configPath() (cp string, err error) {
if s.Option.bool(optionUserService, optionUserServiceDefault) {
err = errNoUserServiceUpstart
Expand Down