-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (50 loc) · 1.1 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
package main
import (
"context"
"os"
"os/signal"
"syscall"
"time"
"github.com/ShoshinNikita/rview/cmd"
"github.com/ShoshinNikita/rview/pkg/rlog"
"github.com/ShoshinNikita/rview/rview"
)
func main() {
cfg, err := rview.ParseConfig()
if err != nil {
rlog.Errorf("invalid config: %s", err)
os.Exit(1)
}
cfg.BuildInfo.Print()
cfg.Print()
if cfg.DebugLogLevel {
rlog.EnableDebug()
}
rview := cmd.NewRview(cfg)
// Always shutdown service to not keep any external commands running (for example, rclone).
var (
exitCode int
startFinished <-chan struct{}
)
defer func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
rlog.Info("shutdown")
if err := rview.Shutdown(ctx); err != nil {
rlog.Error(err)
}
<-startFinished
os.Exit(exitCode)
}()
if err := rview.Prepare(); err != nil {
rlog.Error(err)
exitCode = 1
return
}
termCtx, termCtxCancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
startFinished = rview.Start(func() {
exitCode = 1
termCtxCancel()
})
<-termCtx.Done()
}