Add SIGHUP support to reload telegraf config

closes #539
This commit is contained in:
Thibault Cohen 2016-01-17 03:08:02 -05:00 committed by Cameron Sparr
parent bc71e956a5
commit 551db20657
2 changed files with 127 additions and 112 deletions

View File

@ -9,6 +9,7 @@
- [#534](https://github.com/influxdata/telegraf/pull/534): NSQ input plugin. Thanks @allingeek!
- [#494](https://github.com/influxdata/telegraf/pull/494): Graphite output plugin. Thanks @titilambert!
- AMQP SSL support. Thanks @ekini!
- [#539](https://github.com/influxdata/telegraf/pull/539): Reload config on SIGHUP. Thanks @titilambert!
### Bugfixes
- [#506](https://github.com/influxdb/telegraf/pull/506): Ping input doesn't return response time metric when timeout. Thanks @titilambert!

View File

@ -7,6 +7,7 @@ import (
"os"
"os/signal"
"strings"
"syscall"
"github.com/influxdb/telegraf"
"github.com/influxdb/telegraf/internal/config"
@ -82,6 +83,10 @@ Examples:
`
func main() {
reload := make(chan bool, 1)
reload <- true
for <-reload {
reload <- false
flag.Usage = usageExit
flag.Parse()
@ -196,10 +201,18 @@ func main() {
shutdown := make(chan struct{})
signals := make(chan os.Signal)
signal.Notify(signals, os.Interrupt)
signal.Notify(signals, os.Interrupt, syscall.SIGHUP)
go func() {
<-signals
sig := <-signals
if sig == os.Interrupt {
close(shutdown)
}
if sig == syscall.SIGHUP {
log.Printf("Reloading Telegraf config\n")
<-reload
reload <- true
close(shutdown)
}
}()
log.Printf("Starting Telegraf (version %s)\n", Version)
@ -219,6 +232,7 @@ func main() {
}
ag.Run(shutdown)
}
}
func usageExit() {