You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.8 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  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. shellOptions.FilerGroup = cmdShell.Flag.String("filerGroup", "", "filerGroup for the filers")
  18. shellInitialFiler = cmdShell.Flag.String("filer", "", "filer host and port, 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. if *shellOptions.Masters == "" {
  32. util.LoadConfiguration("shell", false)
  33. v := util.GetViper()
  34. cluster := v.GetString("cluster.default")
  35. if *shellCluster != "" {
  36. cluster = *shellCluster
  37. }
  38. if cluster == "" {
  39. *shellOptions.Masters = "localhost:9333"
  40. } else {
  41. *shellOptions.Masters = v.GetString("cluster." + cluster + ".master")
  42. *shellInitialFiler = v.GetString("cluster." + cluster + ".filer")
  43. fmt.Printf("master: %s filer: %s\n", *shellOptions.Masters, *shellInitialFiler)
  44. }
  45. }
  46. shellOptions.FilerAddress = pb.ServerAddress(*shellInitialFiler)
  47. shellOptions.Directory = "/"
  48. shell.RunShell(shellOptions)
  49. return true
  50. }