From 570df2e9e13e2c139c8b3cb6b8dfdf8685a24e45 Mon Sep 17 00:00:00 2001 From: Nurlan Moldomurov Date: Thu, 18 Aug 2022 16:44:43 +0300 Subject: [PATCH] PMM-7 fix sidecar failing (#1156) --- agent/cmd/pmm-agent-entrypoint/main.go | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/agent/cmd/pmm-agent-entrypoint/main.go b/agent/cmd/pmm-agent-entrypoint/main.go index 94db1f67ec..d0dfb7d5e4 100644 --- a/agent/cmd/pmm-agent-entrypoint/main.go +++ b/agent/cmd/pmm-agent-entrypoint/main.go @@ -73,26 +73,28 @@ var pmmAgentProcessID = 0 func runPmmAgent(ctx context.Context, commandLineArgs []string, restartPolicy restartPolicy, l *logrus.Entry, pmmAgentSidecarSleep int) int { pmmAgentFullCommand := "pmm-admin " + strings.Join(commandLineArgs, " ") for { - l.Infof("Starting 'pmm-admin %s'...", strings.Join(commandLineArgs, " ")) - cmd := commandPmmAgent(commandLineArgs) - if err := cmd.Start(); err != nil { - l.Errorf("Can't run: '%s', Error: %s", commandLineArgs, err) - return -1 - } - var exitCode int - pmmAgentProcessID = cmd.Process.Pid select { case <-ctx.Done(): return 1 default: } - if err := cmd.Wait(); err != nil { - exitError, ok := err.(*exec.ExitError) - if !ok { - l.Errorf("Can't get exit code for '%s'. err: %s", pmmAgentFullCommand, err) - return -1 + var exitCode int + l.Infof("Starting 'pmm-admin %s'...", strings.Join(commandLineArgs, " ")) + cmd := commandPmmAgent(commandLineArgs) + if err := cmd.Start(); err != nil { + l.Errorf("Can't run: '%s', Error: %s", commandLineArgs, err) + exitCode = -1 + } else { + pmmAgentProcessID = cmd.Process.Pid + if err := cmd.Wait(); err != nil { + exitError, ok := err.(*exec.ExitError) + if !ok { + l.Errorf("Can't get exit code for '%s'. err: %s", pmmAgentFullCommand, err) + exitCode = -1 + } else { + exitCode = exitError.ExitCode() + } } - exitCode = exitError.ExitCode() } l.Infof("'%s' exited with %d", pmmAgentFullCommand, exitCode)