程序意外退出时关闭sqlite指针

This commit is contained in:
GoEdgeLab
2022-03-14 11:47:34 +08:00
parent 9a6a491817
commit 6436ba503b
7 changed files with 72 additions and 13 deletions

View File

@@ -33,10 +33,12 @@ import (
"log"
"os"
"os/exec"
"os/signal"
"runtime"
"runtime/debug"
"sort"
"sync"
"syscall"
"time"
)
@@ -96,6 +98,9 @@ func (this *Node) Start() {
// 处理异常
this.handlePanic()
// 监听signal
this.listenSignals()
// 启动事件
events.Notify(events.EventStart)
@@ -593,6 +598,20 @@ func (this *Node) checkClusterConfig() error {
return nil
}
// 监听一些信号
func (this *Node) listenSignals() {
var queue = make(chan os.Signal, 8)
signal.Notify(queue, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL, syscall.SIGQUIT)
goman.New(func() {
for range queue {
events.Notify(events.EventTerminated)
time.Sleep(100 * time.Millisecond)
os.Exit(0)
return
}
})
}
// 监听本地sock
func (this *Node) listenSock() error {
// 检查是否在运行