Skip to content

Commit

Permalink
added optional inteface ConfigInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmingacic committed Dec 17, 2020
1 parent ef35c56 commit 20d92e3
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 1 deletion.
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 ..

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

//ConfigInfo is an optional interface which allows for certain information to be obtained.
type ConfigInfo interface {
configPath() string
}

//ConfigPath returns location of the service file where applicable
func ConfigPath(s Service) string {
if configinfo, ok := s.(ConfigInfo); ok {
return configinfo.configPath()
}
return "not implemented"
}

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

Expand Down
5 changes: 5 additions & 0 deletions service_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func (s *aixService) template() *template.Template {
}
}

func (s *aixService) ConfigPath() string {
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
5 changes: 5 additions & 0 deletions service_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func (s *freebsdService) template() *template.Template {
}
}

func (s *freebsdService) ConfigPath() string {
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_openrc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ 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 {
path, _ := s.configPath()
return path
}

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

func (s *solarisService) ConfigPath() string {
path, _ := s.configPath()
return path
}

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

func (s *systemd) ConfigPath() string {
path, _ := s.configPath()
return path
}

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

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

func (s *sysv) ConfigPath() string {
path, _ := s.configPath()
return path
}

func (s *sysv) configPath() (cp string, err error) {
if s.Option.bool(optionUserService, optionUserServiceDefault) {
err = errNoUserServiceSystemV
Expand Down
5 changes: 5 additions & 0 deletions service_upstart_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ 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 {
path, _ := s.configPath()
return path
}

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

0 comments on commit 20d92e3

Please sign in to comment.