# HG changeset patch # User Sascha L. Teichmann # Date 1535452763 -7200 # Node ID a6d732584c4e7282c3c3cdcbd0ef4906f4862d7f # Parent b077633453527fd0edad5f709366d083b6fb1c08 Don't give up to configure GeoServer the first time. Type 5 times with 5 seconds between the attempts. diff -r b07763345352 -r a6d732584c4e cmd/gemma/main.go --- 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 } }()