Run systemd commands with --user flag (#310)
When controlling a user service with systemd supply the --user flag
This commit is contained in:
@@ -0,0 +1 @@
|
||||
.vscode/
|
||||
@@ -90,7 +90,7 @@ func (s *systemd) unitName() string {
|
||||
}
|
||||
|
||||
func (s *systemd) getSystemdVersion() int64 {
|
||||
_, out, err := runWithOutput("systemctl", "--version")
|
||||
_, out, err := s.runWithOutput("systemctl", "--version")
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
@@ -234,7 +234,7 @@ func (s *systemd) Run() (err error) {
|
||||
}
|
||||
|
||||
func (s *systemd) Status() (Status, error) {
|
||||
exitCode, out, err := runWithOutput("systemctl", "is-active", s.unitName())
|
||||
exitCode, out, err := s.runWithOutput("systemctl", "is-active", s.unitName())
|
||||
if exitCode == 0 && err != nil {
|
||||
return StatusUnknown, err
|
||||
}
|
||||
@@ -244,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.unitName())
|
||||
exitCode, out, err := s.runWithOutput("systemctl", "list-unit-files", "-t", "service", s.unitName())
|
||||
if exitCode == 0 && err != nil {
|
||||
return StatusUnknown, err
|
||||
}
|
||||
@@ -275,6 +275,13 @@ func (s *systemd) Restart() error {
|
||||
return s.runAction("restart")
|
||||
}
|
||||
|
||||
func (s *systemd) runWithOutput(command string, arguments ...string) (int, string, error) {
|
||||
if s.isUserService() {
|
||||
arguments = append(arguments, "--user")
|
||||
}
|
||||
return runWithOutput(command, arguments...)
|
||||
}
|
||||
|
||||
func (s *systemd) run(action string, args ...string) error {
|
||||
if s.isUserService() {
|
||||
return run("systemctl", append([]string{action, "--user"}, args...)...)
|
||||
|
||||
Reference in New Issue
Block a user