Skip to content

Commit

Permalink
Handle SIGTERM for graceful shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
KoichiWada committed Jan 18, 2021
1 parent ee237a4 commit 9907376
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions server_adapter_go.go
@@ -1,21 +1,23 @@
package revel

import (
"net"
"net/http"
"time"
"context"
"golang.org/x/net/websocket"
"io"
"mime/multipart"
"net"
"net/http"
"net/url"
"os"
"os/signal"
"path"
"sort"
"strconv"
"strings"
"syscall"
"time"

"github.com/revel/revel/utils"
"golang.org/x/net/websocket"
)

// Register the GoHttpServer engine
Expand Down Expand Up @@ -216,7 +218,7 @@ func (g *GoHttpServer) Engine() interface{} {
func (g *GoHttpServer) Event(event Event, args interface{}) (r EventResponse) {
switch event {
case ENGINE_STARTED:
signal.Notify(g.signalChan, os.Interrupt, os.Kill)
signal.Notify(g.signalChan, os.Interrupt, syscall.SIGTERM, os.Kill)
go func() {
_ = <-g.signalChan
serverLogger.Info("Received quit singal Please wait ... ")
Expand Down Expand Up @@ -495,7 +497,7 @@ func (r *GoResponse) WriteStream(name string, contentlen int64, modtime time.Tim
if _, err := io.Copy(r.Writer, reader); err != nil {
r.Original.WriteHeader(http.StatusInternalServerError)
return err
}
}
}
return nil
}
Expand Down

0 comments on commit 9907376

Please sign in to comment.