2016-06-03 01:09:14 +00:00
|
|
|
package command
|
2012-08-24 03:56:09 +00:00
|
|
|
|
|
|
|
import (
|
2019-10-25 14:44:37 +00:00
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2019-03-16 20:43:16 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/security"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/shell"
|
2019-06-05 08:30:24 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2019-03-16 20:43:16 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
2014-10-26 18:34:55 +00:00
|
|
|
|
2019-03-16 20:43:16 +00:00
|
|
|
var (
|
2019-10-25 14:45:12 +00:00
|
|
|
shellOptions shell.ShellOptions
|
2019-10-25 14:44:37 +00:00
|
|
|
shellInitialFilerUrl *string
|
2012-08-24 03:56:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2013-01-17 08:56:56 +00:00
|
|
|
cmdShell.Run = runShell // break init cycle
|
2019-03-16 20:43:16 +00:00
|
|
|
shellOptions.Masters = cmdShell.Flag.String("master", "localhost:9333", "comma-separated master servers")
|
2019-10-25 14:44:37 +00:00
|
|
|
shellInitialFilerUrl = cmdShell.Flag.String("filer.url", "http://localhost:8888/", "initial filer url")
|
2012-08-24 03:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var cmdShell = &Command{
|
2013-01-17 08:56:56 +00:00
|
|
|
UsageLine: "shell",
|
2019-03-16 20:43:16 +00:00
|
|
|
Short: "run interactive administrative commands",
|
|
|
|
Long: `run interactive administrative commands.
|
2012-08-24 03:56:09 +00:00
|
|
|
|
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
|
|
|
func runShell(command *Command, args []string) bool {
|
2019-03-16 20:43:16 +00:00
|
|
|
|
2019-06-05 08:30:24 +00:00
|
|
|
util.LoadConfiguration("security", false)
|
2019-03-16 20:43:16 +00:00
|
|
|
shellOptions.GrpcDialOption = security.LoadClientTLS(viper.Sub("grpc"), "client")
|
|
|
|
|
2019-10-25 14:44:37 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-03-16 20:43:16 +00:00
|
|
|
shell.RunShell(shellOptions)
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
2019-10-25 14:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|