mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🐛 macOS 端报错 数据库被锁定 Fix https://github.com/siyuan-note/siyuan/issues/6492
This commit is contained in:
parent
51a0db5822
commit
949e21ee09
1 changed files with 37 additions and 7 deletions
|
|
@ -78,8 +78,7 @@ func Serve(fastMode bool) {
|
||||||
api.ServeAPI(ginServer)
|
api.ServeAPI(ginServer)
|
||||||
|
|
||||||
if !fastMode {
|
if !fastMode {
|
||||||
// 杀掉占用 6806 的已有内核进程
|
killRunningKernel()
|
||||||
killByPort(util.FixedPort)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var host string
|
var host string
|
||||||
|
|
@ -460,6 +459,37 @@ func corsMiddleware() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func killRunningKernel() {
|
||||||
|
if "dev" == util.Mode {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if util.ContainerStd != util.Container {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
processes, err := goPS.Processes()
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("get processes failed: %s", err)
|
||||||
|
killByPort(util.FixedPort)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
killed := false
|
||||||
|
for _, process := range processes {
|
||||||
|
procName := strings.ToLower(process.Executable())
|
||||||
|
if strings.Contains(procName, "siyuan-kernel") {
|
||||||
|
kill(fmt.Sprintf("%d", process.Pid()))
|
||||||
|
killed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if killed {
|
||||||
|
portJSON := filepath.Join(util.HomeDir, ".config", "siyuan", "port.json")
|
||||||
|
os.RemoveAll(portJSON)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func killByPort(port string) {
|
func killByPort(port string) {
|
||||||
if !isPortOpen(port) {
|
if !isPortOpen(port) {
|
||||||
return
|
return
|
||||||
|
|
@ -497,14 +527,14 @@ func isPortOpen(port string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func kill(pid string) {
|
func kill(pid string) {
|
||||||
var kill *exec.Cmd
|
var killCmd *exec.Cmd
|
||||||
if gulu.OS.IsWindows() {
|
if gulu.OS.IsWindows() {
|
||||||
kill = exec.Command("cmd", "/c", "TASKKILL /F /PID "+pid)
|
killCmd = exec.Command("cmd", "/c", "TASKKILL /F /PID "+pid)
|
||||||
} else {
|
} else {
|
||||||
kill = exec.Command("kill", "-9", pid)
|
killCmd = exec.Command("kill", "-9", pid)
|
||||||
}
|
}
|
||||||
gulu.CmdAttr(kill)
|
gulu.CmdAttr(killCmd)
|
||||||
kill.CombinedOutput()
|
killCmd.CombinedOutput()
|
||||||
}
|
}
|
||||||
|
|
||||||
func pidByPort(port string) (ret string) {
|
func pidByPort(port string) (ret string) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue