From 201464c9a16d36ccad7584d1255ad495c7b2b603 Mon Sep 17 00:00:00 2001 From: CWen Date: Wed, 28 Aug 2019 13:16:37 +0800 Subject: [PATCH] add config-check flag for pd-server (#1695) (#1711) 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 f7ccb0fa681..8799d4fe6fc 100644 --- a/server/config.go +++ b/server/config.go @@ -44,6 +44,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"` @@ -145,6 +147,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", "", "human-readable name for this pd member") diff --git a/server/util.go b/server/util.go index f2a5c6b9703..f3119a4a1cd 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)