-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (70 loc) · 1.49 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
package main
import (
"context"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
"github.com/pingcap/br/cmd"
"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
func main() {
conf := &log.Config{Level: "info", File: log.FileLogConfig{}}
lg, p, _ := log.InitLogger(conf)
log.ReplaceGlobals(lg, p)
gCtx := context.Background()
ctx, cancel := context.WithCancel(gCtx)
go func() {
if err := http.ListenAndServe("localhost:6060", nil); err != nil {
log.Warn("fail to start pprof", zap.Error(err))
} else {
log.Info("start pprof at localhost:6060")
}
}()
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
sig := <-sc
fmt.Printf("\nGot signal [%v] to exit.\n", sig)
switch sig {
case syscall.SIGTERM:
cancel()
os.Exit(0)
default:
cancel()
os.Exit(1)
}
}()
rootCmd := &cobra.Command{
Use: "br",
Short: "br is a TiDB/TiKV cluster backup tool.",
TraverseChildren: true,
SilenceUsage: true,
PersistentPreRunE: func(c *cobra.Command, args []string) error {
// c.DebugFlags()
return cmd.Init(ctx, c)
},
}
cmd.AddFlags(rootCmd)
rootCmd.AddCommand(
cmd.NewMetaCommand(),
cmd.NewBackupCommand(),
cmd.NewRestoreCommand(),
)
rootCmd.SetArgs(os.Args[1:])
if err := rootCmd.Execute(); err != nil {
rootCmd.Println(errors.ErrorStack(err))
cancel()
os.Exit(1)
}
cancel()
}