-
Notifications
You must be signed in to change notification settings - Fork 3
/
goahead.go
97 lines (79 loc) · 2.58 KB
/
goahead.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"sync"
"github.com/sirupsen/logrus"
)
var (
debug bool
verbose bool
info bool
quiet bool
buildtime string
config configSettings
clusterSettings map[string]clusterSetting
sleepingClusterChecks map[string]clusterCheck
checkCluster chan clusterCheck
startCheckerChannel chan request
mutex sync.Mutex
clusterLoggers map[string]*logrus.Entry
mainLogger *logrus.Entry
unknownLogger *logrus.Entry
checkerLogger *logrus.Entry
)
func main() {
var (
configFileFlag = flag.String("config", "./config.yml", "which config file to use, defaults to ./config.yml")
versionFlag = flag.Bool("version", false, "show build time and version number")
)
flag.BoolVar(&debug, "debug", false, "log debug output, defaults to false")
flag.Parse()
configFile := *configFileFlag
version := *versionFlag
if version {
fmt.Println("goahead version 0.0.7 Build time:", buildtime, "UTC")
os.Exit(0)
}
config = readConfigfile(configFile)
clusterLoggers = make(map[string]*logrus.Entry)
clusterSettings = make(map[string]clusterSetting)
checkCluster = make(chan clusterCheck)
sleepingClusterChecks = make(map[string]clusterCheck)
startCheckerChannel = make(chan request)
mainLogger = initLogger("goahead")
unknownLogger = initLogger("unknown")
checkerLogger = initLogger("checker")
if len(config.IncludeDir) > 0 {
if isDir(config.IncludeDir) {
mainLogger.Debug("Glob'ing with " + config.IncludeDir + "**/*.yml")
files := []string{}
err := filepath.Walk(config.IncludeDir, func(path string, f os.FileInfo, err error) error {
mainLogger.Info("Checking for file extension on file: " + path)
if filepath.Ext(path) == ".yml" {
files = append(files, path)
}
return nil
})
if len(files) == 0 {
mainLogger.Fatal("Could not find any cluster settings matching " + config.IncludeDir + "**/*.yml")
}
Debugf("found potential module versions:" + strings.Join(files, " "))
if err != nil {
mainLogger.Fatal("Failed to glob cluster settings include_dir with glob path " + config.IncludeDir + "**/*.yml Error: " + err.Error())
}
for _, f := range files {
readClusterSetting(f)
}
}
}
mainLogger.Info("Found following cluster settings:")
mainLogger.Infof("%+v\n", clusterSettings)
// check for previously create cluster state files and check if I need to restart checker
go checkCurrentClusterStates()
go serve()
select {}
}