shell.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package command
  2. import (
  3. "fmt"
  4. "github.com/chrislusf/seaweedfs/weed/security"
  5. "github.com/chrislusf/seaweedfs/weed/shell"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. )
  8. var (
  9. shellOptions shell.ShellOptions
  10. shellInitialFiler *string
  11. shellCluster *string
  12. )
  13. func init() {
  14. cmdShell.Run = runShell // break init cycle
  15. shellOptions.Masters = cmdShell.Flag.String("master", "", "comma-separated master servers, e.g. localhost:9333")
  16. shellInitialFiler = cmdShell.Flag.String("filer", "", "filer host and port, e.g. localhost:8888")
  17. shellCluster = cmdShell.Flag.String("cluster", "", "cluster defined in shell.toml")
  18. }
  19. var cmdShell = &Command{
  20. UsageLine: "shell",
  21. Short: "run interactive administrative commands",
  22. Long: `run interactive administrative commands.
  23. Generate shell.toml via "weed scaffold -config=shell"
  24. `,
  25. }
  26. func runShell(command *Command, args []string) bool {
  27. util.LoadConfiguration("security", false)
  28. shellOptions.GrpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
  29. if *shellOptions.Masters == "" && *shellInitialFiler == "" {
  30. util.LoadConfiguration("shell", false)
  31. v := util.GetViper()
  32. cluster := v.GetString("cluster.default")
  33. if *shellCluster != "" {
  34. cluster = *shellCluster
  35. }
  36. if cluster == "" {
  37. *shellOptions.Masters, *shellInitialFiler = "localhost:9333", "localhost:8888"
  38. } else {
  39. *shellOptions.Masters = v.GetString("cluster." + cluster + ".master")
  40. *shellInitialFiler = v.GetString("cluster." + cluster + ".filer")
  41. }
  42. }
  43. fmt.Printf("master: %s filer: %s\n", *shellOptions.Masters, *shellInitialFiler)
  44. var err error
  45. shellOptions.FilerHost, shellOptions.FilerPort, err = util.ParseHostPort(*shellInitialFiler)
  46. if err != nil {
  47. fmt.Printf("failed to parse filer %s: %v\n", *shellInitialFiler, err)
  48. return false
  49. }
  50. shellOptions.Directory = "/"
  51. shell.RunShell(shellOptions)
  52. return true
  53. }