shell.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package command
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/pb"
  5. "github.com/seaweedfs/seaweedfs/weed/security"
  6. "github.com/seaweedfs/seaweedfs/weed/shell"
  7. "github.com/seaweedfs/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. shellOptions.FilerGroup = cmdShell.Flag.String("filerGroup", "", "filerGroup for the filers")
  18. shellInitialFiler = cmdShell.Flag.String("filer", "", "filer host and port for initial connection, e.g. localhost:8888")
  19. shellCluster = cmdShell.Flag.String("cluster", "", "cluster defined in shell.toml")
  20. }
  21. var cmdShell = &Command{
  22. UsageLine: "shell",
  23. Short: "run interactive administrative commands",
  24. Long: `run interactive administrative commands.
  25. Generate shell.toml via "weed scaffold -config=shell"
  26. `,
  27. }
  28. func runShell(command *Command, args []string) bool {
  29. util.LoadConfiguration("security", false)
  30. shellOptions.GrpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
  31. shellOptions.Directory = "/"
  32. util.LoadConfiguration("shell", false)
  33. viper := util.GetViper()
  34. cluster := viper.GetString("cluster.default")
  35. if *shellCluster != "" {
  36. cluster = *shellCluster
  37. }
  38. if *shellOptions.Masters == "" {
  39. if cluster == "" {
  40. *shellOptions.Masters = "localhost:9333"
  41. } else {
  42. *shellOptions.Masters = viper.GetString("cluster." + cluster + ".master")
  43. }
  44. }
  45. filerAddress := *shellInitialFiler
  46. if filerAddress == "" && cluster != "" {
  47. filerAddress = viper.GetString("cluster." + cluster + ".filer")
  48. }
  49. shellOptions.FilerAddress = pb.ServerAddress(filerAddress)
  50. fmt.Printf("master: %s filer: %s\n", *shellOptions.Masters, shellOptions.FilerAddress)
  51. shell.RunShell(shellOptions)
  52. return true
  53. }