2018-10-08 19:20:28 +00:00
|
|
|
package tunnel
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2020-04-29 20:51:32 +00:00
|
|
|
|
2020-11-25 06:55:13 +00:00
|
|
|
"github.com/rs/zerolog"
|
2018-05-01 23:45:06 +00:00
|
|
|
)
|
|
|
|
|
2021-01-25 21:51:58 +00:00
|
|
|
// waitForSignal closes graceShutdownC to indicate that we should start graceful shutdown sequence
|
|
|
|
func waitForSignal(graceShutdownC chan struct{}, logger *zerolog.Logger) {
|
2018-05-01 23:45:06 +00:00
|
|
|
signals := make(chan os.Signal, 10)
|
|
|
|
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT)
|
|
|
|
defer signal.Stop(signals)
|
|
|
|
|
|
|
|
select {
|
2020-04-28 00:55:27 +00:00
|
|
|
case s := <-signals:
|
2020-11-25 06:55:13 +00:00
|
|
|
logger.Info().Msgf("Initiating graceful shutdown due to signal %s ...", s)
|
2018-05-01 23:45:06 +00:00
|
|
|
close(graceShutdownC)
|
|
|
|
case <-graceShutdownC:
|
|
|
|
}
|
2021-03-23 14:30:43 +00:00
|
|
|
}
|