Skip to content

Commit

Permalink
Allow stopping junos_exporter with sigint/ctrl+c (#270)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Geiselhardt-Herms <[email protected]>
  • Loading branch information
taktv6 and Oliver Geiselhardt-Herms authored Dec 17, 2024
1 parent eb6dac4 commit 409238d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ import (
"syscall"
"time"

"go.opentelemetry.io/otel/codes"

"github.com/czerwonk/junos_exporter/internal/config"
"github.com/czerwonk/junos_exporter/pkg/connector"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/codes"

"github.com/czerwonk/junos_exporter/internal/config"
log "github.com/sirupsen/logrus"
)

const version string = "0.12.7"
Expand Down Expand Up @@ -126,12 +125,12 @@ func main() {
}
defer shutdownTracing()

initChannels()
initChannels(ctx)

startServer()
}

func initChannels() {
func initChannels(ctx context.Context) {
hup := make(chan os.Signal, 1)
signal.Notify(hup, syscall.SIGHUP)

Expand All @@ -155,15 +154,21 @@ func initChannels() {
} else {
rc <- nil
}
case <-ctx.Done():
shutdown()
case <-term:
log.Infoln("Closing connections to devices")
connManager.Close()
os.Exit(0)
shutdown()
}
}
}()
}

func shutdown() {
log.Infoln("Closing connections to devices")
connManager.Close()
os.Exit(0)
}

func printVersion() {
fmt.Println("junos_exporter")
fmt.Printf("Version: %s\n", version)
Expand Down

0 comments on commit 409238d

Please sign in to comment.