Skip to content

Commit

Permalink
Merge pull request alibaba#134 from jzwlqx/feature/signal
Browse files Browse the repository at this point in the history
stop probes on signal
  • Loading branch information
BSWANG committed Nov 15, 2023
2 parents e62a876 + ab7bd6b commit 4fb9948
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/exporter/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (i *inspServer) start() error {
}
}()

WaitSignals(i.ctx, syscall.SIGHUP, syscall.SIGINT)
WaitSignals(i, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
return nil
}

Expand All @@ -375,10 +375,17 @@ func createSink(sinkConfigs []EventSinkConfig) ([]sink.Sink, error) {
return ret, nil
}

func WaitSignals(_ context.Context, sgs ...os.Signal) {
func WaitSignals(i *inspServer, sgs ...os.Signal) {
s := make(chan os.Signal, 1)
signal.Notify(s, sgs...)
<-s
sig := <-s
log.Warnf("recive signal %s, stopping", sig.String())
if err := i.metricsServer.Stop(i.ctx); err != nil {
log.Errorf("failed stop metrics server, err: %v", err)
}
if err := i.eventServer.Stop(i.ctx); err != nil {
log.Errorf("failed stop event server, err: %v", err)
}
}

func defaultPage(w http.ResponseWriter, _ *http.Request) {
Expand Down

0 comments on commit 4fb9948

Please sign in to comment.