support shutdown command

This commit is contained in:
siddontang 2015-05-03 11:19:31 +08:00
parent a999f2201d
commit 9bfd3b2208
2 changed files with 10 additions and 0 deletions

View File

@ -113,5 +113,7 @@ func main() {
<-sc <-sc
println("ledis-server is closing")
app.Close() app.Close()
println("ledis-server is closed")
} }

View File

@ -13,6 +13,7 @@ import (
"net" "net"
"runtime" "runtime"
"strconv" "strconv"
"syscall"
"time" "time"
) )
@ -165,6 +166,13 @@ func (c *respClient) handleRequest(reqData [][]byte) error {
c.resp.writeStatus(OK) c.resp.writeStatus(OK)
c.resp.flush() c.resp.flush()
c.conn.Close() c.conn.Close()
return errClientQuit
} else if c.cmd == "shutdown" {
c.conn.Close()
// send kill signal
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
return errClientQuit return errClientQuit
} }