Skip to content

Commit

Permalink
Merge pull request #140 from markmandel/feature/sidecar-stop-signal
Browse files Browse the repository at this point in the history
Handle stop signal in the SDK Server
  • Loading branch information
markmandel authored Mar 14, 2018
2 parents bc575f8 + 8345e05 commit 97b3025
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmd/sdk-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"agones.dev/agones/pkg/gameservers"
"agones.dev/agones/pkg/sdk"
"agones.dev/agones/pkg/util/runtime"
"agones.dev/agones/pkg/util/signals"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"golang.org/x/net/context"
Expand Down Expand Up @@ -101,6 +102,7 @@ func main() {
if err != nil {
logger.WithField("port", port).WithField("address", address).Fatalf("Could not listen on port")
}
stop := signals.NewStopChannel()
grpcServer := grpc.NewServer()

if isLocal {
Expand Down Expand Up @@ -134,8 +136,17 @@ func main() {
sdk.RegisterSDKServer(grpcServer, s)
}

err = grpcServer.Serve(lis)
if err != nil {
logger.WithError(err).Error("Could not serve grpc server")
}
go func() {
err = grpcServer.Serve(lis)
if err != nil {
logger.WithError(err).Fatal("Could not serve grpc server")
}
}()

<-stop
logger.Info("shutting down grpc server")
// don't graceful stop, because if we get a kill signal
// then the gameserver is being shut down, and we no longer
// care about running RPC calls.
grpcServer.Stop()
}

0 comments on commit 97b3025

Please sign in to comment.