diff options
| author | Paul Bütow <pbuetow@mimecast.com> | 2020-01-20 18:41:05 +0000 |
|---|---|---|
| committer | Paul Bütow <pbuetow@mimecast.com> | 2020-01-21 14:35:23 +0000 |
| commit | c128865c4c7411c29a59fca9a3a2f95537686d7b (patch) | |
| tree | 193bccc70d942c8b70cc93fae2670263701e43aa /cmd | |
| parent | 3755a9911ecb05886577095f2b8cc8b9e4066a3a (diff) | |
Move commands to cmd/ and move internal dependencies to internal/
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/dcat/main.go | 80 | ||||
| -rw-r--r-- | cmd/dgrep/main.go | 83 | ||||
| -rw-r--r-- | cmd/dmap/main.go | 85 | ||||
| -rw-r--r-- | cmd/dserver/main.go | 69 | ||||
| -rw-r--r-- | cmd/dtail/main.go | 108 |
5 files changed, 425 insertions, 0 deletions
diff --git a/cmd/dcat/main.go b/cmd/dcat/main.go new file mode 100644 index 0000000..b02d369 --- /dev/null +++ b/cmd/dcat/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 files 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(&files, "files", "", "File(s) to read") + 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.NewCatClient(args) + if err != nil { + panic(err) + } + client.Start() +} diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go new file mode 100644 index 0000000..d1a7d52 --- /dev/null +++ b/cmd/dgrep/main.go @@ -0,0 +1,83 @@ +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 files string + var noColor bool + var pprofEnable bool + var regex string + 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(&files, "files", "", "File(s) to read") + flag.StringVar(®ex, "regex", ".", "Regular expression") + 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, + Regex: regex, + } + + client, err := clients.NewGrepClient(args) + if err != nil { + panic(err) + } + client.Start() +} diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go new file mode 100644 index 0000000..83dad50 --- /dev/null +++ b/cmd/dmap/main.go @@ -0,0 +1,85 @@ +package main + +import ( + "flag" + + "github.com/mimecast/dtail/internal/omode" + "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 files string + var noColor bool + var pprofEnable bool + var queryStr string + var serversStr string + var silentEnable bool + var sshPort int + var trustAllHosts bool + + pingTimeoutS := 900 + 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(&files, "files", "", "File(s) to read") + flag.StringVar(&queryStr, "query", "", "Map reduce query") + 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, + Mode: omode.MapClient, + } + + client, err := clients.NewMaprClient(args, queryStr) + if err != nil { + panic(err) + } + + client.Start() +} diff --git a/cmd/dserver/main.go b/cmd/dserver/main.go new file mode 100644 index 0000000..489910b --- /dev/null +++ b/cmd/dserver/main.go @@ -0,0 +1,69 @@ +package main + +import ( + "flag" + "os" + "time" + + "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/server" + "github.com/mimecast/dtail/internal/user" + "github.com/mimecast/dtail/internal/version" +) + +// The evil begins here. +func main() { + var cfgFile string + var debugEnable bool + var displayVersion bool + var noColor bool + var pprofEnable bool + var shutdownAfter int + var sshPort int + + 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.IntVar(&shutdownAfter, "shutdownAfter", 0, "Automatically shutdown after so many seconds") + flag.IntVar(&sshPort, "port", 2222, "SSH server port") + flag.StringVar(&cfgFile, "cfg", "", "Config file path") + + flag.Parse() + + config.Read(cfgFile, sshPort) + color.Colored = !noColor + + if displayVersion { + version.PrintAndExit() + } + + serverEnable := true + silentEnable := false + nothingEnable := false + logger.Start(serverEnable, debugEnable, silentEnable, nothingEnable) + defer logger.Stop() + + if shutdownAfter > 0 { + go func() { + defer os.Exit(1) + + logger.Info("Enabling auto shutdown timer", shutdownAfter) + time.Sleep(time.Duration(shutdownAfter) * time.Second) + logger.Info("Auto shutdown timer reached, shutting down now") + }() + } + + if pprofEnable || config.Common.PProfEnable { + pprof.Start() + } + + logger.Info("Launching server", version.String(), userName) + sshServer := server.New() + sshServer.Start() +} diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go new file mode 100644 index 0000000..1bf77c7 --- /dev/null +++ b/cmd/dtail/main.go @@ -0,0 +1,108 @@ +package main + +import ( + "flag" + "os" + + "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/omode" + "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 checkHealth bool + var connectionsPerCPU int + var debugEnable bool + var discovery string + var displayVersion bool + var files string + var noColor bool + var pprofEnable bool + var queryStr string + var regex string + var serversStr string + var silentEnable bool + var sshPort int + var trustAllHosts bool + + pingTimeoutS := 5 + userName := user.Name() + + flag.BoolVar(&checkHealth, "checkHealth", false, "Only check for server health") + 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(&files, "files", "", "File(s) to read") + flag.StringVar(&queryStr, "query", "", "Map reduce query") + flag.StringVar(®ex, "regex", ".", "Regular expression") + 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() + } + + if checkHealth { + healthClient, _ := clients.NewHealthClient(omode.HealthClient) + os.Exit(healthClient.Start()) + } + + serverEnable := false + if checkHealth { + silentEnable = true + } + 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, + Regex: regex, + Mode: omode.TailClient, + } + + var client clients.Client + var err error + + switch queryStr { + case "": + if client, err = clients.NewTailClient(args); err != nil { + panic(err) + } + default: + if client, err = clients.NewMaprClient(args, queryStr); err != nil { + panic(err) + } + } + + client.Start() +} |
