-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
46 lines (37 loc) · 999 Bytes
/
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
package main
import (
"github.com/robfig/cron"
"github.com/natefinch/lumberjack"
"os"
"os/signal"
"log"
"fmt"
)
func main() {
log.Println("Starting GoDoIt")
config := LoadConfig()
logger := &lumberjack.Logger{
Filename: os.ExpandEnv(config.LogFile),
MaxSize: config.LogMaxSize, // megabytes
MaxAge: config.LogMaxAge, //days
MaxBackups: config.LogMaxBackups, //days
}
log.SetOutput(logger)
scanner := NewScanner(config, logger)
cron := cron.New()
cron.AddFunc(fmt.Sprintf("@every %ds",config.ScanTime), func(){scanner.Run()})
log.Println("Starting scanner")
cron.Start()
if config.StatusInterval > 0 {
statusFunc := StatusReporterFromScript(config.StatusScript, config.StatusEnvironment, logger)
cron.AddFunc(fmt.Sprintf("@every %ds",config.StatusInterval), func(){
statusFunc(scanner.jobSets)
})
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
s := <- c
log.Println("Shutting down: ", s)
cron.Stop()
scanner.Stop()
}