From 6e44953bec17cb882502007042de77edfb1503e8 Mon Sep 17 00:00:00 2001 From: CWen Date: Tue, 3 Sep 2019 16:13:36 +0800 Subject: [PATCH] add config-check flag for pd-server (#1695) (#1725) Signed-off-by: cwen0 --- cmd/pd-server/main.go | 6 ++++++ server/config.go | 3 +++ server/util.go | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 8cf1306930c..7b290ad7de5 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -53,6 +53,12 @@ func main() { default: log.Fatal("parse cmd flags error", zap.Error(err)) } + + if cfg.ConfigCheck { + server.PrintConfigCheckMsg(cfg) + exit(0) + } + // New zap logger err = cfg.SetupLogger() if err == nil { diff --git a/server/config.go b/server/config.go index 767f0fe33e7..0283c4cc071 100644 --- a/server/config.go +++ b/server/config.go @@ -42,6 +42,8 @@ type Config struct { Version bool `json:"-"` + ConfigCheck bool `json:"-"` + ClientUrls string `toml:"client-urls" json:"client-urls"` PeerUrls string `toml:"peer-urls" json:"peer-urls"` AdvertiseClientUrls string `toml:"advertise-client-urls" json:"advertise-client-urls"` @@ -139,6 +141,7 @@ func NewConfig() *Config { fs.BoolVar(&cfg.Version, "V", false, "print version information and exit") fs.BoolVar(&cfg.Version, "version", false, "print version information and exit") fs.StringVar(&cfg.configFile, "config", "", "Config file") + fs.BoolVar(&cfg.ConfigCheck, "config-check", false, "check config file validity and exit") fs.StringVar(&cfg.Name, "name", defaultName, "human-readable name for this pd member") diff --git a/server/util.go b/server/util.go index 138efd5543b..391e82f8345 100644 --- a/server/util.go +++ b/server/util.go @@ -71,6 +71,18 @@ func PrintPDInfo() { fmt.Println("UTC Build Time: ", PDBuildTS) } +// PrintConfigCheckMsg prints the message about configuration checks. +func PrintConfigCheckMsg(cfg *Config) { + if len(cfg.WarningMsgs) == 0 { + fmt.Println("config check successful") + return + } + + for _, msg := range cfg.WarningMsgs { + fmt.Println(msg) + } +} + // CheckPDVersion checks if PD needs to be upgraded. func CheckPDVersion(opt *scheduleOption) { pdVersion := MinSupportedVersion(Base)