summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-06 10:55:50 +0300
committerPaul Buetow <paul@buetow.org>2021-10-06 10:55:50 +0300
commit7306afe9ab073c424ddca0ddc57950f237948118 (patch)
tree063c7181425f0657ec97e415c0224d311bafe6c5 /cmd
parentfab5dc3e70434ea0abc7a0976487a1973b662331 (diff)
move health check to separate client binary
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dtail/main.go22
-rw-r--r--cmd/dtailhealthcheck/main.go31
2 files changed, 40 insertions, 13 deletions
diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go
index d333825..301fc08 100644
--- a/cmd/dtail/main.go
+++ b/cmd/dtail/main.go
@@ -41,7 +41,7 @@ func main() {
flag.BoolVar(&args.RegexInvert, "invert", false, "Invert regex")
flag.BoolVar(&args.Spartan, "spartan", false, "Spartan output mode")
flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Trust all unknown host keys")
- flag.BoolVar(&checkHealth, "checkHealth", false, "Only check for server health")
+ flag.BoolVar(&checkHealth, "checkHealth", false, "Deprecated, flag will be removed soon")
flag.BoolVar(&displayColorTable, "colorTable", false, "Show color table")
flag.BoolVar(&displayWideColorTable, "wideColorTable", false, "Show a large color table")
flag.BoolVar(&displayVersion, "version", false, "Display version")
@@ -66,27 +66,23 @@ func main() {
if grep != "" {
args.RegexStr = grep
}
- sourceProcess := source.Client
- if checkHealth {
- sourceProcess = source.HealthCheck
- }
- config.Setup(sourceProcess, &args, flag.Args())
-
+ config.Setup(source.Client, &args, flag.Args())
if displayVersion {
version.PrintAndExit()
}
if !args.Spartan {
+ if !checkHealth {
+ version.Print()
+ }
if displayWideColorTable {
color.TablePrintAndExit(true)
}
if displayColorTable {
color.TablePrintAndExit(false)
}
- version.Print()
}
ctx, cancel := context.WithCancel(context.Background())
-
if shutdownAfter > 0 {
ctx, cancel = context.WithTimeout(ctx, time.Duration(shutdownAfter)*time.Second)
defer cancel()
@@ -94,12 +90,12 @@ func main() {
var wg sync.WaitGroup
wg.Add(1)
- dlog.Start(ctx, &wg, sourceProcess, config.Common.LogLevel)
+ dlog.Start(ctx, &wg, source.Client, config.Common.LogLevel)
if checkHealth {
- defer cancel()
- healthClient, _ := clients.NewHealthClient(args)
- os.Exit(healthClient.Start(ctx, signal.InterruptCh(ctx)))
+ fmt.Println("WARN: DTail health check has moved to separate binary dtailhealtcheck - please adjust the monitoring scripts!")
+ cancel()
+ os.Exit(1)
}
if pprof > -1 {
diff --git a/cmd/dtailhealthcheck/main.go b/cmd/dtailhealthcheck/main.go
new file mode 100644
index 0000000..e0cb795
--- /dev/null
+++ b/cmd/dtailhealthcheck/main.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "context"
+ "flag"
+ "os"
+ "sync"
+
+ "github.com/mimecast/dtail/internal/clients"
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/io/dlog"
+ "github.com/mimecast/dtail/internal/io/signal"
+ "github.com/mimecast/dtail/internal/source"
+)
+
+// The evil begins here.
+func main() {
+ var args config.Args
+ flag.StringVar(&args.ServersStr, "server", "", "Remote server to connect")
+ flag.Parse()
+ config.Setup(source.HealthCheck, &args, flag.Args())
+
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ var wg sync.WaitGroup
+ wg.Add(1)
+
+ dlog.Start(ctx, &wg, source.HealthCheck, config.Common.LogLevel)
+ healthClient, _ := clients.NewHealthClient(args)
+ os.Exit(healthClient.Start(ctx, signal.NoCh(ctx)))
+}