mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-04-05 20:52:50 +08:00
fix iitial filer url
This commit is contained in:
parent
05fe7a2366
commit
288c45a690
@ -1,6 +1,11 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/security"
|
"github.com/chrislusf/seaweedfs/weed/security"
|
||||||
"github.com/chrislusf/seaweedfs/weed/shell"
|
"github.com/chrislusf/seaweedfs/weed/shell"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
@ -8,18 +13,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
shellOptions shell.ShellOptions
|
shellOptions shell.ShellOptions
|
||||||
|
shellInitialFilerUrl *string
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmdShell.Run = runShell // break init cycle
|
cmdShell.Run = runShell // break init cycle
|
||||||
shellOptions.Masters = cmdShell.Flag.String("master", "localhost:9333", "comma-separated master servers")
|
shellOptions.Masters = cmdShell.Flag.String("master", "localhost:9333", "comma-separated master servers")
|
||||||
filerHost := cmdShell.Flag.String("filer.host", "localhost", "comma-separated filer server host")
|
shellInitialFilerUrl = cmdShell.Flag.String("filer.url", "http://localhost:8888/", "initial filer url")
|
||||||
flierPort := cmdShell.Flag.Int64("filer.port", 8888, "comma-separated filer server port")
|
|
||||||
directory := cmdShell.Flag.String("filer.dir", "/", "comma-separated filer server directory")
|
|
||||||
shellOptions.FilerHost = *filerHost
|
|
||||||
shellOptions.FilerPort = *flierPort
|
|
||||||
shellOptions.Directory = *directory
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdShell = &Command{
|
var cmdShell = &Command{
|
||||||
@ -36,8 +38,35 @@ func runShell(command *Command, args []string) bool {
|
|||||||
util.LoadConfiguration("security", false)
|
util.LoadConfiguration("security", false)
|
||||||
shellOptions.GrpcDialOption = security.LoadClientTLS(viper.Sub("grpc"), "client")
|
shellOptions.GrpcDialOption = security.LoadClientTLS(viper.Sub("grpc"), "client")
|
||||||
|
|
||||||
|
|
||||||
|
var filerPwdErr error
|
||||||
|
shellOptions.FilerHost, shellOptions.FilerPort, shellOptions.Directory, filerPwdErr = parseFilerUrl(*shellInitialFilerUrl)
|
||||||
|
if filerPwdErr != nil {
|
||||||
|
fmt.Printf("failed to parse url filer.url=%s : %v\n", *shellInitialFilerUrl, filerPwdErr)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
shell.RunShell(shellOptions)
|
shell.RunShell(shellOptions)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseFilerUrl(entryPath string) (filerServer string, filerPort int64, path string, err error) {
|
||||||
|
if !strings.HasPrefix(entryPath, "http://") && !strings.HasPrefix(entryPath, "https://") {
|
||||||
|
entryPath = "http://" + entryPath
|
||||||
|
}
|
||||||
|
|
||||||
|
var u *url.URL
|
||||||
|
u, err = url.Parse(entryPath)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
filerServer = u.Hostname()
|
||||||
|
portString := u.Port()
|
||||||
|
if portString != "" {
|
||||||
|
filerPort, err = strconv.ParseInt(portString, 10, 32)
|
||||||
|
}
|
||||||
|
path = u.Path
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -16,8 +16,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ShellOptions struct {
|
type ShellOptions struct {
|
||||||
Masters *string
|
Masters *string
|
||||||
GrpcDialOption grpc.DialOption
|
GrpcDialOption grpc.DialOption
|
||||||
// shell transient context
|
// shell transient context
|
||||||
FilerHost string
|
FilerHost string
|
||||||
FilerPort int64
|
FilerPort int64
|
||||||
|
Loading…
Reference in New Issue
Block a user