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"
|
2021-09-13 05:47:52 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
2019-10-25 14:44:37 +00:00
|
|
|
|
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
|
|
|
)
|
2014-10-26 18:34:55 +00:00
|
|
|
|
2019-03-16 20:43:16 +00:00
|
|
|
var (
|
2020-04-09 06:57:15 +00:00
|
|
|
shellOptions shell.ShellOptions
|
|
|
|
shellInitialFiler *string
|
2020-12-28 23:07:16 +00:00
|
|
|
shellCluster *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
|
2020-12-28 23:07:16 +00:00
|
|
|
shellOptions.Masters = cmdShell.Flag.String("master", "", "comma-separated master servers, e.g. localhost:9333")
|
2022-05-02 04:59:16 +00:00
|
|
|
shellOptions.FilerGroup = cmdShell.Flag.String("filerGroup", "", "filerGroup for the filers")
|
2020-12-28 23:07:16 +00:00
|
|
|
shellInitialFiler = cmdShell.Flag.String("filer", "", "filer host and port, e.g. localhost:8888")
|
|
|
|
shellCluster = cmdShell.Flag.String("cluster", "", "cluster defined in shell.toml")
|
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
|
|
|
|
2020-12-28 23:07:16 +00:00
|
|
|
Generate shell.toml via "weed scaffold -config=shell"
|
|
|
|
|
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)
|
2020-01-29 17:09:55 +00:00
|
|
|
shellOptions.GrpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
|
2019-03-16 20:43:16 +00:00
|
|
|
|
2021-11-03 06:38:45 +00:00
|
|
|
if *shellOptions.Masters == "" {
|
2020-12-28 23:07:16 +00:00
|
|
|
util.LoadConfiguration("shell", false)
|
|
|
|
v := util.GetViper()
|
|
|
|
cluster := v.GetString("cluster.default")
|
|
|
|
if *shellCluster != "" {
|
|
|
|
cluster = *shellCluster
|
|
|
|
}
|
|
|
|
if cluster == "" {
|
2021-11-03 06:38:45 +00:00
|
|
|
*shellOptions.Masters = "localhost:9333"
|
2020-12-28 23:07:16 +00:00
|
|
|
} else {
|
|
|
|
*shellOptions.Masters = v.GetString("cluster." + cluster + ".master")
|
|
|
|
*shellInitialFiler = v.GetString("cluster." + cluster + ".filer")
|
2021-11-03 06:38:45 +00:00
|
|
|
fmt.Printf("master: %s filer: %s\n", *shellOptions.Masters, *shellInitialFiler)
|
2020-12-28 23:07:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
shellOptions.FilerAddress = pb.ServerAddress(*shellInitialFiler)
|
2020-04-09 06:57:15 +00:00
|
|
|
shellOptions.Directory = "/"
|
2019-10-25 14:44:37 +00:00
|
|
|
|
2019-03-16 20:43:16 +00:00
|
|
|
shell.RunShell(shellOptions)
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
2019-10-25 14:44:37 +00:00
|
|
|
}
|