-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
101 lines (86 loc) · 1.83 KB
/
main.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
98
99
100
101
package main
import (
"flag"
"os"
"github.com/Sirupsen/logrus"
)
var c Config
var l = logrus.New()
func main() {
logq := make(chan interface{}, c.Pidzero.BufferSize)
quit := make(chan *Daemon)
pzlogger := LogRoutine{
q: logq,
log: l,
}
go pzlogger.start()
var daemonList []Daemon
for _, i := range c.Daemons {
d := Daemon{
Name: i.Name,
Command: i.Command,
Args: i.Args,
Description: i.Description,
Vital: i.Vital,
Env: i.Env,
dlog: i.Log,
q: logq,
quit: quit,
}
daemonList = append(daemonList, d)
go d.start()
}
mw := LogMiddleware{
r: l,
config: c,
}
api := API{
host: c.API.Host,
port: c.API.Port,
authEnabled: c.API.Auth.Enabled,
authKey: c.API.Auth.Key,
httpsEnabled: c.API.HTTPS.Enabled,
httpsPrivKey: c.API.HTTPS.PrivateKey,
httpsPubKey: c.API.HTTPS.PublicKey,
logping: c.API.LogPing,
accesslog: c.API.AccessLog,
q: logq,
middleware: mw,
mainlogger: l,
config: c,
}
go api.start()
// blocking call to get "quit" signal on channel
p := <-quit
if p != nil {
os.Exit(1)
}
os.Exit(0)
}
func init() {
// Do some setup stuff before starting main()
ParseArgs()
ReadConfig()
SetupLogging()
}
// ParseArgs : parses command line arguments
func ParseArgs() {
flag.StringVar(&Args.configFile, "config", "config.yaml", "Absolute path to config.yaml")
flag.Parse()
}
// ReadConfig : reads config from file
func ReadConfig() {
c.read(Args.configFile)
}
// SetupLogging : sets up logging for the rest of the app
func SetupLogging() {
l.Out = os.Stdout
if c.Pidzero.PrettyLogging == false {
l.Formatter = &logrus.JSONFormatter{}
} else {
l.Formatter = &logrus.TextFormatter{
FullTimestamp: true,
}
}
l.SetLevel(getLogLevel(c.Pidzero.LogLevel))
}