summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile16
-rw-r--r--cmd/dcat/main.go19
-rw-r--r--cmd/dgrep/main.go18
-rw-r--r--cmd/dmap/main.go19
-rw-r--r--cmd/drun/main.go (renamed from cmd/dexec/main.go)24
-rw-r--r--cmd/dserver/main.go22
-rw-r--r--cmd/dtail/main.go19
-rw-r--r--doc/examples.md4
-rw-r--r--doc/installation.md5
-rw-r--r--doc/quickstart.md23
-rw-r--r--go.mod1
-rw-r--r--go.sum9
-rw-r--r--internal/clients/args.go3
-rw-r--r--internal/clients/baseclient.go130
-rw-r--r--internal/clients/catclient.go20
-rw-r--r--internal/clients/client.go5
-rw-r--r--internal/clients/connectionmaker.go12
-rw-r--r--internal/clients/execclient.go48
-rw-r--r--internal/clients/grepclient.go20
-rw-r--r--internal/clients/handlers/basehandler.go84
-rw-r--r--internal/clients/handlers/clienthandler.go11
-rw-r--r--internal/clients/handlers/handler.go12
-rw-r--r--internal/clients/handlers/healthhandler.go21
-rw-r--r--internal/clients/handlers/maprhandler.go21
-rw-r--r--internal/clients/handlers/withcancel.go24
-rw-r--r--internal/clients/healthclient.go7
-rw-r--r--internal/clients/maker.go8
-rw-r--r--internal/clients/maprclient.go52
-rw-r--r--internal/clients/remote/connection.go116
-rw-r--r--internal/clients/runclient.go40
-rw-r--r--internal/clients/stats.go8
-rw-r--r--internal/clients/tailclient.go21
-rw-r--r--internal/discovery/comma.go2
-rw-r--r--internal/discovery/discovery.go21
-rw-r--r--internal/discovery/file.go2
-rw-r--r--internal/io/fs/catfile.go (renamed from internal/fs/catfile.go)6
-rw-r--r--internal/io/fs/filereader.go (renamed from internal/fs/filereader.go)9
-rw-r--r--internal/io/fs/permissions/permission.go (renamed from internal/fs/permissions/permission.go)2
-rw-r--r--internal/io/fs/permissions/permission_linux.c (renamed from internal/fs/permissions/permission_linux.c)0
-rw-r--r--internal/io/fs/permissions/permission_linux.go (renamed from internal/fs/permissions/permission_linux.go)0
-rw-r--r--internal/io/fs/permissions/permission_linux.h (renamed from internal/fs/permissions/permission_linux.h)0
-rw-r--r--internal/io/fs/permissions/permission_test.go (renamed from internal/fs/permissions/permission_test.go)0
-rw-r--r--internal/io/fs/readfile.go (renamed from internal/fs/readfile.go)73
-rw-r--r--internal/io/fs/stats.go (renamed from internal/fs/stats.go)0
-rw-r--r--internal/io/fs/tailfile.go (renamed from internal/fs/tailfile.go)6
-rw-r--r--internal/io/line/line.go (renamed from internal/fs/lineread.go)14
-rw-r--r--internal/io/logger/logger.go (renamed from internal/logger/logger.go)56
-rw-r--r--internal/io/run/run.go104
-rw-r--r--internal/mapr/aggregateset.go5
-rw-r--r--internal/mapr/client/aggregate.go25
-rw-r--r--internal/mapr/groupset.go5
-rw-r--r--internal/mapr/logformat/parser.go2
-rw-r--r--internal/mapr/query.go2
-rw-r--r--internal/mapr/server/aggregate.go141
-rw-r--r--internal/mapr/wherecondition.go2
-rw-r--r--internal/omode/mode.go6
-rw-r--r--internal/pprof/pprof.go3
-rw-r--r--internal/prompt/prompt.go2
-rw-r--r--internal/server/handlers/controlhandler.go42
-rw-r--r--internal/server/handlers/handler.go2
-rw-r--r--internal/server/handlers/mapcommand.go35
-rw-r--r--internal/server/handlers/readcommand.go158
-rw-r--r--internal/server/handlers/runcommand.go73
-rw-r--r--internal/server/handlers/serverhandler.go521
-rw-r--r--internal/server/server.go70
-rw-r--r--internal/server/stats.go10
-rw-r--r--internal/ssh/client/authmethods.go2
-rw-r--r--internal/ssh/client/hostkeycallback.go10
-rw-r--r--internal/ssh/server/hostkey.go2
-rw-r--r--internal/ssh/server/publickeycallback.go2
-rw-r--r--internal/ssh/ssh.go2
-rw-r--r--internal/user/name.go15
-rw-r--r--internal/user/server/user.go44
-rw-r--r--internal/version/version.go22
-rw-r--r--samples/dtail.json.sample12
75 files changed, 1271 insertions, 1081 deletions
diff --git a/Makefile b/Makefile
index 3480637..c358d8e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,29 +1,31 @@
GO ?= go
all: build
build:
+ ${GO} build -o dserver ./cmd/dserver/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 drun ./cmd/drun/main.go
${GO} build -o dtail ./cmd/dtail/main.go
clean:
- rm -v dtail dgrep dcat dmap dserver dexec 2>/dev/null
+ ls ./cmd/ | while read cmd; do \
+ test -f $$cmd && rm $$cmd; \
+ done
install: build
+ cp -pv dserver ${GOPATH}/bin/dserver
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 drun ${GOPATH}/bin/drun
cp -pv dtail ${GOPATH}/bin/dtail
vet:
find . -type d | while read dir; do \
echo ${GO} vet $$dir; \
${GO} vet $$dir; \
- done
+ done
lint:
${GO} get golang.org/x/lint/golint
find . -type d | while read dir; do \
echo ${GOPATH}/bin/golint $$dir; \
${GOPATH}/bin/golint $$dir; \
- done
+ done
diff --git a/cmd/dcat/main.go b/cmd/dcat/main.go
index b02d369..1ec945d 100644
--- a/cmd/dcat/main.go
+++ b/cmd/dcat/main.go
@@ -1,12 +1,14 @@
package main
import (
+ "context"
"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/io/logger"
"github.com/mimecast/dtail/internal/pprof"
"github.com/mimecast/dtail/internal/user"
"github.com/mimecast/dtail/internal/version"
@@ -27,7 +29,6 @@ func main() {
var sshPort int
var trustAllHosts bool
- pingTimeoutS := 60
userName := user.Name()
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
@@ -37,7 +38,6 @@ func main() {
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")
@@ -54,9 +54,10 @@ func main() {
version.PrintAndExit()
}
+ ctx := context.Background()
serverEnable := false
- logger.Start(serverEnable, debugEnable, silentEnable, silentEnable)
- defer logger.Stop()
+
+ logger.Start(ctx, serverEnable, debugEnable, silentEnable, silentEnable)
if pprofEnable || config.Common.PProfEnable {
pprof.Start()
@@ -67,14 +68,16 @@ func main() {
ServersStr: serversStr,
Discovery: discovery,
UserName: userName,
- Files: files,
+ What: files,
TrustAllHosts: trustAllHosts,
- PingTimeout: pingTimeoutS,
}
client, err := clients.NewCatClient(args)
if err != nil {
panic(err)
}
- client.Start()
+
+ status := client.Start(ctx)
+ logger.Flush()
+ os.Exit(status)
}
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go
index d1a7d52..74a501f 100644
--- a/cmd/dgrep/main.go
+++ b/cmd/dgrep/main.go
@@ -1,12 +1,14 @@
package main
import (
+ "context"
"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/io/logger"
"github.com/mimecast/dtail/internal/pprof"
"github.com/mimecast/dtail/internal/user"
"github.com/mimecast/dtail/internal/version"
@@ -28,7 +30,6 @@ func main() {
var sshPort int
var trustAllHosts bool
- pingTimeoutS := 60
userName := user.Name()
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
@@ -38,7 +39,6 @@ func main() {
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")
@@ -56,9 +56,9 @@ func main() {
version.PrintAndExit()
}
+ ctx := context.Background()
serverEnable := false
- logger.Start(serverEnable, debugEnable, silentEnable, silentEnable)
- defer logger.Stop()
+ logger.Start(ctx, serverEnable, debugEnable, silentEnable, silentEnable)
if pprofEnable || config.Common.PProfEnable {
pprof.Start()
@@ -69,9 +69,8 @@ func main() {
ServersStr: serversStr,
Discovery: discovery,
UserName: userName,
- Files: files,
+ What: files,
TrustAllHosts: trustAllHosts,
- PingTimeout: pingTimeoutS,
Regex: regex,
}
@@ -79,5 +78,8 @@ func main() {
if err != nil {
panic(err)
}
- client.Start()
+
+ status := client.Start(ctx)
+ logger.Flush()
+ os.Exit(status)
}
diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go
index 83dad50..f3f706a 100644
--- a/cmd/dmap/main.go
+++ b/cmd/dmap/main.go
@@ -1,13 +1,15 @@
package main
import (
+ "context"
"flag"
+ "os"
- "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/io/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"
@@ -29,7 +31,6 @@ func main() {
var sshPort int
var trustAllHosts bool
- pingTimeoutS := 900
userName := user.Name()
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
@@ -39,7 +40,6 @@ func main() {
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")
@@ -57,10 +57,10 @@ func main() {
version.PrintAndExit()
}
+ ctx := context.Background()
serverEnable := false
- logger.Start(serverEnable, debugEnable, silentEnable, silentEnable)
- defer logger.Stop()
+ logger.Start(ctx, serverEnable, debugEnable, silentEnable, silentEnable)
if pprofEnable || config.Common.PProfEnable {
pprof.Start()
}
@@ -70,9 +70,8 @@ func main() {
ServersStr: serversStr,
Discovery: discovery,
UserName: userName,
- Files: files,
+ What: files,
TrustAllHosts: trustAllHosts,
- PingTimeout: pingTimeoutS,
Mode: omode.MapClient,
}
@@ -81,5 +80,7 @@ func main() {
panic(err)
}
- client.Start()
+ status := client.Start(ctx)
+ logger.Flush()
+ os.Exit(status)
}
diff --git a/cmd/dexec/main.go b/cmd/drun/main.go
index 7a7ab1f..b1936d4 100644
--- a/cmd/dexec/main.go
+++ b/cmd/drun/main.go
@@ -1,12 +1,14 @@
package main
import (
+ "context"
"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/io/logger"
"github.com/mimecast/dtail/internal/pprof"
"github.com/mimecast/dtail/internal/user"
"github.com/mimecast/dtail/internal/version"
@@ -15,11 +17,11 @@ import (
// The evil begins here.
func main() {
var cfgFile string
+ var command 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
@@ -27,7 +29,6 @@ func main() {
var sshPort int
var trustAllHosts bool
- pingTimeoutS := 60
userName := user.Name()
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
@@ -37,11 +38,10 @@ func main() {
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(&discovery, "discovery", "", "Server discovery method")
flag.StringVar(&serversStr, "servers", "", "Remote servers to connect")
flag.StringVar(&userName, "user", userName, "Your system user name")
@@ -54,10 +54,10 @@ func main() {
version.PrintAndExit()
}
+ ctx := context.Background()
serverEnable := false
- logger.Start(serverEnable, debugEnable, silentEnable, silentEnable)
- defer logger.Stop()
+ logger.Start(ctx, serverEnable, debugEnable, silentEnable, silentEnable)
if pprofEnable || config.Common.PProfEnable {
pprof.Start()
}
@@ -67,14 +67,16 @@ func main() {
ServersStr: serversStr,
Discovery: discovery,
UserName: userName,
- Files: files,
+ What: command,
TrustAllHosts: trustAllHosts,
- PingTimeout: pingTimeoutS,
}
- client, err := clients.NewExecClient(args)
+ client, err := clients.NewRunClient(args)
if err != nil {
panic(err)
}
- client.Start()
+
+ status := client.Start(ctx)
+ logger.Flush()
+ os.Exit(status)
}
diff --git a/cmd/dserver/main.go b/cmd/dserver/main.go
index 489910b..aa209a8 100644
--- a/cmd/dserver/main.go
+++ b/cmd/dserver/main.go
@@ -1,13 +1,14 @@
package main
import (
+ "context"
"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/io/logger"
"github.com/mimecast/dtail/internal/pprof"
"github.com/mimecast/dtail/internal/server"
"github.com/mimecast/dtail/internal/user"
@@ -24,7 +25,7 @@ func main() {
var shutdownAfter int
var sshPort int
- userName := user.Name()
+ user.NoRootCheck()
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
@@ -43,19 +44,23 @@ func main() {
version.PrintAndExit()
}
+ ctx := context.Background()
+
serverEnable := true
silentEnable := false
nothingEnable := false
- logger.Start(serverEnable, debugEnable, silentEnable, nothingEnable)
- defer logger.Stop()
+ logger.Start(ctx, serverEnable, debugEnable, silentEnable, nothingEnable)
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")
+ select {
+ case <-time.After(time.Duration(shutdownAfter) * time.Second):
+ logger.Info("Auto shutdown timer reached, shutting down now")
+ case <-ctx.Done():
+ }
}()
}
@@ -63,7 +68,8 @@ func main() {
pprof.Start()
}
- logger.Info("Launching server", version.String(), userName)
sshServer := server.New()
- sshServer.Start()
+ status := sshServer.Start(ctx)
+ logger.Flush()
+ os.Exit(status)
}
diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go
index 1bf77c7..76070ff 100644
--- a/cmd/dtail/main.go
+++ b/cmd/dtail/main.go
@@ -1,13 +1,14 @@
package main
import (
+ "context"
"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/io/logger"
"github.com/mimecast/dtail/internal/omode"
"github.com/mimecast/dtail/internal/pprof"
"github.com/mimecast/dtail/internal/user"
@@ -32,7 +33,6 @@ func main() {
var sshPort int
var trustAllHosts bool
- pingTimeoutS := 5
userName := user.Name()
flag.BoolVar(&checkHealth, "checkHealth", false, "Only check for server health")
@@ -43,7 +43,6 @@ func main() {
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")
@@ -62,17 +61,18 @@ func main() {
version.PrintAndExit()
}
+ ctx := context.Background()
+
if checkHealth {
healthClient, _ := clients.NewHealthClient(omode.HealthClient)
- os.Exit(healthClient.Start())
+ os.Exit(healthClient.Start(ctx))
}
serverEnable := false
if checkHealth {
silentEnable = true
}
- logger.Start(serverEnable, debugEnable, silentEnable, silentEnable)
- defer logger.Stop()
+ logger.Start(ctx, serverEnable, debugEnable, silentEnable, silentEnable)
if pprofEnable || config.Common.PProfEnable {
pprof.Start()
@@ -83,9 +83,8 @@ func main() {
ServersStr: serversStr,
Discovery: discovery,
UserName: userName,
- Files: files,
+ What: files,
TrustAllHosts: trustAllHosts,
- PingTimeout: pingTimeoutS,
Regex: regex,
Mode: omode.TailClient,
}
@@ -104,5 +103,7 @@ func main() {
}
}
- client.Start()
+ status := client.Start(ctx)
+ logger.Flush()
+ os.Exit(status)
}
diff --git a/doc/examples.md b/doc/examples.md
index 959105c..964660a 100644
--- a/doc/examples.md
+++ b/doc/examples.md
@@ -25,7 +25,7 @@ To run ad-hoc mapreduce aggregations on newly written log lines you also must ad
--files '/var/log/service/*.log'
```
-In order for mapreduce queries to work you have to make sure that your log format is supported by DTail. You can either use the ones which are already defined in ``mapr/logformat`` or add an extension to support a custom log format.
+In order for mapreduce queries to work you have to make sure that your log format is supported by DTail. You can either use the ones which are already defined in ``internal/mapr/logformat`` or add an extension to support a custom log format.
![dtail-map](dtail-map.gif "Tail mapreduce example")
@@ -62,6 +62,6 @@ To run a mapreduce aggregation over logs written in the past the ``dmap`` comman
--files "/var/log/service/*.log"
```
-Remember: In order for that to work you have to make sure that your log format is supported by DTail. You can either use the ones which are already defined in ``mapr/logformat`` or add an extension to support a custom log format.
+Remember: In order for that to work you have to make sure that your log format is supported by DTail. You can either use the ones which are already defined in ``internal/mapr/logf