Skip to content

Commit

Permalink
Addressing PR remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmingacic committed Dec 18, 2020
1 parent 616adb4 commit f509d03
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 54 deletions.
13 changes: 4 additions & 9 deletions service_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,7 @@ func (s *aixService) template() *template.Template {
}
}

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

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 @@ -138,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 @@ -189,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 @@ -218,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
13 changes: 4 additions & 9 deletions service_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ func (s *freebsdService) template() *template.Template {
}
}

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

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 @@ -106,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 @@ -142,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
10 changes: 3 additions & 7 deletions service_openrc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ 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) {
return s.configPath()
}

func (s *openrc) configPath() (cp string, err error) {
func (s *openrc) ConfigPath() (cp string, err error) {
if s.Option.bool(optionUserService, optionUserServiceDefault) {
err = errNoUserServiceOpenRC
return
Expand All @@ -93,7 +89,7 @@ func (s *openrc) configPath() (cp string, err error) {
}

func (s *openrc) Install() error {
confPath, err := s.configPath()
confPath, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down Expand Up @@ -135,7 +131,7 @@ func (s *openrc) Install() error {
}

func (s *openrc) Uninstall() error {
confPath, err := s.configPath()
confPath, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down
11 changes: 3 additions & 8 deletions service_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ func (s *solarisService) template() *template.Template {
}
}

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

func (s *solarisService) configPath() (string, error) {
func (s *solarisService) ConfigPath() (string, error) {
return "/lib/svc/manifest/" + s.Prefix + "/" + s.Config.Name + ".xml", nil
}

Expand All @@ -115,7 +110,7 @@ func (s *solarisService) getFMRI() string {

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

confPath, err := s.configPath()
confPath, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down
10 changes: 3 additions & 7 deletions service_systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ func (s *systemd) Platform() string {
return s.platform
}

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

func (s *systemd) configPath() (cp string, err error) {
func (s *systemd) ConfigPath() (cp string, err error) {
if !s.isUserService() {
cp = "/etc/systemd/system/" + s.Config.Name + ".service"
return
Expand Down Expand Up @@ -140,7 +136,7 @@ func (s *systemd) isUserService() bool {
}

func (s *systemd) Install() error {
confPath, err := s.configPath()
confPath, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down Expand Up @@ -200,7 +196,7 @@ func (s *systemd) Uninstall() error {
if err != nil {
return err
}
cp, err := s.configPath()
cp, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down
10 changes: 3 additions & 7 deletions service_sysv_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ 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) {
func (s *sysv) ConfigPath() (cp string, err error) {
if s.Option.bool(optionUserService, optionUserServiceDefault) {
err = errNoUserServiceSystemV
return
Expand All @@ -70,7 +66,7 @@ func (s *sysv) template() *template.Template {
}

func (s *sysv) Install() error {
confPath, err := s.configPath()
confPath, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down Expand Up @@ -121,7 +117,7 @@ func (s *sysv) Install() error {
}

func (s *sysv) Uninstall() error {
cp, err := s.configPath()
cp, err := s.ConfigPath()
if err != nil {
return err
}
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 = s.(service.ConfigInfoer).ConfigPath()
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
10 changes: 3 additions & 7 deletions service_upstart_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ 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) {
return s.configPath()
}

func (s *upstart) configPath() (cp string, err error) {
func (s *upstart) ConfigPath() (cp string, err error) {
if s.Option.bool(optionUserService, optionUserServiceDefault) {
err = errNoUserServiceUpstart
return
Expand Down Expand Up @@ -132,7 +128,7 @@ func (s *upstart) template() *template.Template {
}

func (s *upstart) Install() error {
confPath, err := s.configPath()
confPath, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down Expand Up @@ -170,7 +166,7 @@ func (s *upstart) Install() error {
}

func (s *upstart) Uninstall() error {
cp, err := s.configPath()
cp, err := s.ConfigPath()
if err != nil {
return err
}
Expand Down

0 comments on commit f509d03

Please sign in to comment.