Skip to content

Commit

Permalink
reload config on SIGHUP
Browse files Browse the repository at this point in the history
Fixes: #118
Signed-off-by: Carlos Rodriguez-Fernandez <[email protected]>
  • Loading branch information
carlosrodfern committed Oct 31, 2023
1 parent 7db8c6f commit c1cab5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ In each host group the `interval`, `network`, and `protocol` are optional.

The interval Duration is in [Go time.ParseDuration()](https://golang.org/pkg/time/#ParseDuration) syntax.

NOTE: The config is only read on startup, SIGHUP is not supported (yet).
The config is read on startup, and can be reloaded with the SIGHUP signal.

## Building and running

Expand Down
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import (
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"

"github.com/prometheus-community/pro-bing"
probing "github.com/prometheus-community/pro-bing"
"github.com/superq/smokeping_prober/config"

"github.com/alecthomas/kingpin/v2"
Expand Down Expand Up @@ -228,6 +230,18 @@ func main() {
http.Handle("/", landingPage)
}

hup := make(chan os.Signal, 1)
signal.Notify(hup, syscall.SIGHUP)
go func() {
for {
<-hup
level.Info(logger).Log("msg", "Reexecuting and reloading the configuration")
if err := syscall.Exec("/proc/self/exe", os.Args, os.Environ()); err != nil {
level.Error(logger).Log("msg", "Error reloading config", "err", err)
}
}
}()

server := &http.Server{}
if err := web.ListenAndServe(server, webConfig, logger); err != nil {
level.Error(logger).Log("err", err)
Expand Down

0 comments on commit c1cab5b

Please sign in to comment.