Add control+c or INT handling

This commit is contained in:
Chris Lu 2014-05-13 00:04:28 -07:00
parent 982aaa41b9
commit 7e0ae72b07

View file

@ -78,7 +78,7 @@ func runVolume(cmd *Command, args []string) bool {
r := http.NewServeMux()
weed_server.NewVolumeServer(r, *ip, *vport, *publicIp, folders, maxCounts,
volumeServer := weed_server.NewVolumeServer(r, *ip, *vport, *publicIp, folders, maxCounts,
*masterNode, *vpulse, *dataCenter, *rack, volumeWhiteList,
)
@ -91,6 +91,16 @@ func runVolume(cmd *Command, args []string) bool {
glog.Fatalf(e.Error())
}
// deal with control+c
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt)
go func() {
for _ = range signalChan {
volumeServer.Shutdown()
os.Exit(0)
}
}()
if e := http.Serve(listener, r); e != nil {
glog.Fatalf("Fail to serve:%s", e.Error())
}