mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-08 02:40:32 +08:00
程序意外退出时关闭sqlite指针
This commit is contained in:
@@ -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 {
|
||||
// 检查是否在运行
|
||||
|
||||
Reference in New Issue
Block a user