Add SIGKILL to shutdown signals (#1552)

* Add SIGKILL to shutdown signals

* go mod tidy

* Add missing file
This commit is contained in:
Janos Dobronszki 2020-04-21 14:00:12 +02:00 committed by GitHub
parent 7c31edd5f8
commit e5c215556e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 6 deletions

View File

@ -5,13 +5,13 @@ import (
"context" "context"
"os" "os"
"os/signal" "os/signal"
"syscall"
"time" "time"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/codec"
"github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/logger"
"github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/registry"
signalutil "github.com/micro/go-micro/v2/util/signal"
) )
// Server is a simple micro server abstraction // Server is a simple micro server abstraction
@ -200,7 +200,7 @@ func Run() error {
} }
ch := make(chan os.Signal, 1) ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) signal.Notify(ch, signalutil.ShutdownSignals()...)
if logger.V(logger.InfoLevel, log) { if logger.V(logger.InfoLevel, log) {
log.Infof("Received signal %s", <-ch) log.Infof("Received signal %s", <-ch)
} }

View File

@ -6,7 +6,6 @@ import (
"runtime" "runtime"
"strings" "strings"
"sync" "sync"
"syscall"
"github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client"
@ -18,6 +17,7 @@ import (
"github.com/micro/go-micro/v2/plugin" "github.com/micro/go-micro/v2/plugin"
"github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/server"
"github.com/micro/go-micro/v2/store" "github.com/micro/go-micro/v2/store"
signalutil "github.com/micro/go-micro/v2/util/signal"
"github.com/micro/go-micro/v2/util/wrapper" "github.com/micro/go-micro/v2/util/wrapper"
) )
@ -210,7 +210,7 @@ func (s *service) Run() error {
ch := make(chan os.Signal, 1) ch := make(chan os.Signal, 1)
if s.opts.Signal { if s.opts.Signal {
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT) signal.Notify(ch, signalutil.ShutdownSignals()...)
} }
select { select {

13
util/signal/signal.go Normal file
View File

@ -0,0 +1,13 @@
package signal
import (
"os"
"syscall"
)
// ShutDownSingals returns all the singals that are being watched for to shut down services.
func ShutdownSignals() []os.Signal {
return []os.Signal{
syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL,
}
}

View File

@ -10,7 +10,6 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
"syscall"
"time" "time"
"github.com/micro/cli/v2" "github.com/micro/cli/v2"
@ -20,6 +19,7 @@ import (
maddr "github.com/micro/go-micro/v2/util/addr" maddr "github.com/micro/go-micro/v2/util/addr"
mhttp "github.com/micro/go-micro/v2/util/http" mhttp "github.com/micro/go-micro/v2/util/http"
mnet "github.com/micro/go-micro/v2/util/net" mnet "github.com/micro/go-micro/v2/util/net"
signalutil "github.com/micro/go-micro/v2/util/signal"
mls "github.com/micro/go-micro/v2/util/tls" mls "github.com/micro/go-micro/v2/util/tls"
) )
@ -404,7 +404,7 @@ func (s *service) Run() error {
ch := make(chan os.Signal, 1) ch := make(chan os.Signal, 1)
if s.opts.Signal { if s.opts.Signal {
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) signal.Notify(ch, signalutil.ShutdownSignals()...)
} }
select { select {