-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (41 loc) · 1.05 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
package main
import (
"os"
"os/signal"
"syscall"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"gitlab.com/atomys-universe/dns-updater/pkg/manager"
)
func init() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
if os.Getenv("DEBUG") == "true" {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
} else {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
viper.SetConfigName("updater")
viper.SetConfigType("yaml")
viper.AddConfigPath("./config")
viper.AutomaticEnv()
err := viper.ReadInConfig()
if err != nil {
log.Panic().Err(err).Msg("Fatal error on reading config file")
}
}
func main() {
log.Info().Msg("DNS Updater starting...")
if err := manager.ValidateConfiguration(); err != nil {
log.Fatal().Err(err).Msg("configuration is invalid")
}
go manager.Run()
log.Info().Msg("DNS Updater is running")
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
defer func() {
log.Info().Msg("Stoping DNS Updater...")
}()
<-c
}