forked from stefanprodan/mgob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (74 loc) · 2.12 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
package main
import (
"flag"
"os"
"os/signal"
"path"
"syscall"
"github.com/Sirupsen/logrus"
"github.com/stefanprodan/mgob/api"
"github.com/stefanprodan/mgob/backup"
"github.com/stefanprodan/mgob/config"
"github.com/stefanprodan/mgob/db"
"github.com/stefanprodan/mgob/scheduler"
)
var version = "undefined"
func main() {
var appConfig = &config.AppConfig{}
flag.StringVar(&appConfig.LogLevel, "LogLevel", "debug", "logging threshold level: debug|info|warn|error|fatal|panic")
flag.IntVar(&appConfig.Port, "Port", 8090, "HTTP port to listen on")
flag.StringVar(&appConfig.ConfigPath, "ConfigPath", "/config", "plan yml files dir")
flag.StringVar(&appConfig.StoragePath, "StoragePath", "/storage", "backup storage")
flag.StringVar(&appConfig.TmpPath, "TmpPath", "/tmp", "temporary backup storage")
flag.StringVar(&appConfig.DataPath, "DataPath", "/data", "db dir")
flag.Parse()
setLogLevel(appConfig.LogLevel)
logrus.Infof("Starting with config: %+v", appConfig)
info, err := backup.CheckMongodump()
if err != nil {
logrus.Fatal(err)
}
logrus.Info(info)
info, err = backup.CheckMinioClient()
if err != nil {
logrus.Fatal(err)
}
logrus.Info(info)
info, err = backup.CheckGCloudClient()
if err != nil {
logrus.Fatal(err)
}
logrus.Info(info)
plans, err := config.LoadPlans(appConfig.ConfigPath)
if err != nil {
logrus.Fatal(err)
}
store, err := db.Open(path.Join(appConfig.DataPath, "mgob.db"))
if err != nil {
logrus.Fatal(err)
}
statusStore, err := db.NewStatusStore(store)
if err != nil {
logrus.Fatal(err)
}
sch := scheduler.New(plans, appConfig, statusStore)
sch.Start()
server := &api.HttpServer{
Config: appConfig,
Stats: statusStore,
}
logrus.Infof("Starting HTTP server on port %v", appConfig.Port)
go server.Start(version)
//wait for SIGINT (Ctrl+C) or SIGTERM (docker stop)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigChan
logrus.Infof("Shutting down %v signal received", sig)
}
func setLogLevel(levelName string) {
level, err := logrus.ParseLevel(levelName)
if err != nil {
logrus.Fatal(err)
}
logrus.SetLevel(level)
}