From 979dfb6ee7675344fa6fed47d9f6b377f45a1121 Mon Sep 17 00:00:00 2001 From: Anirudh Goel Date: Fri, 10 Mar 2023 17:06:08 +0530 Subject: [PATCH] Do not exit if pgpool is unreachable on startup If pgpool is down on exporter startup, keep waiting for pgpool to be up --- pgpool2_exporter.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pgpool2_exporter.go b/pgpool2_exporter.go index 42aad06..ada8043 100644 --- a/pgpool2_exporter.go +++ b/pgpool2_exporter.go @@ -227,9 +227,13 @@ func NewExporter(dsn string, namespace string) *Exporter { db, err := getDBConn(dsn) - if err != nil { + // If pgpool is down on exporter startup, keep waiting for pgpool to be up + for err != nil { level.Error(Logger).Log("err", err) - os.Exit(1) + level.Info(Logger).Log("info", "Sleeping for 5 seconds before trying to connect again") + time.Sleep(5 * time.Second) + + db, err = getDBConn(dsn) } return &Exporter{