Skip to content

Commit

Permalink
Merge d04a345 into ef35c56
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaczukin committed Jun 2, 2021
2 parents ef35c56 + d04a345 commit 24d4306
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions service_systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *systemd) Platform() string {

func (s *systemd) configPath() (cp string, err error) {
if !s.isUserService() {
cp = "/etc/systemd/system/" + s.Config.Name + ".service"
cp = "/etc/systemd/system/" + s.unitName()
return
}
homeDir, err := os.UserHomeDir()
Expand All @@ -81,10 +81,14 @@ func (s *systemd) configPath() (cp string, err error) {
if err != nil {
return
}
cp = filepath.Join(systemdUserDir, s.Config.Name+".service")
cp = filepath.Join(systemdUserDir, s.unitName())
return
}

func (s *systemd) unitName() string {
return s.Config.Name + ".service"
}

func (s *systemd) getSystemdVersion() int64 {
_, out, err := runWithOutput("systemctl", "--version")
if err != nil {
Expand Down Expand Up @@ -230,7 +234,7 @@ func (s *systemd) Run() (err error) {
}

func (s *systemd) Status() (Status, error) {
exitCode, out, err := runWithOutput("systemctl", "is-active", s.Name)
exitCode, out, err := runWithOutput("systemctl", "is-active", s.unitName())
if exitCode == 0 && err != nil {
return StatusUnknown, err
}
Expand All @@ -240,7 +244,7 @@ func (s *systemd) Status() (Status, error) {
return StatusRunning, nil
case strings.HasPrefix(out, "inactive"):
// inactive can also mean its not installed, check unit files
exitCode, out, err := runWithOutput("systemctl", "list-unit-files", "-t", "service", s.Name)
exitCode, out, err := runWithOutput("systemctl", "list-unit-files", "-t", "service", s.unitName())
if exitCode == 0 && err != nil {
return StatusUnknown, err
}
Expand Down Expand Up @@ -279,7 +283,7 @@ func (s *systemd) run(action string, args ...string) error {
}

func (s *systemd) runAction(action string) error {
return s.run(action, s.Name+".service")
return s.run(action, s.unitName())
}

const systemdScript = `[Unit]
Expand Down

0 comments on commit 24d4306

Please sign in to comment.