-
Notifications
You must be signed in to change notification settings - Fork 131
/
main.go
82 lines (69 loc) · 1.9 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
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"math/rand"
"os"
"os/signal"
"runtime"
"sync"
"syscall"
"time"
_ "net/http/pprof"
"github.com/pingcap/log"
"github.com/pingcap/tidb-binlog/pkg/util"
"github.com/pingcap/tidb-binlog/pkg/version"
"github.com/pingcap/tidb-binlog/pump"
"go.uber.org/zap"
_ "google.golang.org/grpc/encoding/gzip"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
rand.Seed(time.Now().UTC().UnixNano())
cfg := pump.NewConfig()
if err := cfg.Parse(os.Args[1:]); err != nil {
log.Fatal("verifying flags failed. See 'pump --help'.", zap.Error(err))
}
if err := util.InitLogger(cfg.LogLevel, cfg.LogFile); err != nil {
log.Fatal("Failed to initialize log", zap.Error(err))
}
version.PrintVersionInfo("Pump")
log.Info("start pump...", zap.Reflect("config", cfg))
p, err := pump.NewServer(cfg)
if err != nil {
log.Fatal("creating pump server failed", zap.Error(err))
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
var wg sync.WaitGroup
go func() {
sig := <-sc
log.Info("got signal to exit.", zap.Stringer("signal", sig))
wg.Add(1)
p.Close()
log.Info("pump is closed")
wg.Done()
}()
// Start will block until the server is closed
if err := p.Start(); err != nil {
log.Error("start pump server failed", zap.Error(err))
// exit when start fail
os.Exit(2)
}
wg.Wait()
log.Info("pump exit")
}