diff --git a/supervisor.go b/supervisor.go index f2a0024..7584aab 100644 --- a/supervisor.go +++ b/supervisor.go @@ -46,7 +46,28 @@ func (s *Supervisor) Start() { } else { fmt.Println("当前正常运行中~") } + if s.hasDefunct() { + fmt.Printf("发现僵尸进程,准备清理~\n") + // 此处只考虑僵尸进程是由自身内存释放导致的,如有其他原因,后续再patch + sys.RestartApplication() + } + } +} + +func (s *Supervisor) hasDefunct() bool { + var cmd *exec.Cmd + if runtime.GOOS == "windows" { + return false + } else { + cmd = exec.Command("ps", "-ef") + } + var out bytes.Buffer + cmd.Stdout = &out + err := cmd.Run() + if err != nil { + fmt.Printf("[ERROR] %v", err) } + return strings.Contains(out.String(), "[PalServer.sh] ") } func (s *Supervisor) isServiceRunning() bool { @@ -109,10 +130,10 @@ func (s *Supervisor) restartService() { // 对于非Windows系统的处理保持不变 exePath = filepath.Join(s.Config.GamePath, s.Config.ProcessName+".sh") args = []string{ - "--RconEnabled=True", - fmt.Sprintf("--AdminPassword=%s", s.Config.WorldSettings.AdminPassword), - fmt.Sprintf("--port=%d", s.Config.WorldSettings.PublicPort), - fmt.Sprintf("--players=%d", s.Config.WorldSettings.ServerPlayerMaxNum), + "-RconEnabled=True", + fmt.Sprintf("-AdminPassword=%s", s.Config.WorldSettings.AdminPassword), + fmt.Sprintf("-port=%d", s.Config.WorldSettings.PublicPort), + fmt.Sprintf("-players=%d", s.Config.WorldSettings.ServerPlayerMaxNum), } } diff --git a/webui/api.go b/webui/api.go index e707d01..09bde08 100644 --- a/webui/api.go +++ b/webui/api.go @@ -579,10 +579,10 @@ func restartService(cfg config.Config, kill bool) { } else { exePath = filepath.Join(cfg.GamePath, cfg.ProcessName+".sh") args = []string{ - "--RconEnabled=True", - fmt.Sprintf("--AdminPassword=%s", cfg.WorldSettings.AdminPassword), - fmt.Sprintf("--port=%d", cfg.WorldSettings.PublicPort), - fmt.Sprintf("--players=%d", cfg.WorldSettings.ServerPlayerMaxNum), + "-RconEnabled=True", + fmt.Sprintf("-AdminPassword=%s", cfg.WorldSettings.AdminPassword), + fmt.Sprintf("-port=%d", cfg.WorldSettings.PublicPort), + fmt.Sprintf("-players=%d", cfg.WorldSettings.ServerPlayerMaxNum), } }