nix-amer/internal/ser/systemd.go

32 lines
529 B
Go

package ser
import (
"os/exec"
)
type systemd struct{}
// available actions
var actions = []string{"enable", "disable", "start", "stop", "reload", "restart"}
func (d systemd) Name() string { return "systemctl" }
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 exec.Command("systemctl", action, service).Run()
}