Browse Source

feat(main): terminate the kuiper server gracefully.

RockyJin 4 years atrás
parent
commit
f4986cb99a
1 changed files with 12 additions and 0 deletions
  1. 12 0
      xstream/server/server/server.go

+ 12 - 0
xstream/server/server/server.go

@@ -9,7 +9,10 @@ import (
 	"net"
 	"net/http"
 	"net/rpc"
+	"os"
+	"os/signal"
 	"path"
+	"syscall"
 	"time"
 )
 
@@ -36,6 +39,15 @@ func StartUp(Version, LoadFileType string) {
 		logger.Infof("db location is %s", dr)
 		dataDir = dr
 	}
+
+	c := make(chan os.Signal)
+	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
+	go func() {
+		<-c
+		logger.Printf("Kuiper is terminated.\n")
+		os.Exit(0)
+	}()
+
 	ruleProcessor = processors.NewRuleProcessor(path.Dir(dataDir))
 	streamProcessor = processors.NewStreamProcessor(path.Join(path.Dir(dataDir), "stream"))
 	pluginManager, err = plugins.NewPluginManager()