Skip to content

Commit 79773d2

Browse files
feat: Implement server stop before update and restart to prevent detached processes.
Fixes #159
1 parent 2830ae3 commit 79773d2

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/setup/update/runandexit.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/JacksonTheMaster/StationeersServerUI/v5/src/config"
1313
"github.com/JacksonTheMaster/StationeersServerUI/v5/src/logger"
14+
"github.com/JacksonTheMaster/StationeersServerUI/v5/src/managers/gamemgr"
1415
)
1516

1617
// runAndExit launches the new executable and terminates the current process
@@ -61,7 +62,13 @@ func runAndExitLinux(newExe string) error {
6162
return nil
6263
}
6364

64-
func RestartMySelf() {
65+
func RestartMySelf() { // Stop the game server before restarting to prevent detached processes
66+
if config.GetIsGameServerRunning() {
67+
logger.Install.Info("🛑 Stopping game server before restart...")
68+
if err := gamemgr.InternalStopServer(); err != nil {
69+
logger.Install.Warn(fmt.Sprintf("⚠️ Failed to stop game server before restart: %v. Proceeding anyway.", err))
70+
}
71+
}
6572
currentExe, err := os.Executable()
6673
if err != nil {
6774
logger.Install.Warn(fmt.Sprintf("⚠️ Restart failed: couldn’t get current executable path: %v. Keeping version %s.", err, config.GetVersion()))

src/setup/update/updater.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/JacksonTheMaster/StationeersServerUI/v5/src/config"
1111
"github.com/JacksonTheMaster/StationeersServerUI/v5/src/logger"
12+
"github.com/JacksonTheMaster/StationeersServerUI/v5/src/managers/gamemgr"
1213
)
1314

1415
// githubRelease represents the structure of a GitHub release response
@@ -112,6 +113,14 @@ func Update(isInUpdateableState bool) (err error, newVersion string) {
112113
}
113114
}
114115

116+
// Stop the game server before launching the new version to prevent detached processes
117+
if config.GetIsGameServerRunning() {
118+
logger.Install.Info("🛑 Stopping game server before applying update...")
119+
if err := gamemgr.InternalStopServer(); err != nil {
120+
logger.Install.Warn(fmt.Sprintf("⚠️ Failed to stop game server before update: %v. Proceeding anyway.", err))
121+
}
122+
}
123+
115124
// Launch the new executable and exit
116125
logger.Install.Info("🚀 Launching the new version and retiring the old one...")
117126
if runtime.GOOS == "windows" {

0 commit comments

Comments
 (0)