-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
52 lines (44 loc) · 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
package main
import (
"binlog-sync/util"
"binlog-sync/sync"
"os"
"os/signal"
"syscall"
"gopkg.in/birkirb/loggers.v1/log"
"binlog-sync/config"
)
var signChannel = make(chan os.Signal, 1)
func main() {
installSign()
nodes, err := config.GetNodes()
if err != nil {
log.Fatalf("Read config error: %v\n", err)
}
log.Printf("%v", nodes.Nodes)
var waitWrapper = util.WaitGroupWrapper{}
var workers []*sync.Sync
for _, node := range nodes.Nodes {
worker := sync.NewSync(node.Host, node.User, node.Password, node.Db, node.Tables, node.ServerId, node.Urls)
waitWrapper.Wrap(func() {worker.Run()})
workers = append(workers, worker)
}
for {
select {
case <- signChannel:
CloseWorkers(workers)
goto EXIT
}
}
EXIT:
waitWrapper.Wait()
log.Infoln("main exit")
}
func CloseWorkers(workers []*sync.Sync) {
for _, worker := range workers {
close(worker.ExitCh)
}
}
func installSign() {
signal.Notify(signChannel, os.Interrupt, os.Kill, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
}