seaweedfs/weed/command/shell.go

69 lines
1.9 KiB
Go
Raw Normal View History

package command
2012-08-24 11:56:09 +08:00
import (
2019-10-25 22:44:37 +08:00
"fmt"
"github.com/seaweedfs/seaweedfs/weed/pb"
2019-10-25 22:44:37 +08:00
"github.com/seaweedfs/seaweedfs/weed/security"
"github.com/seaweedfs/seaweedfs/weed/shell"
"github.com/seaweedfs/seaweedfs/weed/util"
)
var (
shellOptions shell.ShellOptions
shellInitialFiler *string
shellCluster *string
2012-08-24 11:56:09 +08:00
)
func init() {
2013-01-17 16:56:56 +08:00
cmdShell.Run = runShell // break init cycle
shellOptions.Masters = cmdShell.Flag.String("master", "", "comma-separated master servers, e.g. localhost:9333")
2022-05-02 12:59:16 +08:00
shellOptions.FilerGroup = cmdShell.Flag.String("filerGroup", "", "filerGroup for the filers")
2024-03-25 02:20:33 +08:00
shellInitialFiler = cmdShell.Flag.String("filer", "", "filer host and port for initial connection, e.g. localhost:8888")
shellCluster = cmdShell.Flag.String("cluster", "", "cluster defined in shell.toml")
2012-08-24 11:56:09 +08:00
}
var cmdShell = &Command{
2013-01-17 16:56:56 +08:00
UsageLine: "shell",
Short: "run interactive administrative commands",
Long: `run interactive administrative commands.
2012-08-24 11:56:09 +08:00
Generate shell.toml via "weed scaffold -config=shell"
2024-03-25 02:20:33 +08:00
`,
2012-08-24 11:56:09 +08:00
}
func runShell(command *Command, args []string) bool {
util.LoadConfiguration("security", false)
shellOptions.GrpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
2024-03-25 02:20:33 +08:00
shellOptions.Directory = "/"
util.LoadConfiguration("shell", false)
viper := util.GetViper()
cluster := viper.GetString("cluster.default")
if *shellCluster != "" {
cluster = *shellCluster
}
if *shellOptions.Masters == "" {
if cluster == "" {
*shellOptions.Masters = "localhost:9333"
} else {
2024-03-25 02:20:33 +08:00
*shellOptions.Masters = viper.GetString("cluster." + cluster + ".master")
}
}
2024-03-25 02:20:33 +08:00
filerAddress := *shellInitialFiler
if filerAddress == "" && cluster != "" {
filerAddress = viper.GetString("cluster." + cluster + ".filer")
}
shellOptions.FilerAddress = pb.ServerAddress(filerAddress)
fmt.Printf("master: %s filer: %s\n", *shellOptions.Masters, shellOptions.FilerAddress)
2019-10-25 22:44:37 +08:00
shell.RunShell(shellOptions)
return true
2019-10-25 22:44:37 +08:00
}