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. 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 == "" && *shellInitialFiler == "" {
  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, *shellInitialFiler = "localhost:9333", "localhost:8888"
  39. } else {
  40. *shellOptions.Masters = v.GetString("cluster." + cluster + ".master")
  41. *shellInitialFiler = v.GetString("cluster." + cluster + ".filer")
  42. }
  43. }
  44. fmt.Printf("master: %s filer: %s\n", *shellOptions.Masters, *shellInitialFiler)
  45. shellOptions.FilerAddress = pb.ServerAddress(*shellInitialFiler)
  46. shellOptions.Directory = "/"
  47. shell.RunShell(shellOptions)
  48. return true
  49. }