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.

69 lines
1.9 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
3 years ago
  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. shellOptions.FilerAddress = *shellInitialFiler
  47. if err != nil {
  48. fmt.Printf("failed to parse filer %s: %v\n", *shellInitialFiler, err)
  49. return false
  50. }
  51. shellOptions.Directory = "/"
  52. shell.RunShell(shellOptions)
  53. return true
  54. }