From ebac6d496b0c7156c9a7ed854bfed538ade80d54 Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Mon, 7 Aug 2023 16:30:22 +0800 Subject: [PATCH] feat: display more context on binary exit Signed-off-by: Ruihang Xia --- pkg/deployer/baremetal/component/cluster.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/deployer/baremetal/component/cluster.go b/pkg/deployer/baremetal/component/cluster.go index 01c388dc..08ca72fe 100644 --- a/pkg/deployer/baremetal/component/cluster.go +++ b/pkg/deployer/baremetal/component/cluster.go @@ -82,19 +82,20 @@ func runBinary(ctx context.Context, binary string, args []string, logDir string, cmd.Stdout = outputFileWriter cmd.Stderr = outputFileWriter - logger.V(3).Infof("run binary '%s' with args: '%v', log: '%s', pid: '%s'", binary, args, logDir, pidDir) - if err := cmd.Start(); err != nil { return err } + pid := strconv.Itoa(cmd.Process.Pid) + logger.V(3).Infof("run binary '%s' with args: '%v', log: '%s', pid: '%s'", binary, args, logDir, pid) + pidFile := path.Join(pidDir, "pid") f, err := os.Create(pidFile) if err != nil { return err } - _, err = f.Write([]byte(strconv.Itoa(cmd.Process.Pid))) + _, err = f.Write([]byte(pid)) if err != nil { return err } @@ -112,7 +113,9 @@ func runBinary(ctx context.Context, binary string, args []string, logDir string, } } } - logger.Errorf("binary '%s' exited with error: %v", binary, err) + logger.Errorf("binary '%s' (pid '%s') exited with error: %v. Log at '%s'", binary, pid, err, logDir) + logger.Errorf("args: '%v'", args) + _ = outputFileWriter.Flush() } }()