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 3 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
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)
}

// ConfigInfoer is an optional interface which allows for certain information to be obtained.
type ConfigInfoer interface {
configpath() (string, error)
jasmingacic marked this conversation as resolved.
Show resolved Hide resolved
}

//ConfigPath returns location of the service file where applicable
func ConfigPath(s Service) (string, error) {
jasmingacic marked this conversation as resolved.
Show resolved Hide resolved
if configinfo, ok := s.(ConfigInfoer); ok {
return configinfo.configpath()
}
return "", fmt.Errorf("ConfigInfoer 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 {
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
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 {
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_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 {
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
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
16 changes: 16 additions & 0 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ func TestRunInterrupt(t *testing.T) {
}
}

func TestConfigPath(t *testing.T) {
p := &program{}
sc := &service.Config{
Name: "go_service_test",
}
s, err := service.New(p, sc)
if err != nil {
t.Fatalf("New err: %s", err)
}

_, err = service.ConfigPath(s)
if err != nil {
t.Fatal("Failed to fetch or not implemented")
}
}

const testInstallEnv = "TEST_USER_INSTALL"

// Should always run, without asking for any permission
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