From 4e38d03629c4ad71e3182357df7fd6a86ed74341 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sun, 6 Jun 2021 04:55:07 -0700 Subject: [PATCH] move panic from init to exec --- util.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util.go b/util.go index 03f5cec..a132d96 100644 --- a/util.go +++ b/util.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "log" "os/exec" "regexp" ) @@ -15,7 +16,9 @@ const killed = 130 func init() { path, err := exec.LookPath("systemctl") if err != nil { - panic(ErrNotInstalled) + log.Printf("%v", ErrNotInstalled) + systemctl = "" + return } systemctl = path } @@ -30,6 +33,9 @@ func execute(ctx context.Context, args []string) (string, string, int, error) { warnings string ) + if systemctl == "" { + panic(ErrNotInstalled) + } cmd := exec.CommandContext(ctx, systemctl, args...) cmd.Stdout = &stdout cmd.Stderr = &stderr