changeset 530:a6d732584c4e

Don't give up to configure GeoServer the first time. Type 5 times with 5 seconds between the attempts.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 28 Aug 2018 12:39:23 +0200
parents b07763345352
children 9c036b32c852
files cmd/gemma/main.go
diffstat 1 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/gemma/main.go	Tue Aug 28 12:30:41 2018 +0200
+++ b/cmd/gemma/main.go	Tue Aug 28 12:39:23 2018 +0200
@@ -4,11 +4,14 @@
 	"context"
 	"fmt"
 	"log"
+	"net"
 	"net/http"
+	"net/url"
 	"os"
 	"os/signal"
 	"path/filepath"
 	"syscall"
+	"time"
 
 	"github.com/gorilla/mux"
 	"github.com/rs/cors"
@@ -39,8 +42,24 @@
 
 	// Do GeoServer setup in background.
 	go func() {
-		if err := prepareGeoServer(); err != nil {
-			log.Printf("warn: preparing GeoServer: %v\n", err)
+		log.Println("Configure GeoServer...")
+		const maxTries = 5
+		const sleep = time.Second * 5
+
+		for try := 1; try <= maxTries; try++ {
+			err := prepareGeoServer()
+			if err != nil && try < maxTries {
+				if uerr, ok := err.(*url.Error); ok {
+					if oerr, ok := uerr.Err.(*net.OpError); ok && oerr.Op == "dial" {
+						log.Printf("Failed attempt %d of %d to configure GeoServer. "+
+							"Will try again in %s...\n", try, maxTries, sleep)
+						time.Sleep(sleep)
+						continue
+					}
+				}
+			}
+			log.Printf("warn: configure GeoServer failed: %v\n", err)
+			break
 		}
 	}()