[ARVADOS] created: 4e9567a57ed7af343e24eeb4dc403a1eb73b1f81

git at public.curoverse.com git at public.curoverse.com
Fri May 16 15:30:46 EDT 2014


        at  4e9567a57ed7af343e24eeb4dc403a1eb73b1f81 (commit)


commit 4e9567a57ed7af343e24eeb4dc403a1eb73b1f81
Author: Tim Pierce <twp at curoverse.com>
Date:   Fri May 16 15:29:31 2014 -0400

    2770: terminate on SIGTERM.
    
    When SIGTERM is received, the Keep server shuts down gracefully. (refs #2770)

diff --git a/services/keep/src/keep/keep.go b/services/keep/src/keep/keep.go
index 7c41737..59396ad 100644
--- a/services/keep/src/keep/keep.go
+++ b/services/keep/src/keep/keep.go
@@ -12,8 +12,10 @@ import (
 	"io"
 	"io/ioutil"
 	"log"
+	"net"
 	"net/http"
 	"os"
+	"os/signal"
 	"regexp"
 	"strconv"
 	"strings"
@@ -93,6 +95,8 @@ var ReadErrorTooLong = errors.New("Too long")
 // permission arguments).
 
 func main() {
+	log.Println("Keep started: pid", os.Getpid())
+
 	// Parse command-line flags:
 	//
 	// -listen=ipaddr:port
@@ -235,8 +239,27 @@ func main() {
 	// router.
 	http.Handle("/", MakeRESTRouter())
 
+	// Set up a TCP listener.
+	listener, err := net.Listen("tcp", listen)
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	// Shut down the server gracefully (by closing the listener)
+	// if SIGTERM is received.
+	term := make(chan os.Signal, 1)
+	go func(sig <-chan os.Signal) {
+		s := <-sig
+		log.Println("caught signal:", s)
+		listener.Close()
+	}(term)
+	signal.Notify(term, syscall.SIGTERM)
+
 	// Start listening for requests.
-	http.ListenAndServe(listen, nil)
+	srv := &http.Server{Addr: listen}
+	srv.Serve(listener)
+
+	log.Println("shutting down")
 }
 
 // MakeRESTRouter

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list