]> source.dussan.org Git - gitea.git/commitdiff
detect kill signal
authorUnknwon <u@gogs.io>
Tue, 18 Aug 2015 15:36:08 +0000 (23:36 +0800)
committerUnknwon <u@gogs.io>
Tue, 18 Aug 2015 15:36:08 +0000 (23:36 +0800)
cmd/web.go

index c441e91966847cf53f10caaf72a9884b33182b05..84def2a4812ad56a5306e0dc07da9fe99daafbe1 100644 (file)
@@ -12,6 +12,7 @@ import (
        "net/http"
        "net/http/fcgi"
        "os"
+       "os/signal"
        "path"
        "strings"
 
@@ -530,6 +531,16 @@ func runWeb(ctx *cli.Context) {
        // Not found handler.
        m.NotFound(routers.NotFound)
 
+       // Detect kill signal.
+       c := make(chan os.Signal, 1)
+       signal.Notify(c, os.Interrupt)
+       go func() {
+               for _ = range c {
+                       fmt.Println("Kill signal detected, exiting now...")
+                       os.Exit(0)
+               }
+       }()
+
        // Flag for port number in case first time run conflict.
        if ctx.IsSet("port") {
                setting.AppUrl = strings.Replace(setting.AppUrl, setting.HttpPort, ctx.String("port"), 1)