move panic from init to exec
This commit is contained in:
parent
701893ebbd
commit
4e38d03629
8
util.go
8
util.go
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
@ -15,7 +16,9 @@ const killed = 130
|
|||||||
func init() {
|
func init() {
|
||||||
path, err := exec.LookPath("systemctl")
|
path, err := exec.LookPath("systemctl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(ErrNotInstalled)
|
log.Printf("%v", ErrNotInstalled)
|
||||||
|
systemctl = ""
|
||||||
|
return
|
||||||
}
|
}
|
||||||
systemctl = path
|
systemctl = path
|
||||||
}
|
}
|
||||||
@ -30,6 +33,9 @@ func execute(ctx context.Context, args []string) (string, string, int, error) {
|
|||||||
warnings string
|
warnings string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if systemctl == "" {
|
||||||
|
panic(ErrNotInstalled)
|
||||||
|
}
|
||||||
cmd := exec.CommandContext(ctx, systemctl, args...)
|
cmd := exec.CommandContext(ctx, systemctl, args...)
|
||||||
cmd.Stdout = &stdout
|
cmd.Stdout = &stdout
|
||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user