github.com/pingcap/tiup@v1.15.1/components/cluster/command/check.go (about) 1 // Copyright 2020 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package command 15 16 import ( 17 "path" 18 19 "github.com/pingcap/tiup/pkg/cluster/manager" 20 operator "github.com/pingcap/tiup/pkg/cluster/operation" 21 "github.com/pingcap/tiup/pkg/utils" 22 "github.com/spf13/cobra" 23 ) 24 25 func newCheckCmd() *cobra.Command { 26 opt := manager.CheckOptions{ 27 Opr: &operator.CheckOptions{}, 28 IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"), 29 } 30 cmd := &cobra.Command{ 31 Use: "check <topology.yml | cluster-name> [scale-out.yml]", 32 Short: "Perform preflight checks for the cluster.", 33 Long: `Perform preflight checks for the cluster. By default, it checks deploy servers 34 before a cluster is deployed, the input is the topology.yaml for the cluster. 35 If '--cluster' is set, it will perform checks for an existing cluster, the input 36 is the cluster name. Some checks are ignore in this mode, such as port and dir 37 conflict checks with other clusters 38 If you want to check the scale-out topology, please use execute the following command 39 ' check <cluster-name> <scale-out.yml> --cluster ' 40 it will check the new instances `, 41 RunE: func(cmd *cobra.Command, args []string) error { 42 if len(args) != 1 && len(args) != 2 { 43 return cmd.Help() 44 } 45 scaleOutTopo := "" 46 47 if opt.ExistCluster { 48 clusterReport.ID = scrubClusterName(args[0]) 49 } 50 51 if len(args) == 2 { 52 if !opt.ExistCluster { 53 return cmd.Help() 54 } 55 scaleOutTopo = args[1] 56 } 57 58 return cm.CheckCluster(args[0], scaleOutTopo, opt, gOpt) 59 }, 60 } 61 62 cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.") 63 cmd.Flags().StringVarP(&opt.IdentityFile, "identity_file", "i", opt.IdentityFile, "The path of the SSH identity file. If specified, public key authentication will be used.") 64 cmd.Flags().BoolVarP(&opt.UsePassword, "password", "p", false, "Use password of target hosts. If specified, password authentication will be used.") 65 cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only check specified roles") 66 cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Only check specified nodes") 67 68 cmd.Flags().BoolVar(&opt.Opr.EnableCPU, "enable-cpu", false, "Enable CPU thread count check") 69 cmd.Flags().BoolVar(&opt.Opr.EnableMem, "enable-mem", false, "Enable memory size check") 70 cmd.Flags().BoolVar(&opt.Opr.EnableDisk, "enable-disk", false, "Enable disk IO (fio) check") 71 cmd.Flags().BoolVar(&opt.ApplyFix, "apply", false, "Try to fix failed checks") 72 cmd.Flags().BoolVar(&opt.ExistCluster, "cluster", false, "Check existing cluster, the input is a cluster name.") 73 cmd.Flags().Uint64Var(&gOpt.APITimeout, "api-timeout", 10, "Timeout in seconds when querying PD APIs.") 74 75 return cmd 76 }