diff options
| author | Jeff Carr <[email protected]> | 2025-09-22 18:54:25 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-22 18:54:25 -0500 | 
| commit | 31c4bacc9070e6b0dd992a1d11af932e9e91a2c4 (patch) | |
| tree | 91a1c068d00e4569aced3a285a8f7a5ea7a4afdb | |
| parent | 7f20ecc4387f9d88b0645c73ac84c0723028470d (diff) | |
| -rw-r--r-- | main.go | 58 | 
1 files changed, 53 insertions, 5 deletions
@@ -5,10 +5,12 @@ package main  import (  	"embed" +	"fmt"  	"os"  	"time"  	"go.wit.com/dev/alexflint/arg" +	"go.wit.com/lib/hostname"  	"go.wit.com/lib/protobuf/zoopb"  	"go.wit.com/log"  ) @@ -37,12 +39,12 @@ func main() {  	} -	me.urlbase = "http://zookeeper.chap.wit.com:8080" -	if argv.URL != "" { -		log.Info("USING ARGV URL:", argv.URL) -		me.urlbase = argv.URL +	if err := testZoo(); err != nil { +		log.Info("FAILED TO CONNECT TO ZOOKEEPER: ", err) +		log.Info("sleeping for 3 minutes") +		time.Sleep(3 * time.Minute) +		os.Exit(0)  	} -  	me.pollDelay = 3 * time.Second  	me.failcountmax = 20 // die every minute if zookeeper can't be found @@ -54,6 +56,52 @@ func main() {  	zood() // talks to zookeeper  } +func testZoo() error { +	var err error +	if argv.URL != "" { +		log.Info("USING ARGV URL:", argv.URL) +		if err = testURL(argv.URL, me.machine); err == nil { +			me.urlbase = argv.URL +			return nil +		} +	} + +	zooname := findZookeeper() + +	url := fmt.Sprintf("http://%s:8080/", zooname) +	if err = testURL(url, me.machine); err == nil { +		me.urlbase = url +		return nil +	} +	url = fmt.Sprintf("https://%s/", zooname) +	if err = testURL(url, me.machine); err == nil { +		me.urlbase = url +		return nil +	} +	url = "http://zookeeper.wit.com:8080/" +	if err = testURL(url, me.machine); err == nil { +		me.urlbase = url +		return nil +	} +	url = "https://zookeeper.wit.com/" +	if err = testURL(url, me.machine); err == nil { +		me.urlbase = url +		return nil +	} +	return err +} + +func findZookeeper() string { +	hname, dname, err := hostname.GetDomainname() +	if err != nil { +		log.Info("error with os.Hostname()", hname, dname, err) +	} +	if dname == "" { +		return "zookeeper.wit.com" +	} +	return hostname.Join("zookeeper", dname) +} +  func testURL(urlbase string, pb *zoopb.Machine) error {  	newpb, wsPB, err := pb.HttpPost(urlbase, "test")  	if err != nil {  | 
