-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
124 lines (103 loc) · 2.74 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"context"
"flag"
"fmt"
"jtso/association"
"jtso/config"
"jtso/kapacitor"
"jtso/logger"
_ "jtso/output"
_ "jtso/parser"
"jtso/portal"
"jtso/sqlite"
"jtso/worker"
"os"
"os/signal"
"syscall"
"time"
)
var (
ConfigFile string
)
func init() {
flag.StringVar(&ConfigFile, "config", "/etc/jtso/config.yml", "YAML configuration file path")
flag.BoolVar(&logger.Verbose, "verbose", false, "Enable verbose in the console")
}
const banner = `
██ ████████ ███████ ██████
██ ██ ██ ██ ██
██ ██ ███████ ██ ██
██ ██ ██ ██ ██ ██
█████ ██ ███████ ██████
`
func main() {
var err error
flag.Parse()
if ConfigFile == "" {
fmt.Println("Please provide the path of the Yaml configuration file")
os.Exit(0)
}
logger.StartLogger()
logger.HandlePanic()
logger.Log.Info(banner)
// Create New Config container
Cfg := config.NewConfigContainer(ConfigFile)
// Create a shared Context with cancel function
_, close := context.WithCancel(context.Background())
// wait 5 seconds to let docker DNS service to start
time.Sleep(5 * time.Second)
// Clean all kapacitor tasks
logger.Log.Info("Start cleaning all active Kapacitor tasks")
kapacitor.CleanKapa()
// Init the sqliteDB
//err = sqlite.Init("./jtso.db")
err = sqlite.Init("/etc/jtso/jtso.db")
if err != nil {
logger.Log.Errorf("unable to open DB... panic...: %v", err)
panic(err)
}
// init the webapp
webapp := portal.New(Cfg)
if Cfg.Portal.Https {
logger.Log.Infof("Start HTTPS Server - listen to %d", Cfg.Portal.Port)
} else {
logger.Log.Infof("Start HTTP Server - listen to %d", Cfg.Portal.Port)
}
go webapp.Run()
// create a ticker to refresh the Enrichment struct
ticker := time.NewTicker(Cfg.Enricher.Interval)
// Create the Thread that periodically refreshes the Enrichment struct
go func() {
for {
select {
case <-ticker.C:
worker.Collect(Cfg)
}
}
}()
// create a ticker to refresh the Enrichment struct
ticker2 := time.NewTicker(1 * time.Minute)
// Create the Thread that periodically refreshes the Enrichment struct
go func() {
for {
select {
case <-ticker2.C:
association.PeriodicCheck()
}
}
}()
// Trigger a first run of some background processes
association.PeriodicCheck()
go worker.Collect(Cfg)
go association.ConfigueStack(Cfg, "all")
// Waiting exit
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
// Send Close to all threads
close()
// close DB
defer sqlite.CloseDb()
// Bye...
fmt.Println("JTSO - received signal: ", <-c)
}