2020-10-02 04:43:14 +00:00
|
|
|
package cmdutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2020-11-23 08:36:03 +00:00
|
|
|
func WaitForSignal(ctx context.Context, signals ...os.Signal) os.Signal {
|
2020-10-02 04:43:14 +00:00
|
|
|
var sigC = make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigC, signals...)
|
|
|
|
defer signal.Stop(sigC)
|
|
|
|
|
|
|
|
select {
|
|
|
|
case sig := <-sigC:
|
|
|
|
logrus.Warnf("%v", sig)
|
2020-11-23 08:36:03 +00:00
|
|
|
return sig
|
2020-10-02 04:43:14 +00:00
|
|
|
|
|
|
|
case <-ctx.Done():
|
2020-11-23 08:36:03 +00:00
|
|
|
return nil
|
2020-10-02 04:43:14 +00:00
|
|
|
|
|
|
|
}
|
2020-11-23 08:36:03 +00:00
|
|
|
|
|
|
|
return nil
|
2020-10-02 04:43:14 +00:00
|
|
|
}
|