pages tagged kf2serverAnton Eliassonhttp://www.antoneliasson.se//tags/kf2server/Anton Eliassonikiwiki2019-03-20T21:48:15ZVersion control for the Killing Floor 2 server configurationhttp://www.antoneliasson.se//journal/version-control-killing-floor-2-server/2019-03-20T21:48:15Z2016-05-20T08:56:00Z
<h2>Introduction</h2>
<p>To edit the configuration files for my Killing Floor 2 Dedicated Server more easily, I keep them in a version control repository that I sync to my main computer where I can use Emacs to edit them. This has not worked so well for several reasons:</p>
<ul>
<li>The configuration files are full of autogenerated crap that I never touch.</li>
<li>They change a lot by themselves when the game server is updated.</li>
<li>Worst of all, they contain the running state of the server (for example, the current map and difficulty).</li>
</ul>
<p>Another reason, which I can't really blame the game for, is that the server must be stopped while the configuration files are changed, or the changes will be silently discarded at some point.</p>
<p>Still, bad version control is usually better than no version control and this case has not been an exception. So here I share my setup.</p>
<h2>Structure</h2>
<p>I have a Git repository server running on one of my machines that will store the master copy of the config files. A Git repository server doesn't have to be more fancy than a directory that you can write to over SSH, but in my case I'm using <a href="http://gitolite.com/">Gitolite</a>. Gitolite allows me to easily restrict read and/or write access to some set of users. Users are defined by SSH keys and don't have to be human at all. The KF2 server will get its own user account with no access to any of my other repositories.</p>
<p>In this guide I will assume that the repository is located at <code>git@git.antoneliasson.se:kf2server-config.git</code> but you can also use a Github repository or similar if you like.</p>
<h2>Setup</h2>
<p>As the unprivileged user running the Killing Floor 2 server, <code>cd</code> to the configuration directory and <em>init</em> a Git repository:</p>
<pre><code>kf2server@kf2server:~$ cd .wine/drive_c/steamcmd/kf2server/KFGame/Config/
kf2server@kf2server:~/.wine/drive_c/steamcmd/kf2server/KFGame/Config$ git init
</code></pre>
<p>Optionally configure the username and e-mail address that will be used to sign your commits. Git will yell at you if you don't but since you probably won't make the repository public anyway it doesn't matter much.</p>
<pre><code>$ git config --global user.email anton@thisdomain.se
$ git config --global user.name "Anton Eliasson"
</code></pre>
<p>Make a <em>gitignore</em> file listing all the stuff that you don't care about. <code>Default*.ini</code> files contain the default settings and are copied to the <code>KF*.ini</code> and <code>PCServer-KF*.ini</code> files if the latter do not exist. The <code>PCServer</code> directory contains I have no idea what.</p>
<pre><code>$ cat .gitignore
/Default*
/PCServer
</code></pre>
<p>Now add the files that you think you might change at some point and make the first commit:</p>
<pre><code>$ git add PCServer-* KFAI.ini KFWeb.ini
$ git commit
</code></pre>
<p>Create an SSH keypair. Since mine will only be used for the purpose of authenticating the KF2 server to the Git server and nothing else I chose to not encrypt it with a passphrase.</p>
<pre><code>$ ssh-keygen
<enter>
<enter>
</code></pre>
<p>Now give this key read/write permissions to your master repository. Finally set up the Git remote and push your first commit:</p>
<pre><code>$ git remote add origin git@git.antoneliasson.se:kf2server-config.git
$ git push -u origin master
</code></pre>
<p>Sit back and relax, knowing that the world is now ever so slightly more version controlled <img alt=":)" src="http://www.antoneliasson.se//smileys/smile.png" /></p>
Containerized Killing Floor 2 Dedicated Serverhttp://www.antoneliasson.se//journal/containerized-killing-floor-2-dedicated-server/2019-03-20T21:48:15Z2016-05-19T08:45:00Z
<p>This guide shows how a Killing Floor 2 server can be setup in an LXC container.</p>
<hr />
<h2>Background</h2>
<p>Refer to <a href="http://www.antoneliasson.se//journal/installing-killing-floor-2-dedicated-server-in-linux/">Installing Killing Floor 2 Dedicated Server in Linux</a> for motivation why you might want to do this.</p>
<p><strong>A recap on container security:</strong> Anything that runs as root inside the container (guest) also has root access to the host machine, since they run on the same Linux kernel instance. You must make very sure that the container application can never get unauthorized privileged access. This is in contrast to virtualization, where the guest runs a separate operating system kernel and can never take over the host in the general case.</p>
<h2>Preparation</h2>
<p>Get yourself a minimal Linux installation running in a container somehow. It must be 64-bit and recent enough to have Wine 1.9 packaged. I'm using a Debian 8 guest (container) running on a Debian 8 host system using LXC managed by libvirt. If you have a similar host system you may want to have a look at my guide on <a href="http://www.antoneliasson.se//journal/lxc-libvirt-debian-jessie/">getting LXC to work with libvirt in Debian Jessie</a>.</p>
<h3>Example</h3>
<p>Create the container with a minimal Debian installation:</p>
<pre><code># lxc-create -t debian -n kf2server
</code></pre>
<p>Write down the root password. Start it up:</p>
<pre><code># lxc-start -n kf2server
</code></pre>
<p>Get the console fixed according to <a href="http://www.antoneliasson.se//journal/lxc-libvirt-debian-jessie/">my previous article</a>. Shut down the container.</p>
<p>Write a domain definition like <a href="http://www.antoneliasson.se//lxc-scripts/minimal-domain-definition.xml">this one</a>, which I also described in my <a href="http://www.antoneliasson.se//journal/lxc-libvirt-debian-jessie/">previous article about LXC</a>. Make sure to edit the name and paths according to your installation.</p>
<p>Import the definition into libvirt:</p>
<pre><code># virsh --connect lxc:/// define kf2server.xml
</code></pre>
<p>Start the new domain and connect to its console:</p>
<pre><code># virsh --connect lxc:/// start kf2server
# virsh --connect lxc:/// console kf2server
</code></pre>
<h2>System wide container configuration</h2>
<p>In this part the system wide configuration of the container is done. As I would like to be able to destroy/recreate the server at will I created a script to semi-automate this part. It is shown below.</p>
<hr />
<div class="highlight-sh"><pre class="hl">
<span class="hl slc">#!/bin/bash</span>
<span class="hl slc"># Start the container with libvirt and run this in the console to configure the</span>
<span class="hl slc"># system.</span>
<span class="hl kwb">set</span> <span class="hl opt">-</span>e
<span class="hl slc"># jessie/contrib for winetricks</span>
<span class="hl kwc">cat</span> <span class="hl opt">> /</span>etc<span class="hl opt">/</span>apt<span class="hl opt">/</span>sources.list <span class="hl str"><<EOF</span>
<span class="hl str">deb http://ftp.se.debian.org/debian/ jessie main contrib</span>
<span class="hl str">EOF</span>
<span class="hl slc"># Optionally use apt-cacher-ng, if you have one</span>
<span class="hl kwc">cat</span> <span class="hl opt">> /</span>etc<span class="hl opt">/</span>apt<span class="hl opt">/</span>apt.conf.d<span class="hl opt">/</span><span class="hl num">02</span>proxy <span class="hl str"><<EOF</span>
<span class="hl str">Acquire::http::proxy "http://aptcache:3142";</span>
<span class="hl str">EOF</span>
<span class="hl slc"># wget is used to download the WineHQ release key over HTTPS next</span>
apt-get update
apt-get <span class="hl kwc">install</span> <span class="hl opt">-</span>y wget <span class="hl opt"></</span>dev<span class="hl opt">/</span>null
<span class="hl slc"># Unstable wine repo for Wine 1.9</span>
<span class="hl kwc">cat</span> <span class="hl opt">> /</span>etc<span class="hl opt">/</span>apt<span class="hl opt">/</span>sources.list.d<span class="hl opt">/</span>wine.list <span class="hl str"><<EOF</span>
<span class="hl str">deb http://dl.winehq.org/wine-builds/debian/ jessie main</span>
<span class="hl str">EOF</span>
wget https<span class="hl opt">://</span>dl.winehq.org<span class="hl opt">/</span>wine-builds<span class="hl opt">/</span>Release.key
apt-key add Release.key
<span class="hl slc"># Enable 32-bit multiarch</span>
dpkg <span class="hl opt">--</span>add-architecture i386
apt-get update
<span class="hl slc"># xserver-common for MS VC runtime installer</span>
apt-get <span class="hl kwc">install</span> <span class="hl opt">-</span>y xserver-common <span class="hl opt"></</span>dev<span class="hl opt">/</span>null
apt-get <span class="hl kwc">install</span> <span class="hl opt">-</span>y wine-staging wine-staging-amd64 winehq-staging <span class="hl opt"></</span>dev<span class="hl opt">/</span>null
<span class="hl slc"># winetricks just for its dependencies. We will actually use the latest version from git.</span>
<span class="hl slc"># expect for unbuffer</span>
<span class="hl slc"># sudo for unprivileged control of the server systemd service</span>
apt-get <span class="hl kwc">install</span> <span class="hl opt">-</span>y winetricks expect sudo <span class="hl opt"></</span>dev<span class="hl opt">/</span>null
<span class="hl slc"># Optionally install your favorite tools for managing the server's config files</span>
apt-get <span class="hl kwc">install</span> <span class="hl opt">-</span>y git vim <span class="hl kwc">less</span> <span class="hl opt"></</span>dev<span class="hl opt">/</span>null
<span class="hl slc"># Get the latest winetricks, since the repository version doesn't support wine 1.8</span>
<span class="hl kwb">pushd</span> <span class="hl opt">/</span>usr<span class="hl opt">/</span><span class="hl kwb">local</span><span class="hl opt">/</span>bin<span class="hl opt">/</span>
wget https<span class="hl opt">://</span>raw.githubusercontent.com<span class="hl opt">/</span>Winetricks<span class="hl opt">/</span>winetricks<span class="hl opt">/</span>master<span class="hl opt">/</span>src<span class="hl opt">/</span>winetricks
<span class="hl kwc">chmod</span> <span class="hl opt">+</span>x winetricks
<span class="hl kwb">popd</span>
<span class="hl slc"># Create the non-privilegied user account. Nobody likes /bin/sh (default shell)</span>
useradd <span class="hl opt">--</span>system <span class="hl opt">--</span>create-home <span class="hl opt">--</span>shell <span class="hl opt">/</span>bin<span class="hl opt">/</span>bash kf2server
<span class="hl slc"># Allow the unprivileged user to start/stop the server</span>
<span class="hl kwc">cat</span> <span class="hl opt">>> /</span>etc<span class="hl opt">/</span>sudoers <span class="hl str"><<EOF</span>
<span class="hl str">kf2server ALL=NOPASSWD:/bin/systemctl status kf2server.service</span>
<span class="hl str">kf2server ALL=NOPASSWD:/bin/systemctl start kf2server.service</span>
<span class="hl str">kf2server ALL=NOPASSWD:/bin/systemctl stop kf2server.service</span>
<span class="hl str">EOF</span>
visudo <span class="hl opt">--</span>check
</pre></div>
<p><a href="http://www.antoneliasson.se//journal/containerized-killing-floor-2-dedicated-server/kf2server-system.sh">View raw file</a></p>
<hr />
<p>First, WineHQ's binary repo is installed. Next, APT is configured to use a local cache as a proxy. If you set up and tear down a lot of similar containers, you might want to set up your own cache using <a href="https://www.unix-ag.uni-kl.de/~bloch/acng/">apt-cacher-ng</a> or similar. It can save you a lot of time in skipped package downloads in the long run.</p>
<p>Next, Wine 1.9 and friends are installed using APT. <em>winetricks</em> from Debian is only installed to pull in all its dependencies, but the script itself will not actually be used. Instead, the git tip version of winetricks is installed next, since the packaged version in Debian does not support Wine 1.9.</p>
<p>A non-privileged account is then created that will run Steam and the actual Killing Floor 2 server. It is allowed to control the systemd service <em>kf2server</em>, which does not exist yet.</p>
<p>At this point you can <a href="http://www.antoneliasson.se//journal/containerized-killing-floor-2-dedicated-server/kf2server.service">download my custom service unit</a> for the KF2 server and drop it into <em>/etc/systemd/system/kf2server.service</em>. Refer to my article on <a href="http://www.antoneliasson.se//journal/installing-killing-floor-2-dedicated-server-in-linux/">installing Killing Floor 2 Dedicated Server in Linux</a> for more information on how it works and how you might need to customize it.</p>
<p>Finally, you may manually enable the service so that it starts automatically on the next boot:</p>
<pre><code># systemctl enable kf2server.service
</code></pre>
<h2>User configuration</h2>
<p>In this part we will configure Wine and install Steam as the unprivileged user. As part of the installation we will install Microsoft Visual C Runtime 2010 using winetricks. This is a graphical installation program, like it or not, so we need a way to display X windows somehow. I chose to use SSH with X Forwarding to display the windows on my desktop computer tunneled through SSH.</p>
<p>While still logged into the console as root, <code>su</code> to the unprivileged user:</p>
<pre><code># su - kf2server
</code></pre>
<p>Put your public SSH key in <em>/home/kf2server/.ssh/authorized_keys</em>. Log out and close the console. Using a desktop Linux machine, SSH to the container as the unprivileged user with X Forwarding enabled:</p>
<pre><code>$ ssh -X kf2server@kf2server
</code></pre>
<p>Run <code>winetricks vcrun2010</code> to install Visual C Runtime. Answer no to the offers of installing Mono and Gecko, unless you want them for some other purpose. A graphical installation wizard should then show. Follow the instructions.</p>
<p>Finally, to install Steam and Killing Floor 2 Dedicated Server, run the following script. It should be self-explanatory.</p>
<hr />
<div class="highlight-sh"><pre class="hl">
<span class="hl slc">#!/bin/bash</span>
<span class="hl slc"># Run this as the unprivilegied user in the container. Press "next, next,</span>
<span class="hl slc"># finish" and "OK" in the windows as applicable.</span>
<span class="hl kwb">set</span> <span class="hl opt">-</span>e
<span class="hl slc"># Download and unpack SteamCMD</span>
wget https<span class="hl opt">://</span>steamcdn-a.akamaihd.net<span class="hl opt">/</span>client<span class="hl opt">/</span>installer<span class="hl opt">/</span>steamcmd.<span class="hl kwc">zip</span>
<span class="hl kwc">unzip</span> steamcmd.<span class="hl kwc">zip</span>
mkdir .wine<span class="hl opt">/</span>drive_c<span class="hl opt">/</span>steamcmd
<span class="hl kwc">mv</span> steamcmd.exe .wine<span class="hl opt">/</span>drive_c<span class="hl opt">/</span>steamcmd<span class="hl opt">/</span>
<span class="hl slc"># Install and/or update KF2 dedicated server</span>
wine <span class="hl str">"C:/steamcmd/steamcmd.exe"</span> <span class="hl opt">+</span>login anonymous <span class="hl opt">+</span>force_install_dir kf2server <span class="hl opt">+</span>app_update <span class="hl num">232130</span> <span class="hl opt">+</span>quit
<span class="hl slc"># Start the server manually for testing. Exit with Ctrl+C twice.</span>
wine <span class="hl str">"C:/steamcmd/kf2server/Binaries/Win64/KFServer.exe"</span> kf-burningparis
</pre></div>
<p><a href="http://www.antoneliasson.se//journal/containerized-killing-floor-2-dedicated-server/kf2server-user.sh">View raw file</a></p>
<hr />
<h2>Future work</h2>
<p>You may want to install <a href="https://wiki.debian.org/UnattendedUpgrades">unattended-upgrades</a> to keep the system packages up-to-date.</p>
<p>Furthermore, the KF2 server is not automatically updated. When a new version is released you need to manually SSH into the server, stop the server and re-run <em>steamcmd.exe</em> with the +app_update option. You will notice when this happens because your server will disappear from the server browser.</p>
Installing Killing Floor 2 Dedicated Server in Linuxhttp://www.antoneliasson.se//journal/installing-killing-floor-2-dedicated-server-in-linux/2019-03-20T21:48:15Z2016-01-25T12:33:00Z
<p><strong>Update 2016-04-15: This guide is out of date. KF 2 server now requires Wine 1.9. I'll update this guide when I find the time.</strong></p>
<p><strong>Update 2016-05-19: See <a href="http://www.antoneliasson.se//journal/containerized-killing-floor-2-dedicated-server/">Containerized Killing Floor 2 Dedicated Server</a> for an updated guide.</strong></p>
<h2>Introduction</h2>
<p>Killing Floor 2 has a dedicated server program, but it is not yet available for Linux. However, the Windows version of the program runs perfectly well in a Wine environment. See its <a href="https://appdb.winehq.org/objectManager.php?sClass=application&iId=17316">AppDB entry</a>.</p>
<p>As this is a closed-source program which will run an Internet facing network server, it makes a lot of sense to try to contain it somewhat. Ideally, it should run on its own (containerized/virtualized/bare metal) machine. If you intend to run it on your regular PC, as will be covered here, it should at least run under its own user account.</p>
<p>This is mostly based on the guide <a href="http://forums.tripwireinteractive.com/showthread.php?t=105484">Installing KF 2 Server on Linux with WINE at the Tripwire forums</a>.</p>
<hr />
<h2>Preparation</h2>
<p>Install a recent version of Wine. I used the <a href="https://launchpad.net/~ubuntu-wine">official PPA for Ubuntu</a> to install Wine 1.8.</p>
<p>Create a new local user account on the machine that will run the server, and <code>su</code> to it:</p>
<pre><code># useradd --system --create-home kf2server
# su - kf2server
</code></pre>
<p><code>--system</code> makes it a system account which, among other things, will make it not show up at the login screen if you are using a full desktop environment. <code>--create-home</code> creates an empty home directory for the account. You may also want to use the <code>--base-dir</code> option to specify a different location for the home directory than the default <em>/home</em>.</p>
<h2>Installation</h2>
<p>Run <em>winecfg</em> once to create a Wine directory hierarchy:</p>
<pre><code>$ winecfg
</code></pre>
<p>Use <em>winetricks</em> to install Microsoft Visual C Runtime 2010 in Wine:</p>
<pre><code>$ winetricks vcrun2010
</code></pre>
<p>(Without it, the server would crash on startup with the error message "BugSplatRC resource DLL not found".)</p>
<p>Download <a href="https://developer.valvesoftware.com/wiki/SteamCMD">SteamCMD</a> for Windows. Extract the executable to <em>.wine/drive_c/steamcmd/</em> in the <em>kf2server</em> user's home directory. Use the following command to install the server into <em>C:/steamcmd/kf2server</em>:</p>
<pre><code>$ wine "C:/steamcmd/steamcmd.exe" +login anonymous +force_install_dir kf2server +app_update 232130 +quit
</code></pre>
<p><strong>The same command is later used to update the existing installation when Tripwire releases a new version of the dedicated server.</strong></p>
<p>Now run the server once to let it create its configuration files with default values:</p>
<pre><code>$ wine "C:/steamcmd/kf2server/Binaries/Win64/KFServer.exe" kf-burningparis
</code></pre>
<p>Note that it is required to specify a map on the command line, otherwise <a href="http://forums.tripwireinteractive.com/showthread.php?t=105730">Web Admin will not be accessible</a>. To stop it, press Ctrl+C twice.</p>
<h2>Configuration</h2>
<p>Edit the configuration files to your liking (located in <em>.wine/drive_c/steamcmd/kf2server/KFGame/Config/</em>). See the <a href="http://wiki.tripwireinteractive.com/index.php?title=Dedicated_Server_%28Killing_Floor_2%29">Tripwire wiki page</a> for details. I suggest only setting an administrator's password for the Web Admin interface, and doing the rest of the configuration there.</p>
<h2>Automatic start/stop</h2>
<p>On startup the server checks if it is connected to a controlling terminal. If not, it attempts to start an xterm, presumably so that the user can see the console output even if they started the server by double-clicking it in Windows Explorer. This somewhat obstructs unattended startup of the server, for instance by a init script. One workaround is to fake a controlling TTY using the program <em>unbuffer</em> from <a href="http://sourceforge.net/projects/expect/">expect</a> (see also <a href="http://packages.ubuntu.com/trusty/expect">expect Ubuntu packages</a>.</p>
<p>The following is a sample systemd service unit for the Killing Floor 2 Dedicated Server.</p>
<hr />
<div class="highlight-ini"><pre class="hl">
<span class="hl kwa">[Unit]</span>
<span class="hl kwb">Description</span><span class="hl opt">=</span><span class="hl kwc">Killing Floor 2 Dedicated Server</span>
<span class="hl kwa">[Service]</span>
<span class="hl kwb">ExecStart</span><span class="hl opt">=</span><span class="hl kwc">/usr/bin/unbuffer /usr/bin/wine "C:/steamcmd/kf2server/Binaries/Win64/KFServer.exe" kf-burningparis</span>
<span class="hl slc"># The user account that will run the server</span>
<span class="hl kwb">User</span><span class="hl opt">=</span><span class="hl kwc">kf2server</span>
<span class="hl kwb">Group</span><span class="hl opt">=</span><span class="hl kwc">kf2server</span>
<span class="hl slc"># The server is stopped by sending it a SIGINT (Ctrl-C)</span>
<span class="hl kwb">KillSignal</span><span class="hl opt">=</span><span class="hl kwc">SIGINT</span>
<span class="hl slc"># This hides most of the fixme errors in Wine, which are harmless in this case and just clutter up the output</span>
<span class="hl kwb">Environment</span><span class="hl opt">=</span><span class="hl kwc">"WINEDEBUG=fixme-all"</span>
<span class="hl kwa">[Install]</span>
<span class="hl kwb">WantedBy</span><span class="hl opt">=</span><span class="hl kwc">multi-user.target</span>
</pre></div>
<p><a href="http://www.antoneliasson.se//journal/installing-killing-floor-2-dedicated-server-in-linux/kf2server.service">View raw file</a></p>
<hr />
<p>Place it in <em>/etc/systemd/system/kf2server.service</em>. Now you can easily start and stop the server using the <em>systemctl</em> command, as in the following example:</p>
<pre><code># systemctl start kf2server.service
# systemctl status kf2server.service
● kf2server.service - Killing Floor 2 Dedicated Server
Loaded: loaded (/etc/systemd/system/kf2server.service; disabled; vendor preset: enabled)
Active: active (running) since mån 2016-01-25 16:52:16 CET; 35s ago
Main PID: 25624 (tclsh8.6)
CGroup: /system.slice/kf2server.service
[...]
</code></pre>
<p>To enable automatic start on system startup, run <code>systemctl enable kf2server.service</code>. Happy fragging!</p>