Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko committed Feb 6, 2024
2 parents 44fac8f + a618189 commit a44ef68
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
29 changes: 25 additions & 4 deletions supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] <defunct>")
}

func (s *Supervisor) isServiceRunning() bool {
Expand Down Expand Up @@ -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),
}
}

Expand Down
8 changes: 4 additions & 4 deletions webui/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down

0 comments on commit a44ef68

Please sign in to comment.