Ubuntu

如何在 Ubuntu 上安裝 gmod 伺服器作為系統服務?

  • December 28, 2020

我在 Ubuntu 18.04 上有一個 GMod 伺服器,當我通過./run_gmod.sh(作為擁有文件夾/文件的“蒸汽”使用者)執行它時它執行良好,其內容是

#!/bin/sh
/datadrive/srcds/gmod/srcds_run -game garrysmod -console -norestart -strictportbind -port 27015 -tickrate 60 -maxplayers 20 \
       +gamemode terrortown +map ttt_minecraft_b5 \
       +host_workshop_collection 1413001823 \
       +sv_setsteamaccount XXXXXXXXXXXX

但是,我想使用 systemctl 將其安裝為服務,以便在啟動伺服器(Azure VM)時自動啟動。我創建了一個包含/etc/systemd/system/gmod.service以下內容的文件:

[Unit]
Description=Gmod Server
After=network.target

[Service]
User=steam
WorkingDirectory=/datadrive/srcds/
ExecStart=/datadrive/srcds/gmod/srcds_run -game garrysmod -console -norestart -strictportbind -port 27015 -tickrate 60 -maxplayers 20 +gamemode terrortown +map ttt_minecraft_b5 +host_workshop_collection 1413001823 +sv_setsteamaccount XXXXXXXXXXXX

[Install]
WantedBy=multi-user.target

但是,當我嘗試systemctl start gmod得到的日誌時,我很奇怪:

Nov 27 22:54:49 Server1 systemd[1]: Started Gmod Server.                                                                                                                                                                       
Nov 27 22:54:49 Server1 bash[4025]: Auto detecting CPU                                                                                                                                                                         
Nov 27 22:54:49 Server1 bash[4025]: Using default binary: ./srcds_linux                                                                                                                                                        
Nov 27 22:54:52 Server1 bash[4025]: Setting breakpad minidump AppID = 4000                                                                                                                                                     
Nov 27 22:54:52 Server1 bash[4025]: [S_API] SteamAPI_Init(): Loaded 'steamclient.so' OK.                                                                                                                                       
Nov 27 22:54:52 Server1 bash[4025]: Could not find steamerrorreporter binary. Any minidumps will be uploaded in-processapplicationmanager.cpp (3936) : Assertion Failed: CApplicationManager::GetMountVolume: invalid index    
Nov 27 22:54:52 Server1 bash[4025]: CAppInfoCacheReadFromDiskThread took 0 milliseconds to initialize                                                                                                                          
Nov 27 22:54:52 Server1 bash[4025]: Uploading dump (in-process) [proxy '']                                                                                                                                                     
Nov 27 22:54:52 Server1 bash[4025]: /tmp/dumps/crash_20201127225452_4.dmp                                                                                                                                                      
Nov 27 22:54:52 Server1 bash[4025]: success = no                                                                                                                                                                               
Nov 27 22:54:52 Server1 bash[4025]: error:  libcurl.so: cannot open shared object file: No such file or directory                                                                                                              
Nov 27 22:54:52 Server1 bash[4025]: applicationmanager.cpp (3936) : Assertion Failed: CApplicationManager::GetMountVolume: invalid index                                                                                       
Nov 27 22:54:52 Server1 bash[4025]: applicationmanager.cpp (4099) : Assertion Failed: m_vecInstallBaseFolders.Count() > 0                                                                                                      
Nov 27 22:54:52 Server1 bash[4025]: CApplicationManagerPopulateThread took 0 milliseconds to initialize (will have waited on CAppInfoCacheReadFromDiskThread)                                                                  
Nov 27 22:54:52 Server1 bash[4025]: [S_API FAIL] Tried to access Steam interface SteamUser020 before SteamAPI_Init succeeded.                                                                                                  
Nov 27 22:54:56 Server1 bash[4025]: applicationmanager.cpp (4099) : Assertion Failed: m_vecInstallBaseFolders.Count() > 0                                                                                                      
Nov 27 22:55:00 Server1 bash[4025]: [S_API] SteamAPI_Init(): Loaded 'steamclient.so' OK.                                                                                                                                       
Nov 27 22:55:00 Server1 bash[4025]: CAppInfoCacheReadFromDiskThread took 0 milliseconds to initialize                                                                                                                          
Nov 27 22:55:00 Server1 bash[4025]: Could not find steamerrorreporter binary. Any minidumps will be uploaded in-processapplicationmanager.cpp (3936) : Assertion Failed: CApplicationManager::GetMountVolume: invalid index    
Nov 27 22:55:00 Server1 bash[4025]: Uploading dump (in-process) [proxy '']                                                                                                                                                     
Nov 27 22:55:00 Server1 bash[4025]: /tmp/dumps/crash_20201127225500_5.dmp                                                                                                                                                      
Nov 27 22:55:00 Server1 bash[4025]: success = no                                                                                                                                                                               
Nov 27 22:55:00 Server1 bash[4025]: error:  libcurl.so: cannot open shared object file: No such file or directory                                                                                                              
Nov 27 22:55:00 Server1 bash[4025]: applicationmanager.cpp (3936) : Assertion Failed: CApplicationManager::GetMountVolume: invalid index                                                                                       
Nov 27 22:55:00 Server1 bash[4025]: applicationmanager.cpp (3936) : Assertion Failed: CApplicationManager::GetMountVolume: invalid index                                                                                       
Nov 27 22:55:00 Server1 bash[4025]: applicationmanager.cpp (4099) : Assertion Failed: m_vecInstallBaseFolders.Count() > 0                                                                                                      
Nov 27 22:55:00 Server1 bash[4025]: CApplicationManagerPopulateThread took 0 milliseconds to initialize (will have waited on CAppInfoCacheReadFromDiskThread)                                                                  
Nov 27 22:55:09 Server1 bash[4025]: applicationmanager.cpp (4099) : Assertion Failed: m_vecInstallBaseFolders.Count() > 0                                                                                                      
Nov 27 22:55:09 Server1 bash[4025]: httpclient.cpp (4181) : Assertion Failed: Failed writing http cache file to disk                                                                                                           
Nov 27 23:00:42 Server1 systemd[1]: gmod.service: Current command vanished from the unit file, execution of the command list won't be resumed.   

正常日誌,通過run_gmod.sh腳本啟動時,如下所示:

Auto detecting CPU
Using default binary: ./srcds_linux
mount.cfg adding path: '/datadrive/srcds/gmod/content/css/cstrike'
Couldn't load shader dll: game_shader_generic_garrysmod_srv.soConVarRef mat_dxlevel doesn't point to an existing ConVar
Game_srv.so loaded for "Garry's Mod"
Setting breakpad minidump AppID = 4000
Initializing Steam libraries for Workshop..
[S_API] SteamAPI_Init(): Loaded 'steamclient.so' OK.
CApplicationManagerPopulateThread took 0 milliseconds to initialize (will have waited on CAppInfoCacheReadFromDiskThread)
CAppInfoCacheReadFromDiskThread took 2 milliseconds to initialize
[S_API FAIL] Tried to access Steam interface SteamUser020 before SteamAPI_Init succeeded.
WS: Waiting for Steam to log us in..
WS: Fetching collection info...
Processing collection 1413001823...
  Collection 'TGN Reborn Content'
  75 new addons
WS: Finished!

WS: Processing 75 addons...
and then more stuff happens

日誌在第二行 ( Using default binary: ./srcds_linux) 之後就出現了分歧,我不明白為什麼在執行相同的命令時結果如此不同,只是方式不同。這是 GMod 特有的,還是我的gmod.service文件不正確?我已經嘗試過查找,但是將伺服器作為服務執行的資源很少,而且.service我發現的範例文件最終會給出類似的錯誤,所以我認為我應該從頭開始。

事實證明,使用以下 systemd 服務文件使其工作(或多或少):

[Unit]
Description=Gmod Server
After=network.target

[Service]
User=rooday # the user I normally run run_gmod.sh with
ExecStart=/datadrive/srcds/run_gmod.sh
Restart=Always

[Install]
WantedBy=multi-user.target

或多或少是因為使用我的伺服器的參數run_gmod.sh啟動srcds_run(部分 srcds 安裝)腳本,並且該腳本本身在設置一些環境變數後執行實際的伺服器二進製文件。所以現在至少我的伺服器使用 systemd 成功執行,但journalctl只跟踪srcds_run而不是具有所有重要日誌的實際伺服器二進製文件。但這超出了這個問題的範圍/可以比 gmod 更籠統地說,所以我會考慮回答這個問題。

引用自:https://serverfault.com/questions/1044197