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

Configpath #9

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions linux_test/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

all: sysv systemd upstart clean
all: sysv systemd upstart openrc clean

# compile `go test` binary statically
test:
@go test -c ..
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -installsuffix netgo -a -c ..

clean:
-rm service.test
Expand Down Expand Up @@ -33,3 +34,12 @@ upstart: test
@-docker rm $(shell docker ps -l -q)
@-docker rmi -f service.test.upstart
@-rm upstart/service.test

openrc: test
@echo openrc
@cp service.test openrc/
@docker build -q --tag="service.test.openrc" openrc
@-docker run service.test.openrc
@-docker rm $(shell docker ps -l -q)
@-docker rmi -f service.test.openrc
@-rm openrc/service.test
3 changes: 3 additions & 0 deletions linux_test/openrc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:latest
ADD service.test /tmp/
CMD /tmp/service.test -test.v=true
6 changes: 6 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const (
optionSysvScript = "SysvScript"
optionUpstartScript = "UpstartScript"
optionLaunchdConfig = "LaunchdConfig"
optionOpenRCScript = "OpenRCScript"
)

// Status represents service status as an byte value
Expand Down Expand Up @@ -386,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
10 changes: 6 additions & 4 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,7 +116,7 @@ func (s *aixService) template() *template.Template {
}
}

func (s *aixService) configPath() (cp string, err error) {
func (s *aixService) ConfigPath() (cp string, err error) {
cp = "/etc/rc.d/init.d/" + s.Config.Name
return
}
Expand All @@ -131,7 +133,7 @@ func (s *aixService) Install() error {
}

// write start script
confPath, err := s.configPath()
confPath, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down Expand Up @@ -182,7 +184,7 @@ func (s *aixService) Uninstall() error {
return err
}

confPath, err := s.configPath()
confPath, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down Expand Up @@ -211,7 +213,7 @@ func (s *aixService) Status() (Status, error) {
}
}

confPath, err := s.configPath()
confPath, err := s.ConfigPath()
if err != nil {
return StatusUnknown, err
}
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
10 changes: 6 additions & 4 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,7 +89,7 @@ func (s *freebsdService) template() *template.Template {
}
}

func (s *freebsdService) configPath() (cp string, err error) {
func (s *freebsdService) ConfigPath() (cp string, err error) {
cp = "/usr/local/etc/rc.d/" + s.Config.Name
return
}
Expand All @@ -99,7 +101,7 @@ func (s *freebsdService) Install() error {
}

// write start script
confPath, err := s.configPath()
confPath, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down Expand Up @@ -135,15 +137,15 @@ func (s *freebsdService) Install() error {
}

func (s *freebsdService) Uninstall() error {
cp, err := s.configPath()
cp, err := s.ConfigPath()
if err != nil {
return err
}
return os.Remove(cp)
}

func (s *freebsdService) Status() (Status, error) {
cp, err := s.configPath()
cp, err := s.ConfigPath()
if err != nil {
return StatusUnknown, err
}
Expand Down
14 changes: 14 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 All @@ -53,6 +58,15 @@ func init() {
},
new: newUpstartService,
},
linuxSystemService{
name: "linux-openrc",
detect: isOpenRC,
interactive: func() bool {
is, _ := isInteractive()
return is
},
new: newOpenRCService,
},
linuxSystemService{
name: "unix-systemv",
detect: func() bool { return true },
Expand Down
Loading