Generic Gaming Server Setup
Add a gaming server and set its home directory to be where the servers are
adduser --disabled-login gameadmin usermod -d /srv/data/gameservers/ gameadmin
Make your gaming directories and set permissions etc.
gameadmin@solaris:/srv/data/gameservers$ ls -la total 16 drwxrwx--- 4 gameadmin gameadmin 4096 Aug 6 17:29 . drwxr-xr-x 8 root root 4096 Aug 6 17:28 .. drwxrwx--- 2 gameadmin gameadmin 4096 Aug 6 17:29 7d2dserver drwxrwx--- 2 gameadmin gameadmin 4096 Aug 6 17:28 Steam <--- Make this a capital "S" chown gameadmin:gameadmin gameservers/ -R chmod 770 gameservers/ -R
Install Steam Client
Steam requires this install
sudo dpkg --add-architecture i386 apt install lib32gcc1 libsdl2-2.0-0:i386
Become the gaming account
Move to the newly created steam directory Download the SteamCMD executable.
Run steam, login and check for errors
./steamcmd.sh login <username <password>
Install a server from steam
Run the steam cmdline client
Login and set directory
login <username> <password> force_install_dir ../gameserverdirectory app_update <stream app id>
Create a launcher config file (in the scripts directory)
Set the environment variables as per this template (make all references fully qualified)
ENABLED=true SCREEN_NAME=7d2d GAMEDIR=/srv/data/gameservers/7d2dserver/ CMDLINE="/srv/data/gameservers/7d2dserver/startserver.sh -configfile=/srv/data/gameservers/7d2dserver/serverconfig.xml"
Install the master launcher script.
#!/bin/bash # ===================================================================== # Script to lauch multiple command-line game servers # # V1.00 2020-08-06 Initial Release (ISM) # ===================================================================== _gfiles="/srv/data/gameservers/scripts/*.game" echo "Games server startup script starting to read $_gfiles" for g in $_gfiles do echo "Processing file: $g" source $g if [ $ENABLED != "true" ]; then echo "$SCREEN_NAME: disabled - skipping" continue fi screen -ls | grep "$SCREEN_NAME" &> /dev/null if [ $? == 0 ]; then echo "$SCREEN_NAME: already running - skipping" continue fi echo "$SCREEN_NAME: Changing directory to $GAMEDIR" cd $GAMEDIR echo "$SCREEN_NAME: Launching game..." screen -d -m -S $SCREEN_NAME $CMDLINE done
Set permissions on the launcher (make it executable)
chown gamesadmin:gameadmin game_launcher.sh chmod 770 game_launcher.sh
Make the Game Launcher start on boot. Use your favourite editor to make a new file called game_launcher.service in /etc/systemd/system/.
[Unit] Description=Game Server Launcher service After=network-online.target [Service] User=gameadmin Group=gameadmin Type=forking ExecStart=/srv/data/gameservers/game_launcher.sh [Install] WantedBy=multi-user.target
Once you are done, save the file and close the editor. Now we will activate the script so that it will start on boot. This makes to systemd recognize the file we just created.
systemctl --system daemon-reload
Enable the service. (optional if you want all the servers to launch on boot)
systemctl enable game_launcher.service
Or you can control it via a terminal using
systemctl start game_launcher.service
Once you've started the server, you can check that it's running with this command.
systemctl status game_launcher.service
Note running multiple times is not a problem (as the launcher checks for currently running screens)