32 lines
529 B
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()
|
||
|
|
||
|
}
|