summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2020-01-22 13:07:04 +0000
committerPaul Bütow <pbuetow@mimecast.com>2020-01-22 13:07:04 +0000
commitbd683ec4a63b01255274ab6f2463c95a49695e90 (patch)
tree9c397b2edc9e118aac563abdfa78211a9f3d3938
parente56c31af93c5432eab8c129e19d8741db1e19a32 (diff)
more on dexec
-rw-r--r--Makefile9
-rw-r--r--cmd/dexec/main.go80
-rw-r--r--internal/omode/mode.go50
3 files changed, 88 insertions, 51 deletions
diff --git a/Makefile b/Makefile
index 456987d..3480637 100644
--- a/Makefile
+++ b/Makefile
@@ -1,20 +1,21 @@
GO ?= go
all: build
build:
- ${GO} version
- ${GO} build -o dtail ./cmd/dtail/main.go
${GO} build -o dcat ./cmd/dcat/main.go
+ ${GO} build -o dexec ./cmd/dexec/main.go
${GO} build -o dgrep ./cmd/dgrep/main.go
${GO} build -o dmap ./cmd/dmap/main.go
${GO} build -o dserver ./cmd/dserver/main.go
+ ${GO} build -o dtail ./cmd/dtail/main.go
clean:
- rm -v dtail dgrep dcat dmap dserver 2>/dev/null
+ rm -v dtail dgrep dcat dmap dserver dexec 2>/dev/null
install: build
- cp -pv dtail ${GOPATH}/bin/dtail
cp -pv dcat ${GOPATH}/bin/dcat
+ cp -pv dexec ${GOPATH}/bin/dexec
cp -pv dgrep ${GOPATH}/bin/dgrep
cp -pv dmap ${GOPATH}/bin/dmap
cp -pv dserver ${GOPATH}/bin/dserver
+ cp -pv dtail ${GOPATH}/bin/dtail
vet:
find . -type d | while read dir; do \
echo ${GO} vet $$dir; \
diff --git a/cmd/dexec/main.go b/cmd/dexec/main.go
new file mode 100644
index 0000000..7a7ab1f
--- /dev/null
+++ b/cmd/dexec/main.go
@@ -0,0 +1,80 @@
+package main
+
+import (
+ "flag"
+
+ "github.com/mimecast/dtail/internal/clients"
+ "github.com/mimecast/dtail/internal/color"
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/pprof"
+ "github.com/mimecast/dtail/internal/user"
+ "github.com/mimecast/dtail/internal/version"
+)
+
+// The evil begins here.
+func main() {
+ var cfgFile string
+ var connectionsPerCPU int
+ var debugEnable bool
+ var discovery string
+ var displayVersion bool
+ var command string
+ var noColor bool
+ var pprofEnable bool
+ var serversStr string
+ var silentEnable bool
+ var sshPort int
+ var trustAllHosts bool
+
+ pingTimeoutS := 60
+ userName := user.Name()
+
+ flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
+ flag.BoolVar(&displayVersion, "version", false, "Display version")
+ flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
+ flag.BoolVar(&pprofEnable, "pprofEnable", false, "Enable pprof server")
+ flag.BoolVar(&silentEnable, "silent", false, "Reduce output")
+ flag.BoolVar(&trustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
+ flag.IntVar(&connectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
+ flag.IntVar(&pingTimeoutS, "pingTimeout", 10, "The server ping timeout (0 means disable pings)")
+ flag.IntVar(&sshPort, "port", 2222, "SSH server port")
+ flag.StringVar(&cfgFile, "cfg", "", "Config file path")
+ flag.StringVar(&discovery, "discovery", "", "Server discovery method")
+ flag.StringVar(&command, "command", "", "Command to run")
+ flag.StringVar(&serversStr, "servers", "", "Remote servers to connect")
+ flag.StringVar(&userName, "user", userName, "Your system user name")
+
+ flag.Parse()
+
+ config.Read(cfgFile, sshPort)
+ color.Colored = !noColor
+
+ if displayVersion {
+ version.PrintAndExit()
+ }
+
+ serverEnable := false
+ logger.Start(serverEnable, debugEnable, silentEnable, silentEnable)
+ defer logger.Stop()
+
+ if pprofEnable || config.Common.PProfEnable {
+ pprof.Start()
+ }
+
+ args := clients.Args{
+ ConnectionsPerCPU: connectionsPerCPU,
+ ServersStr: serversStr,
+ Discovery: discovery,
+ UserName: userName,
+ Files: files,
+ TrustAllHosts: trustAllHosts,
+ PingTimeout: pingTimeoutS,
+ }
+
+ client, err := clients.NewExecClient(args)
+ if err != nil {
+ panic(err)
+ }
+ client.Start()
+}
diff --git a/internal/omode/mode.go b/internal/omode/mode.go
index 4bdfc45..57366d2 100644
--- a/internal/omode/mode.go
+++ b/internal/omode/mode.go
@@ -1,11 +1,5 @@
package omode
-import (
- "fmt"
- "os"
- "path"
-)
-
// Mode used.
type Mode int
@@ -18,49 +12,9 @@ const (
GrepClient Mode = iota
MapClient Mode = iota
HealthClient Mode = iota
+ ExecClient Mode = iota
)
-// New returns the mode based on the mode string.
-func New(modeStr string) Mode {
- switch modeStr {
- case "dserver":
- return Server
- case "server":
- return Server
-
- case "dtail":
- fallthrough
- case "tail":
- return TailClient
-
- case "grep":
- fallthrough
- case "dgrep":
- return GrepClient
-
- case "cat":
- fallthrough
- case "dcat":
- return CatClient
-
- case "map":
- fallthrough
- case "dmap":
- return MapClient
-
- case "health":
- return HealthClient
-
- default:
- panic(fmt.Sprintf("Unknown mode: '%s'", modeStr))
- }
-}
-
-// Default mode.
-func Default() Mode {
- return New(path.Base(os.Args[0]))
-}
-
func (m Mode) String() string {
switch m {
case Server:
@@ -75,6 +29,8 @@ func (m Mode) String() string {
return "map"
case HealthClient:
return "health"
+ case ExecClient:
+ return "exec"
default:
return "unknown"
}