diff --git a/pkg/lbagent/haproxy.go b/pkg/lbagent/haproxy.go index 4e4c146edb..16c5c11753 100644 --- a/pkg/lbagent/haproxy.go +++ b/pkg/lbagent/haproxy.go @@ -94,7 +94,7 @@ func (h *HaproxyHelper) handleCmd(ctx context.Context, cmd *LbagentCmd) { func (h *HaproxyHelper) handleStopDaemonsCmd(ctx context.Context) { files := map[string]string{ "gobetween": h.gobetweenPidFile().Path, - "haproxy": h.haproxyPidFile(), + "haproxy": h.haproxyPidFile().Path, "telegraf": h.telegrafPidFile().Path, } wg := &sync.WaitGroup{} @@ -271,8 +271,12 @@ func (h *HaproxyHelper) haproxyConfD() string { return filepath.Join(h.opts.haproxyConfigDir, "haproxy.conf.d") } -func (h *HaproxyHelper) haproxyPidFile() string { - return filepath.Join(h.opts.haproxyRunDir, "haproxy.pid") +func (h *HaproxyHelper) haproxyPidFile() *agentutils.PidFile { + pf := agentutils.NewPidFile( + filepath.Join(h.opts.haproxyRunDir, "haproxy.pid"), + "haproxy", + ) + return pf } func (h *HaproxyHelper) haproxyStatsSocketFile() string { @@ -285,15 +289,18 @@ func (h *HaproxyHelper) reloadHaproxy(ctx context.Context) error { args := []string{ h.opts.HaproxyBin, "-D", // goes daemon - "-p", pidFile, + "-p", pidFile.Path, "-C", h.haproxyConfD(), "-f", h.haproxyConfD(), } - proc := agentutils.ReadPidFile(pidFile) - if proc == nil { + proc, confirmed, err := pidFile.ConfirmOrUnlink() + if !confirmed { log.Infof("starting haproxy") return h.runCmd(args) } + if err != nil { + log.Warningln(err.Error()) + } { // try reload