Skip to content

Commit

Permalink
add loop to test connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkasun committed Oct 2, 2023
1 parent 06ec36a commit cac32dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cmd/netmaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"net/http"
"os"
"strings"
"time"

"github.com/bitfield/script"
Expand Down Expand Up @@ -119,10 +120,25 @@ func getLatestRelease() string {

func testConnection() {
pterm.Println("\nTesting Server setup for https://api." + domain + "/api/server/status")
for i := 1; i < 9; i++ {

if _, err := script.Get("https://api." + domain + "/api/server/status").Stdout(); err != nil {
pterm.Println("unable to connect to server, please investigate")
pterm.Println("Exiting...")
os.Exit(1)
response, err := script.Get("https://api." + domain + "/api/server/status").String()
if err != nil {
if i == 8 {
pterm.Println("Caddy is having an issue setting up certificates, please investigate (docke logs cadd)")
pterm.Println("Exiting...")
os.Exit(1)
}
if strings.Contains(response, "legitimacy of server") {
pterm.Println("certificates not yet configured, retrying ...")
} else if strings.Contains(response, "left intact") {
pterm.Println("Certificates OK")
break
} else {
secs := i*5 + 10
pterm.Println("issue establishing connection, retrying in ", secs, " seconds...")
time.Sleep(time.Second * time.Duration(i*5+10))
}
}
}
}
Binary file modified nm-install
Binary file not shown.

0 comments on commit cac32dc

Please sign in to comment.