This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
/
main.go
76 lines (62 loc) · 2.14 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
package main
import (
"errors"
"fmt"
"os"
"code.cloudfoundry.org/lager"
bootstrapperPkg "github.com/cloudfoundry-incubator/cf-mysql-bootstrap/bootstrapper"
"github.com/cloudfoundry-incubator/cf-mysql-bootstrap/bootstrapper/node_manager"
"github.com/cloudfoundry-incubator/cf-mysql-bootstrap/clock"
"github.com/cloudfoundry-incubator/cf-mysql-bootstrap/config"
)
func main() {
rootConfig, err := config.NewConfig(os.Args)
if err != nil {
panic(fmt.Sprintf("Failed to parse config and build logger: %s", err.Error()))
}
err = rootConfig.Validate()
if err != nil {
panic(fmt.Sprintf("Invalid config: %s", err.Error()))
}
logger := rootConfig.Logger
nodeManager := node_manager.New(rootConfig, clock.DefaultClock())
bootstrapper := bootstrapperPkg.New(nodeManager)
var actionTaken bool
if rootConfig.RepairMode == "bootstrap" {
actionTaken, err = bootstrapper.Bootstrap()
} else if rootConfig.RepairMode == "rejoin-unsafe" {
actionTaken, err = bootstrapper.RejoinUnsafe()
} else {
logger.Error("Invalid repair mode:", errors.New(fmt.Sprintf("%s", rootConfig.RepairMode)))
fmt.Printf("Invalid repair mode: %s", rootConfig.RepairMode)
os.Exit(1)
}
if err != nil {
logger.Error("Failed to repair cluster", err, lager.Data{
"config": rootConfig,
})
printHumanReadableErr(err, rootConfig.RepairMode)
os.Exit(1)
}
if !actionTaken {
fmt.Println("No action taken - cluster already healthy")
os.Exit(0)
}
logger.Info("Successfully repaired cluster")
fmt.Println("Successfully repaired cluster")
}
func printHumanReadableErr(err error, mode string) {
var docsLink string
if mode == "bootstrap" {
docsLink = "https://github.com/cloudfoundry/cf-mysql-release/blob/master/docs/bootstrapping.md"
} else {
docsLink = "https://github.com/cloudfoundry/cf-mysql-release/blob/master/docs/cluster-behavior.md#forcing-a-node-to-rejoin-the-cluster-unsafe-procedure"
}
fmt.Printf(`
##################################################################################
Error: %s
Reference the docs for more information:
%s
##################################################################################
`, err, docsLink)
}