From 9bfd3b2208e48b6c6f1cf8e76b7a5cbba33d517f Mon Sep 17 00:00:00 2001 From: siddontang Date: Sun, 3 May 2015 11:19:31 +0800 Subject: [PATCH] support shutdown command --- cmd/ledis-server/main.go | 2 ++ server/client_resp.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/cmd/ledis-server/main.go b/cmd/ledis-server/main.go index 7987733..d8d3d9c 100644 --- a/cmd/ledis-server/main.go +++ b/cmd/ledis-server/main.go @@ -113,5 +113,7 @@ func main() { <-sc + println("ledis-server is closing") app.Close() + println("ledis-server is closed") } diff --git a/server/client_resp.go b/server/client_resp.go index 47d7d58..65b8b97 100644 --- a/server/client_resp.go +++ b/server/client_resp.go @@ -13,6 +13,7 @@ import ( "net" "runtime" "strconv" + "syscall" "time" ) @@ -165,6 +166,13 @@ func (c *respClient) handleRequest(reqData [][]byte) error { c.resp.writeStatus(OK) c.resp.flush() c.conn.Close() + return errClientQuit + } else if c.cmd == "shutdown" { + c.conn.Close() + + // send kill signal + syscall.Kill(syscall.Getpid(), syscall.SIGTERM) + return errClientQuit }