From b21b73115a24da9d2dd2cd3637c9dc00b1f94dd5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 30 Apr 2020 02:15:39 +0300 Subject: [PATCH] app/vminsert: add `/-/reload` handler in the same way as for `vmagent` --- app/vmagent/main.go | 8 +------- lib/procutil/signal.go | 9 +++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/vmagent/main.go b/app/vmagent/main.go index 7b8501031f..ad0f3d0127 100644 --- a/app/vmagent/main.go +++ b/app/vmagent/main.go @@ -5,7 +5,6 @@ import ( "fmt" "net/http" "strings" - "syscall" "time" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmagent/csvimport" @@ -160,11 +159,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool { return true case "/-/reload": promscrapeConfigReloadRequests.Inc() - if err := syscall.Kill(syscall.Getpid(), syscall.SIGHUP); err != nil { - promscrapeConfigReloadErrors.Inc() - httpserver.Errorf(w, "Fail to reload config file, %s", err) - return true - } + procutil.SelfSIGHUP() w.WriteHeader(http.StatusNoContent) return true } @@ -189,5 +184,4 @@ var ( promscrapeTargetsRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/targets"}`) promscrapeConfigReloadRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/-/reload"}`) - promscrapeConfigReloadErrors = metrics.NewCounter(`vmagent_http_request_errors_total{path="/-/reload"}`) ) diff --git a/lib/procutil/signal.go b/lib/procutil/signal.go index 8221ecb679..c4483ab1f9 100644 --- a/lib/procutil/signal.go +++ b/lib/procutil/signal.go @@ -4,6 +4,8 @@ import ( "os" "os/signal" "syscall" + + "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" ) // WaitForSigterm waits for either SIGTERM or SIGINT @@ -24,3 +26,10 @@ func WaitForSigterm() os.Signal { return sig } } + +// SelfSIGHUP sends SIGHUP signal to the current process. +func SelfSIGHUP() { + if err := syscall.Kill(syscall.Getpid(), syscall.SIGHUP); err != nil { + logger.Panicf("FATAL: cannot send SIGHUP to itself: %s", err) + } +}