Skip to content

Commit

Permalink
新增:支持linux下使用systemctl启动游戏进程 (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadezi authored Feb 8, 2024
1 parent 251886a commit 0f7a218
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ pal.exe
.verysync

# ignore dist
webui/dist/
webui/dist/

# other
.idea
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type PlayerW struct {
}

type Config struct {
GameService bool `json:"gameService"` // 游戏以服务方式启动
GameServiceName string `json:"gameServiceName"` // 游戏服务名称
GamePath string `json:"gamePath"` // 游戏可执行文件路径PalServer.exe所处的位置
GameSavePath string `json:"gameSavePath"` // 游戏存档路径 \PalServer\Pal\Saved\文件夹的完整路径
BackupPath string `json:"backupPath"` // 备份路径
Expand Down
11 changes: 11 additions & 0 deletions front/palworld-front/src/pages/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,23 @@
label="自动注入UE4SS和可输入命令控制台DLL"
class="q-my-md"
/>
<q-toggle
v-model="config.gameService"
label="是否采用systemctl方式管理游戏服务"
class="q-my-md"
/>
<q-input
filled
v-model="config.maintenanceWarningMessage"
label="维护公告消息"
class="q-my-md"
/>
<q-input
filled
v-model="config.gameServiceName"
label="游戏进程服务名称"
class="q-my-md"
/>
<q-input
filled
v-model="config.webuiPort"
Expand Down
24 changes: 17 additions & 7 deletions webui/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,14 +594,24 @@ func restartService(cfg config.Config, kill bool) {
log.Printf("use bat")
sys.RunViaBatch(cfg, exePath, args)
} else {
cmd := exec.Command(exePath, args...)
cmd.Dir = cfg.GamePath // 设置工作目录为游戏路径

// 启动进程
if err := cmd.Start(); err != nil {
log.Printf("Failed to restart game server: %v", err)
if cfg.GameService && cfg.GameServiceName != "" {
cmd := exec.Command("sudo", "systemctl", "restart", cfg.GameServiceName)
// 启动进程
if err := cmd.Start(); err != nil {
log.Printf("Failed to restart game server: %v", err)
} else {
log.Printf("Game server restarted successfully")
}
} else {
log.Printf("Game server restarted successfully")
cmd := exec.Command(exePath, args...)
cmd.Dir = cfg.GamePath // 设置工作目录为游戏路径

// 启动进程
if err := cmd.Start(); err != nil {
log.Printf("Failed to restart game server: %v", err)
} else {
log.Printf("Game server restarted successfully")
}
}
}
}
Expand Down

0 comments on commit 0f7a218

Please sign in to comment.