command

package
v0.0.0-...-7757931 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigCmd = &cobra.Command{
	Use:   "config",
	Short: "scs server config",
	Args:  cobra.MinimumNArgs(1),
	Long:  `All software has versions. This is Hugo's`,

	Run: func(cmd *cobra.Command, args []string) {

	},
}
View Source
var DisableCmd = &cobra.Command{
	Use:   "disable",
	Short: "disable script",
	Long:  `command: scsctl disable <pname>`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range getNodes() {
			wg.Add(1)
			go func(node *client.Node) {
				node.Disable(args[0])
				wg.Done()
			}(node)

		}
		wg.Wait()

	},
}
View Source
var EnableCmd = &cobra.Command{
	Use:   "enable",
	Short: "enable script",
	Long:  `command: scsctl enable <pname>`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Enable(args[0])
				wg.Done()
			}(node)

		}
		wg.Wait()
	},
}
View Source
var EnvCmd = &cobra.Command{
	Use:   "env",
	Short: "show env",
	Long:  `command: scsctl env [flags] <name>`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Env(args[0])
				wg.Done()
			}(node)

		}
		wg.Wait()

	},
}
View Source
var FmtCmd = &cobra.Command{
	Use:   "fmt",
	Short: "Print all script status",
	Long:  `All software has versions. This is Hugo's`,

	Run: func(cmd *cobra.Command, args []string) {
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Fmt()
				wg.Done()
			}(node)

		}
		wg.Wait()

	},
}
View Source
var GetCmd = &cobra.Command{
	Use:   "get",
	Short: "get info",
	Long:  `command: scsctl get servers | scripts | alarms`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}

		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node, flag string) {
				switch flag {
				case "scripts":
					node.GetScripts()
					wg.Done()
				case "servers":
					node.GetServers()
					wg.Done()
				case "indexs":
					node.GetIndexs()
					wg.Done()
				default:
					node.GetAlerts()
					wg.Done()
				}

			}(node, args[0])

		}
		wg.Wait()
	},
}
View Source
var GroupName string
View Source
var InfoCmd = &cobra.Command{
	Use:   "info",
	Short: "show service",
	Long:  `command: scsctl env [flags] <name>`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Info(args[0])
				wg.Done()
			}(node)

		}
		wg.Wait()

	},
}
View Source
var InstallCmd = &cobra.Command{
	Use:   "install",
	Short: "install package",
	Long:  `install package`,
	Run: func(cmd *cobra.Command, args []string) {
		condition := 0
		sc := make([]*scripts.Script, 0)
		if len(args) > 1 {
			condition++
		}
		if url != "" {
			condition++
			resp, err := http.Get(url)
			if err != nil {
				fmt.Println(err)
				return
			}
			err = json.NewDecoder(resp.Body).Decode(&sc)
			if err != nil {
				fmt.Println(err)
				return
			}
		}
		if file != "" {
			condition++
			path, err := filepath.Abs(file)
			if err != nil {
				log.Fatal(err)
			}
			f, err := ioutil.ReadFile(path)
			if err != nil {
				fmt.Println(err)
				return
			}
			err = yaml.Unmarshal(f, &sc)
			if err != nil {
				fmt.Println(err)
				return
			}

			for i := range sc {
				if sc[i].Dir == "" {
					if sc[i].Env == nil {
						sc[i].Env = make(map[string]string)
					}
					sc[i].Dir = filepath.Dir(path)
					sc[i].Env["PROJECT_HOME"] = sc[i].Dir
				}
			}

		}
		if condition != 1 {
			fmt.Println("at lease one params : scsctl install <-f yaml> || <-u url> || <name>")
			return
		}

		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Install(sc, nil)
				wg.Done()
			}(node)

		}
		wg.Wait()

	},
}

install <-f yaml> || <-u url> || <name>

View Source
var KillCmd = &cobra.Command{
	Use:   "kill",
	Short: "kill script",
	Long:  `command: scsctl kill (<pname> [name])`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Kill(args...)
				wg.Done()
			}(node)

		}
		wg.Wait()

	},
}
View Source
var LogCmd = &cobra.Command{
	Use:   "log",
	Short: "script log",
	Long:  `command: scsctl log [flags] <name>`,
	Args:  cobra.MinimumNArgs(1),
	Run:   logConfig,
}
View Source
var ReadTimeout time.Duration
View Source
var ReloadCmd = &cobra.Command{
	Use:   "reload",
	Short: "reload scs server config",
	Long:  `reload scs server config`,
	Args:  cobra.MaximumNArgs(0),
	Run: func(cmd *cobra.Command, args []string) {
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Reload()
				wg.Done()
			}(node)

		}
		wg.Wait()
	},
}
View Source
var RemoveCmd = &cobra.Command{
	Use:   "remove",
	Short: "remove script",
	Long:  `command: scsctl remove ([flags]) || ([pname] [name])`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 && !removeAll {
			fmt.Println("Specify at least one parameter, or --all")
			return
		}
		if removeAll {
			args = nil
		}
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Remove(args...)
				wg.Done()
			}(node)

		}
		wg.Wait()

	},
}
View Source
var RestartCmd = &cobra.Command{
	Use:   "restart",
	Short: "restart assign script",
	Long:  `command: scsctl restart ([flags]) || ([pname] [name])`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 && !restartAll {
			fmt.Println("Specify at least one parameter, or --all")
			return
		}
		if restartAll {
			args = nil
		}
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}

		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Restart(args...)
				wg.Done()
			}(node)

		}
		wg.Wait()

	},
}
View Source
var SearchCmd = &cobra.Command{
	Use:   "search",
	Short: "search package(future)",
	Long:  `search package(future)`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Search(args[0])
				wg.Done()
			}(node)

		}
		wg.Wait()
	},
}
View Source
var ShowCmd = &cobra.Command{
	Use:   "show",
	Short: "Print all script status",
	Long:  `All software has versions. This is Hugo's`,

	Run: func(cmd *cobra.Command, args []string) {
		client.CCfg.PrintNodes()

	},
}
View Source
var StartCmd = &cobra.Command{
	Use:   "start",
	Short: "start assign script",
	Long:  `command: scsctl start [flags] [pname] [name]`,
	Args:  cobra.MaximumNArgs(2),
	Run: func(cmd *cobra.Command, args []string) {
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Start(args...)
				wg.Done()
			}(node)

		}
		wg.Wait()
	},
}
View Source
var StatusCmd = &cobra.Command{
	Use:   "status",
	Short: "Print assign script status",
	Long:  `command: scsctl status [flags] [pname] [name]`,
	Args:  cobra.MaximumNArgs(2),
	Run: func(cmd *cobra.Command, args []string) {
		ss := make([]*client.ScriptStatusNode, 0)
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range getNodes() {
			wg.Add(1)
			go func(node *client.Node) {
				serverStatus, err := node.Status(args...)
				if err == nil {
					ss = append(ss, serverStatus)
				} else {
					fmt.Println(err)
				}
				wg.Done()
			}(node)

		}
		wg.Wait()
		for _, s := range ss {
			s.SortAndPrint(verbose)
		}
	},
}
View Source
var StopCmd = &cobra.Command{
	Use:   "stop",
	Short: "stop script",
	Long:  `command: scsctl stop ([flags]) || ([pname] [name])`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 && !stopAll {
			fmt.Println("Specify at least one parameter, or --all")
			return
		}
		if stopAll {
			args = nil
		}
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Stop(args...)
				wg.Done()
			}(node)

		}
		wg.Wait()

	},
}
View Source
var TarCmd = &cobra.Command{
	Use:   "tar",
	Short: "archive tar package(future)",
	Long:  `archive tar  package(future)`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		if repoUrl == "" {
			repoUrl = "http://localhost:8080/upload"
		}
		if err := compress(filepath.Clean(args[0])); err != nil {
			fmt.Println(err)
			return
		}

	},
}
View Source
var UpdateCmd = &cobra.Command{
	Use:   "update",
	Short: "update server",
	Long:  `command: scsctl update ([flags]) || ([pname] [name])`,
	Args:  cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		if updateAll {
			fmt.Println("waiting update")
			return
		}
		if updateAll {
			args = nil
		}
		wg := &sync.WaitGroup{}
		nodes := getNodes()
		if len(nodes) == 0 {
			fmt.Println("not found any nodes")
			return
		}
		for _, node := range nodes {
			wg.Add(1)
			go func(node *client.Node) {
				node.Update(args...)
				wg.Done()
			}(node)

		}
		wg.Wait()
	},
}
View Source
var UploadCmd = &cobra.Command{
	Use:   "upload",
	Short: "upload package(future)",
	Long:  `upload package(future)`,
	Args:  cobra.MinimumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		if len(osDir) == 0 {
			fmt.Println("must be set os,eg: -o centos")
		}

		if repoUrl == "" {
			repoUrl = "http://localhost:8080/upload"
		}

		upload(args[0])

	},
}
View Source
var UseNodes string

Functions

func Execute

func Execute()

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL