pihole-exporter/main.go

39 lines
662 B
Go
Raw Normal View History

2019-05-08 23:45:04 +02:00
package main
import (
"fmt"
"github.com/eko/pihole-exporter/config"
"github.com/eko/pihole-exporter/internal/metrics"
"github.com/eko/pihole-exporter/internal/pihole"
"github.com/eko/pihole-exporter/internal/server"
"github.com/xonvanetta/shutdown/pkg/shutdown"
2019-05-08 23:45:04 +02:00
)
func main() {
conf := config.Load()
metrics.Init()
serverDead := make(chan struct{})
s := server.NewServer(conf.Port, pihole.NewClient(conf))
go func() {
s.ListenAndServe()
close(serverDead)
}()
2019-05-08 23:45:04 +02:00
ctx := shutdown.Context()
2019-05-08 23:45:04 +02:00
go func() {
<-ctx.Done()
s.Stop()
}()
2019-05-08 23:45:04 +02:00
select {
case <-ctx.Done():
case <-serverDead:
}
2019-05-08 23:45:04 +02:00
fmt.Println("pihole-exporter HTTP server stopped")
2019-05-08 23:45:04 +02:00
}