nix-amer/internal/ser/systemd.go

36 lines
653 B
Go
Raw Normal View History

package ser
import (
"git.xdrm.io/go/nix-amer/internal/exec"
)
type systemd struct{ exec exec.Executor }
// available actions
var actions = []string{"enable", "disable", "start", "stop", "reload", "restart"}
func (d *systemd) SetExecutor(_exec exec.Executor) {
d.exec = _exec
}
2018-11-11 18:01:00 +00:00
func (d systemd) Name() string { return "systemctl" }
2018-11-11 18:01:00 +00:00
func (d systemd) Exec(action, service string) error {
// 1. fail if unknown action
known := false
for _, act := range actions {
if action == act {
known = true
break
}
}
if !known {
return ErrUnknownAction
}
// 2. execute command
return d.exec.Command("systemctl", action, service).Run()
}