diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 9a09726a735..f86833027e9 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -55,6 +55,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/config.go b/server/config/config.go index 68c11351644..bfed4731482 100644 --- a/server/config/config.go +++ b/server/config/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 67fb6fcbc4a..af2e4f54755 100644 --- a/server/util.go +++ b/server/util.go @@ -68,6 +68,18 @@ func PrintPDInfo() { fmt.Println("UTC Build Time: ", PDBuildTS) } +// PrintConfigCheckMsg prints the message about configuration checks. +func PrintConfigCheckMsg(cfg *config.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 *config.ScheduleOption) { pdVersion := *MinSupportedVersion(Base)