2019-05-22 23:16:55 +02:00
|
|
|
package procutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2019-06-03 15:52:08 +02:00
|
|
|
// WaitForSigterm waits for either SIGTERM or SIGINT
|
2019-05-22 23:16:55 +02:00
|
|
|
//
|
|
|
|
// Returns the caught signal.
|
2020-04-30 01:09:27 +02:00
|
|
|
//
|
|
|
|
// It also prevent from program termination on SIGHUP signal,
|
|
|
|
// since this signal is frequently used for config reloading.
|
2019-05-22 23:16:55 +02:00
|
|
|
func WaitForSigterm() os.Signal {
|
|
|
|
ch := make(chan os.Signal, 1)
|
2020-04-30 01:09:27 +02:00
|
|
|
for {
|
|
|
|
signal.Notify(ch, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
|
|
|
sig := <-ch
|
|
|
|
if sig == syscall.SIGHUP {
|
|
|
|
// Prevent from the program stop on SIGHUP
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return sig
|
|
|
|
}
|
2019-05-22 23:16:55 +02:00
|
|
|
}
|