-
-
Notifications
You must be signed in to change notification settings - Fork 108
/
main.go
83 lines (71 loc) · 1.67 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
package main
import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
"time"
"github.com/alecthomas/kong"
"github.com/crazy-max/diun/v3/internal/app"
"github.com/crazy-max/diun/v3/internal/config"
"github.com/crazy-max/diun/v3/internal/logging"
"github.com/crazy-max/diun/v3/internal/model"
"github.com/rs/zerolog/log"
)
var (
diun *app.Diun
cli model.Cli
version = "dev"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
// Parse command line
_ = kong.Parse(&cli,
kong.Name("diun"),
kong.Description(`Docker image update notifier. More info: https://github.com/crazy-max/diun`),
kong.UsageOnError(),
kong.Vars{
"version": fmt.Sprintf("%s", version),
},
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
Summary: true,
}))
// Load timezone location
location, err := time.LoadLocation(cli.Timezone)
if err != nil {
log.Panic().Err(err).Msgf("Cannot load timezone %s", cli.Timezone)
}
// Init
logging.Configure(&cli, location)
log.Info().Msgf("Starting Diun %s", version)
// Handle os signals
channel := make(chan os.Signal)
signal.Notify(channel, os.Interrupt, syscall.SIGTERM)
go func() {
sig := <-channel
diun.Close()
log.Warn().Msgf("Caught signal %v", sig)
os.Exit(0)
}()
// Load configuration
cfg, err := config.Load(cli, version)
if err != nil {
log.Fatal().Err(err).Msg("Cannot load configuration")
}
log.Debug().Msg(cfg.Display())
// Init
if diun, err = app.New(cfg, location); err != nil {
log.Fatal().Err(err).Msg("Cannot initialize Diun")
}
// Test notif
if cli.TestNotif {
diun.TestNotif()
return
}
// Start
if err = diun.Start(); err != nil {
log.Fatal().Err(err).Msg("Cannot start Diun")
}
}