Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
|
31c4bacc90 | |
|
7f20ecc438 | |
|
3a786d60fd | |
|
aeae4ddf46 |
2
Makefile
2
Makefile
|
@ -9,7 +9,7 @@ REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE=
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
./zood --version
|
./zood --version
|
||||||
./zood
|
./zood test
|
||||||
|
|
||||||
build: goimports
|
build: goimports
|
||||||
GO111MODULE=off go build -v -x \
|
GO111MODULE=off go build -v -x \
|
||||||
|
|
2
README
2
README
|
@ -1 +1,3 @@
|
||||||
This is the zookeeper daemon.
|
This is the zookeeper daemon.
|
||||||
|
|
||||||
|
It is simple. It's just designed to keep packages up to date.
|
||||||
|
|
4
argv.go
4
argv.go
|
@ -16,11 +16,15 @@ import (
|
||||||
var argv args
|
var argv args
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
|
Test *EmptyCmd `arg:"subcommand:test" help:"New to forge? This is for you.'"`
|
||||||
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"`
|
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"`
|
||||||
Port int `arg:"--port" default:"2521" help:"port to run on"`
|
Port int `arg:"--port" default:"2521" help:"port to run on"`
|
||||||
URL string `arg:"--url" help:"url to use"`
|
URL string `arg:"--url" help:"url to use"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type EmptyCmd struct {
|
||||||
|
}
|
||||||
|
|
||||||
func (args) Version() string {
|
func (args) Version() string {
|
||||||
return "zood " + VERSION + " Built on: " + BUILDTIME
|
return "zood " + VERSION + " Built on: " + BUILDTIME
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ func TimeFunction(f func()) time.Duration {
|
||||||
return time.Since(startTime) // Calculate the elapsed time
|
return time.Since(startTime) // Calculate the elapsed time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sends updates to zookeeper
|
||||||
func zood() {
|
func zood() {
|
||||||
me.dog = time.NewTicker(me.pollDelay)
|
me.dog = time.NewTicker(me.pollDelay)
|
||||||
defer me.dog.Stop()
|
defer me.dog.Stop()
|
90
main.go
90
main.go
|
@ -5,11 +5,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/hostname"
|
||||||
"go.wit.com/lib/protobuf/zoopb"
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
@ -21,31 +22,94 @@ var BUILDTIME string
|
||||||
var resources embed.FS
|
var resources embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var pp *arg.Parser
|
me = new(zoodStruct)
|
||||||
pp = arg.MustParse(&argv)
|
me.pp = arg.MustParse(&argv)
|
||||||
|
|
||||||
if pp == nil {
|
if me.pp == nil {
|
||||||
pp.WriteHelp(os.Stdout)
|
me.pp.WriteHelp(os.Stdout)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Daemon {
|
if argv.Daemon {
|
||||||
// turn off timestamps for STDOUT (systemd adds them)
|
// turn off timestamps for STDOUT (systemd adds them)
|
||||||
log.DaemonMode(true)
|
log.DaemonMode(true)
|
||||||
|
me.machine, me.fullpath = zoopb.InitDaemon()
|
||||||
|
} else {
|
||||||
|
me.machine, me.fullpath = zoopb.InitMachine()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
me = new(stuff)
|
if err := testZoo(); err != nil {
|
||||||
me.urlbase = "http://zookeeper.grid.wit.com:8080"
|
log.Info("FAILED TO CONNECT TO ZOOKEEPER: ", err)
|
||||||
if argv.URL != "" {
|
log.Info("sleeping for 3 minutes")
|
||||||
log.Info("USING ARGV URL:", argv.URL)
|
time.Sleep(3 * time.Minute)
|
||||||
me.urlbase = argv.URL
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
me.pollDelay = 3 * time.Second
|
me.pollDelay = 3 * time.Second
|
||||||
me.failcountmax = 20 // die every minute if zookeeper can't be found
|
me.failcountmax = 20 // die every minute if zookeeper can't be found
|
||||||
|
|
||||||
me.forge = forgepb.InitPB()
|
if argv.Test != nil {
|
||||||
me.machine = zoopb.InitMachine()
|
testURL(me.urlbase, me.machine)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
zood() // talks to zookeeper
|
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 {
|
||||||
|
log.Info("got error:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
wsPB.DumpClient()
|
||||||
|
newpb.Dump()
|
||||||
|
log.Info("got error:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -6,20 +6,21 @@ package main
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/lib/protobuf/zoopb"
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
)
|
)
|
||||||
|
|
||||||
var me *stuff
|
var me *zoodStruct
|
||||||
|
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type stuff struct {
|
type zoodStruct struct {
|
||||||
urlbase string // the dns name for the zookeeper
|
urlbase string // the dns name for the zookeeper
|
||||||
hostname string // my hostname
|
hostname string // my hostname
|
||||||
pollDelay time.Duration // how often to report our status
|
pollDelay time.Duration // how often to report our status
|
||||||
dog *time.Ticker // the watchdog timer
|
dog *time.Ticker // the watchdog timer
|
||||||
machine *zoopb.Machine // populated from protobuf based zoopb
|
machine *zoopb.Machine // populated from protobuf based zoopb
|
||||||
forge *forgepb.Forge // handle to forge
|
|
||||||
failcount int // how many times we've failed to contact the zookeeper
|
failcount int // how many times we've failed to contact the zookeeper
|
||||||
failcountmax int // after this, exit and let systemd restart the daemon
|
failcountmax int // after this, exit and let systemd restart the daemon
|
||||||
|
fullpath string // where to save the machine PB file
|
||||||
|
pp *arg.Parser // from go-args
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue