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.7 KiB

13 years ago
5 years ago
13 years ago
13 years ago
13 years ago
  1. package command
  2. import (
  3. "fmt"
  4. "net/url"
  5. "strconv"
  6. "strings"
  7. "github.com/chrislusf/seaweedfs/weed/security"
  8. "github.com/chrislusf/seaweedfs/weed/shell"
  9. "github.com/chrislusf/seaweedfs/weed/util"
  10. "github.com/spf13/viper"
  11. )
  12. var (
  13. shellOptions shell.ShellOptions
  14. shellInitialFilerUrl *string
  15. )
  16. func init() {
  17. cmdShell.Run = runShell // break init cycle
  18. shellOptions.Masters = cmdShell.Flag.String("master", "localhost:9333", "comma-separated master servers")
  19. shellInitialFilerUrl = cmdShell.Flag.String("filer.url", "http://localhost:8888/", "initial filer url")
  20. }
  21. var cmdShell = &Command{
  22. UsageLine: "shell",
  23. Short: "run interactive administrative commands",
  24. Long: `run interactive administrative commands.
  25. `,
  26. }
  27. func runShell(command *Command, args []string) bool {
  28. util.LoadConfiguration("security", false)
  29. shellOptions.GrpcDialOption = security.LoadClientTLS(viper.Sub("grpc"), "client")
  30. var filerPwdErr error
  31. shellOptions.FilerHost, shellOptions.FilerPort, shellOptions.Directory, filerPwdErr = parseFilerUrl(*shellInitialFilerUrl)
  32. if filerPwdErr != nil {
  33. fmt.Printf("failed to parse url filer.url=%s : %v\n", *shellInitialFilerUrl, filerPwdErr)
  34. return false
  35. }
  36. shell.RunShell(shellOptions)
  37. return true
  38. }
  39. func parseFilerUrl(entryPath string) (filerServer string, filerPort int64, path string, err error) {
  40. if !strings.HasPrefix(entryPath, "http://") && !strings.HasPrefix(entryPath, "https://") {
  41. entryPath = "http://" + entryPath
  42. }
  43. var u *url.URL
  44. u, err = url.Parse(entryPath)
  45. if err != nil {
  46. return
  47. }
  48. filerServer = u.Hostname()
  49. portString := u.Port()
  50. if portString != "" {
  51. filerPort, err = strconv.ParseInt(portString, 10, 32)
  52. }
  53. path = u.Path
  54. return
  55. }