Skip to content

Commit

Permalink
v3 refactoring wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Feb 18, 2017
1 parent 1429979 commit e40da8e
Show file tree
Hide file tree
Showing 22 changed files with 1,372 additions and 1,157 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/run
.idea
/dns/geodns.conf
geodns-*-*
geodns-*-*.tar
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ install:
- go install

script:
- cd $TRAVIS_BUILD_DIR && go test -gocheck.v
- cd $TRAVIS_BUILD_DIR && make test
- go test -gocheck.v -gocheck.b -gocheck.btime=2s
24 changes: 22 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@ all: templates.go
templates.go: templates/*.html monitor.go
go generate

.PHONY: test
test:
go test $(go list ./... | grep -v /vendor/)

testrace:
go test -race $(go list ./... | grep -v /vendor/)
testrace: .PHONY
go test -race $(shell go list ./... | grep -v /vendor/)

devel:
go build -tags devel

bench:
go test -check.b -check.bmem

TARS=$(wildcard geodns-*-*.tar)

push: $(TARS) tmp-install.sh
rsync -avz tmp-install.sh $(TARS) x3.dev:webtmp/2016/07/

builds: linux-build linux-build-i386 freebsd-build push

linux-build:
docker run --rm -v `pwd`:/go/src/github.com/abh/geodns geodns-build ./build

linux-build-i386:
docker run --rm -v `pwd`:/go/src/github.com/abh/geodns geodns-build-i386 ./build

freebsd-build:
ssh 192.168.64.5 'cd go/src/github.com/abh/geodns; GOPATH=~/go ./build'
ssh [email protected] 'jexec -U ask fbsd32 /home/ask/build'

.PHONY:
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type AppConfig struct {
Token string
}
Pingdom struct {
Username string
Username string

Password string
AccountEmail string
AppKey string
Expand Down
70 changes: 37 additions & 33 deletions geodns.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import (
"time"

"github.com/abh/geodns/applog"
"github.com/abh/geodns/monitor"
"github.com/abh/geodns/querylog"
"github.com/abh/geodns/server"
"github.com/abh/geodns/zones"
"github.com/pborman/uuid"
)
Expand All @@ -45,14 +47,9 @@ var gitVersion string
var development bool

var (
serverID string
serverIP string
serverGroups []string
serverUUID = uuid.New()
serverInfo *monitor.ServerInfo
)

var timeStarted = time.Now()

var (
flagconfig = flag.String("config", "./dns/", "directory of zone files")
flagconfigfile = flag.String("configfile", "geodns.conf", "filename of config file (in 'config' directory)")
Expand All @@ -79,6 +76,11 @@ func init() {

log.SetPrefix("geodns ")
log.SetFlags(log.Lmicroseconds | log.Lshortfile)

serverInfo = &monitor.ServerInfo{}
serverInfo.UUID = uuid.New()
serverInfo.Started = time.Now()

}

func main() {
Expand All @@ -98,8 +100,6 @@ func main() {
os.Exit(0)
}

srv := Server{}

if *flaglog {
applog.Enabled = true
}
Expand All @@ -110,9 +110,9 @@ func main() {

if len(*flagidentifier) > 0 {
ids := strings.Split(*flagidentifier, ",")
serverID = ids[0]
serverInfo.ID = ids[0]
if len(ids) > 1 {
serverGroups = ids[1:]
serverInfo.Groups = ids[1:]
}
}

Expand All @@ -125,17 +125,16 @@ func main() {
}

if *flagcheckconfig {
dirName := *flagconfig

err := configReader(configFileName)
if err != nil {
log.Println("Errors reading config", err)
os.Exit(2)
}

Zones := make(zones.Zones)
srv.setupPgeodnsZone(Zones)
err = srv.zonesReadDir(dirName, Zones)
// dirName := *flagconfig
// Zones := make(zones.Zones)
// srv.setupPgeodnsZone(Zones)
// err = srv.zonesReadDir(dirName, Zones)
if err != nil {
log.Println("Errors reading zones", err)
os.Exit(2)
Expand Down Expand Up @@ -174,17 +173,6 @@ func main() {
// load (and re-load) zone data
go configWatcher(configFileName)

metrics := NewMetrics()
go metrics.Updater()

if qlc := Config.QueryLog; len(qlc.Path) > 0 {
ql, err := querylog.NewFileLogger(qlc.Path, qlc.MaxSize, qlc.Keep)
if err != nil {
log.Fatalf("Could not start file query logger: %s", err)
}
srv.SetQueryLogger(ql)
}

if *flaginter == "*" {
addrs, _ := net.InterfaceAddrs()
ips := make([]string, 0)
Expand All @@ -207,17 +195,33 @@ func main() {
log.Println("StatHat integration has been removed in favor of more generic metrics")
}

// the global-ish zones 'context' is quite a mess
zonelist := make(zones.Zones)
go monitor(zonelist)
srv.setupRootZone()
srv.setupPgeodnsZone(zonelist)
go srv.zonesReader(*flagconfig, zonelist)
mon := monitor.NewMonitor(serverInfo)
go mon.Run()

srv := server.NewServer(serverInfo)

if qlc := Config.QueryLog; len(qlc.Path) > 0 {
ql, err := querylog.NewFileLogger(qlc.Path, qlc.MaxSize, qlc.Keep)
if err != nil {
log.Fatalf("Could not start file query logger: %s", err)
}
srv.SetQueryLogger(ql)
}

muxm, err := zones.NewMuxManager(*flagconfig, srv)
if err != nil {
log.Printf("error loading zones: %s", err)
}
go muxm.Run()

for _, host := range inter {
go srv.listenAndServe(host)
go srv.ListenAndServe(host)
}

go func() {
// setup metrics httpd stuff
}()

terminate := make(chan os.Signal)
signal.Notify(terminate, os.Interrupt)

Expand Down
Loading

0 comments on commit e40da8e

Please sign in to comment.