shell.go 1.7 KB

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