How to Install 7 Days to Die on Ubuntu Server 18.04 LTS

Post Reply
User avatar
LHammonds
Site Admin
Site Admin
Posts: 772
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

How to Install 7 Days to Die on Ubuntu Server 18.04 LTS

Post: # 778Post LHammonds
Sun Oct 13, 2019 7:05 pm

********** WORK IN PROGRESS **********

Overview

This article will describe how to install a dedicated 7 Days to Die server and configure it to run two instances of a map (Navezgane and a randomly generated map) with some useful modifications and custom in-game notifications.

Server Requirements:
  • 4 GB RAM
  • 15 GB free space on /opt (for Alpha 18)
  • 2 CPU cores (2.4GHz+)
Reference: Linux Server Management Scripts

These paths will be used:

/opt/sdtd - home for the user running the server and base path for the server management script system
/bak/sdtd - by default backups of game data files will go here
/usr/local/bin/7dtd.sh - Management script entry point
/usr/local/lib/7dtd/ - Base path of script components
/etc/7dtd.conf - Global configuration options
/etc/bash_completion.d/7dtd - Bash-completion configuration to auto-complete the commands for the scripts
/etc/cron.d/7dtd-backup - Cron job for game backups
/etc/init.d/7dtd.sh - Init script to start/stop the instances on host boot/shutdown

NOTE: Make sure you have enough space on /opt to install 7 Days to Die which is about 12 GB for Alpha 18. You will also need additional space as players explore the map and expand the savegame size.

Install Ubuntu Server

This article assumes Ubuntu was installed following these instructions: How to Install Ubuntu Server

Firewall Rules

Edit the firewall script that was created during the initial setup of the server (if you followed my instructions):

Code: Select all

sudo vi /var/scripts/prod/en-firewall.sh
Add the following:

NOTE: The Telnet port is commented out since it should not be open to the entire Internet but left there as documentation about the port.

Code: Select all

echo "Adding 7dtd Server rules"
ufw allow proto tcp to any port 27000 comment '#1 game port' 1>/dev/null 2>&1
ufw allow proto udp to any port 27000:27002 comment '#1 Steam communication' 1>/dev/null 2>&1
ufw allow proto tcp to any port 8080 comment '#1 Web control panel' 1>/dev/null 2>&1
#ufw allow proto tcp to any port 8081 comment '#1 Telnet control panel' 1>/dev/null 2>&1
ufw allow proto tcp to any port 8082 comment '#1 Allocs Web Map' 1>/dev/null 2>&1

ufw allow proto tcp to any port 27003 comment '#2 game port' 1>/dev/null 2>&1
ufw allow proto udp to any port 27003:27005 comment '#2 Steam communication' 1>/dev/null 2>&1
ufw allow proto tcp to any port 8083 comment '#2 Web control panel' 1>/dev/null 2>&1
#ufw allow proto tcp to any port 8084 comment '#2 Telnet control panel' 1>/dev/null 2>&1
ufw allow proto tcp to any port 8085 comment '#2 Allocs Web Map' 1>/dev/null 2>&1
Run the updated rules:

Code: Select all

sudo /var/scripts/prod/en-firewall.sh
Install Prerequisites

Code: Select all

sudo apt install xmlstarlet gcc
Create Low-Rights User Accounts

Code: Select all

sudo addgroup sdtd
sudo addgroup steam
sudo useradd --comment "7 Days to Die Server" --shell /bin/bash --home /opt/sdtd --gid sdtd sdtd
sudo useradd --comment "Steam Command" --gid sudo --gid steam --create-home steam
Install Alloc's Server Management Scripts

Download the scripts archive, extract it, rename the home folder, set correct file ownership, re-archive and re-extract to the final destination while preserving the changes that were made:

Code: Select all

sudo mkdir /bak/sdtd
sudo chown sdtd:sdtd /bak/sdtd
mkdir /tmp/t
cd /tmp
wget http://illy.bz/fi/7dtd/management_scripts.tar.gz
tar --touch -xvzf /tmp/management_scripts.tar.gz -C /tmp/t/
mv /tmp/t/home /tmp/t/opt
sudo chown --recursive root:root /tmp/t/*
sudo chown --recursive sdtd:sdtd /tmp/t/opt/sdtd
sudo chmod 0755 /tmp/t/etc/init.d/7dtd.sh
sudo chmod 0755 /tmp/t/etc/bash_completion.d/7dtd
sudo chmod 0755 /tmp/t/usr/local/bin/7dtd.sh
sudo find /tmp/t/usr/local/lib/7dtd -type f -name '*.sh' -exec chmod 0755 {} \;
sudo tar -czvf /tmp/7dtd-new.tar.gz /tmp/t/*
sudo tar -xzvf /tmp/7dtd-new.tar.gz -C / --strip-components=2
Enable bash completion - This will allow you to press TAB after typing 7dtd.sh and seeing the options you can type after it.

Code: Select all

sudo vi /etc/bash.bashrc
Starting on line 35, uncomment these lines by removing the # character at the beginning of each line:

Code: Select all

if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
Edit the configuration file and fix the paths:

Code: Select all

sudo vi /etc/7dtd.conf
Change line 19 from:

Code: Select all

export SDTD_BASE=/home/sdtd
to:

Code: Select all

export SDTD_BASE=/opt/sdtd
Change line 25 from:

Code: Select all

export SDTD_BACKUP_ROOT=/home/sdtd/backup
to:

Code: Select all

export SDTD_BACKUP_ROOT=/bak/sdtd
Install 7 Days to Die Server Files

Run this command to install SteamCMD and download the game engine. You can choose to install the experimental or stable version.

Code: Select all

7dtd.sh updateengine --experimental
or

Code: Select all

7dtd.sh updateengine --stable
Run this command to install Alloc's server fixes and web map service:

Code: Select all

7dtd.sh updatefixes
Run this command to make sure the update scripts are current:

Code: Select all

7dtd.sh updatescripts
Compile start-stop-daemon

Code: Select all

cd /usr/local/lib/7dtd/start-stop-daemon
gcc -o start-stop-daemon start-stop-daemon.c
sudo chown root:root start-stop-daemon
sudo chmod 0755 start-stop-daemon
Configure Default Admins

Make sure you know what your Steam 64 ID is and edit this file:

Code: Select all

sudo vi /opt/sdtd/templates/admins.xml
Around line 27, change this section from:

Code: Select all

    <admins>
        <!-- <admin steamID="STEAM GUID" permission_level="0" /> -->
    </admins>
to (using the example of a Steam 64 ID of 76561197970730192):

Code: Select all

    <admins>
        <admin steamID="76561197970730192" permission_level="0" />
    </admins>
Create a New Instance

Code: Select all

sudo 7dtd.sh instances create
Answer the setup questions how you want your server configured. Once created, we will then copy this configuration file to the templates folder and the next time we create another instance, the defaults will be how we configured this instance and we only need to change what is different from the first instance created.

If you called your instance "hamcraft" then this is how you would copy the config you just made to become the new default:

Code: Select all

sudo cp /opt/sdtd/instances/hamcraft/config.xml /opt/sdtd/templates/.
sudo chown sdtd:sdtd /opt/sdtd/templates/config.xml
sudo chmod 644 /opt/sdtd/templates/config.xml
Update Server
  1. List all game instances:

    Code: Select all

    sudo 7dtd.sh instances list

    Code: Select all

    Instance name        | Running  | Players | Port
    ---------------------+----------+---------+------
    hamcraft             |      yes |    1/ 8 | 27000
    navezgane            |      yes |    0/ 8 | 27003
  2. Stop each running instance:

    Code: Select all

    sudo 7dtd.sh kill hamcraft
    sudo 7dtd.sh kill navezgane
  3. Verify all instances have been shutdown:

    Code: Select all

    sudo 7dtd.sh instances list
  4. Make a backup of the savegames:

    Code: Select all

    sudo 7dtd.sh backup
  5. Update the game engine:
    if using stable branch:

    Code: Select all

    sudo 7dtd.sh updateengine --stable
    if using experimental branch:

    Code: Select all

    sudo 7dtd.sh updateengine --experimental
  6. Update the server fixes:

    Code: Select all

    sudo 7dtd.sh updatefixes
  7. Update the management scripts:

    Code: Select all

    sudo 7dtd.sh updatescripts
  8. Start the game instances that were running earlier:

    Code: Select all

    sudo 7dtd.sh start hamcraft
    sudo 7dtd.sh start navezgane
  9. Wait for the instances to load and check their log files for errors (look for "INF StartGame done" which means the server is ready to accept player connections):

    Code: Select all

    sudo vi /opt/sdtd/instances/hamcraft/logs/current_output_log.txt

    Code: Select all

    sudo vi /opt/sdtd/instances/navezgane/logs/current_output_log.txt
  10. On your gaming PC, start up the client and see if you can connect and verify all mods are working like normal.
Backup Data

To manually initiate a backup, run this command:

Code: Select all

sudo 7dtd.sh backup
To have it run at various times throughout the day, edit the root crontab:

Code: Select all

crontab -u root -e
Add this line:

Code: Select all

0 8,12,17,20,22 * * * /usr/local/bin/7dtd.sh backup > /dev/null 2>&1
Be sure to copy the savegames to a different location and keep a copy offsite (such as another computer or external hard drive or web service)

User avatar
LHammonds
Site Admin
Site Admin
Posts: 772
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Instance Creation Options

Post: # 779Post LHammonds
Tue Oct 15, 2019 1:47 pm

Instance Creation Options

Here are the options presented to you when creating a new instance. Be sure to give a unique instance name and port numbers.

Code: Select all

7dtd.sh instances create

Code: Select all

Instance name: navezgane
Server name: NavCraft
Server password:
Public server, options: 2: public
Base Port: 27003
Disabled network protocols, options: 1: None
Server description: Navezgane County
Server website URL: 7dtd.hammondslegacy.com
Hide command execution in log, options: 0: Log all
Max uncovered chunks per player: 131072
Max download speed for the world (KiB/s): 512
Limit allowed view distance settings of clients (5-12): 12
Enable EasyAntiCheat: true
Maximum number of concurrent zombies: 60
Maximum number of concurrent animals: 50
Max players: 4
Reserved VIP slots: 0
Permission level required for VIP slots: 100
Admin slots: 0
Permission level required for admin slots: 0
Enable control panel: false
Control panel port: 8083
Control panel password: supersecretpass
Telnet port: 8084
Telnet password: superdupersecretpass
Max failed login attempts: 10
Telnet login blocktime after failed logins (seconds): 10
World decoration seed: mombo#5
World name, options: 2: Navezgane
Random generation seed (if world RWG):
Random generation map size (if world RWG) (2048-16384):
Game mode, options: 1: GameModeSurvival
XP gain multiplier %: 100
Party range to share kill / quest XP rewards: 100
Player killing, options: 3: Kill everyone
Persistent player profiles: false
Safe zone up to player level: 5
Safe zone up to player hours: 5
Item spawn menu: false
Block damage modifier for players (%): 100
Block damage modifier for AIs (%): 100
Block damage modifier for AIs during blood moons (%): 100
Drop on Death, options: 2: Toolbelt only
Drop on Quit, options: 0: Nothing
Loot abundance (%): 100
Loot respawn delay (days): 7
Airdrop delay (hours): 72
Enable AirDrop markers: true
Length of one day: 60
Duration of daylight (in ingame hours) (0-24): 18
Difficulty (+ damage given / received), options: 2: Nomad (100% / 100%)
Zombie speed, regular, options: 0: Walk
Zombie speed, night, options: 2: Run
Zombie speed, ferals, options: 3: Sprint
Zombie speed, bloodmoons, options: 3: Sprint
Spawn mode: true
Enemy difficulty, options: 0: Normal
Enemies per Player on Blood moons (0-64): 8
Bedroll deadzone size: 15
Bedroll expiry time (days) 45
Land claim size: 13
Minimum keystone distance: 30
Claim expiry time (days): 3
Claim decay mode, options: 0: Linear
Claim durability modifier - online: 4
Claim durability modifier - offline: 4

User avatar
LHammonds
Site Admin
Site Admin
Posts: 772
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Alloc's Web Map

Post: # 780Post LHammonds
Tue Oct 15, 2019 4:05 pm

Alloc's Web Map

By default, the web map permissions do not allow the public to see the map. We will modify the permissions to make the map more usable.

Here are the goals of these changes:
  • Not logged in - Only allow the map to be visible to guests.
  • Logged in - Normal players can see their own location, land claim blocks, total players online.
  • Logged in - Admin players are not restricted and have access to all features.
Let's edit the 1st instance we create:

Code: Select all

vi /opt/sdtd/instances/hamcraft/webpermissions.xml
Here is the default settings:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<webpermissions>
        <admintokens>
                <!-- <token name="adminuser1" token="supersecrettoken" permission_level="0" /> -->
        </admintokens>
        <permissions>
                <!-- <permission module="web.map" permission_level="1000" /> -->
                <!-- <permission module="webapi.getlog" permission_level="0" /> -->
                <!-- <permission module="webapi.executeconsolecommand" permission_level="0" /> -->
                <!-- <permission module="webapi.getstats" permission_level="1000" /> -->
                <!-- <permission module="webapi.getplayersonline" permission_level="1000" /> -->
                <!-- <permission module="webapi.getplayerslocation" permission_level="1000" /> -->
                <!-- <permission module="webapi.viewallplayers" permission_level="1" /> -->
                <!-- <permission module="webapi.getlandclaims" permission_level="1000" /> -->
                <!-- <permission module="webapi.viewallclaims" permission_level="1" /> -->
                <!-- <permission module="webapi.getplayerinventory" permission_level="1" /> -->
                <!-- <permission module="webapi.gethostilelocation" permission_level="1" /> -->
                <!-- <permission module="webapi.getanimalslocation" permission_level="1" /> -->
        </permissions>
</webpermissions>
We will now change the permissions to look like the following:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<webpermissions>
        <admintokens>
                <token name="adminuser1" token="supersecrettoken" permission_level="0" />
        </admintokens>
        <permissions>
                <permission module="web.map" permission_level="2000" />
                <permission module="webapi.getlog" permission_level="0" />
                <permission module="webapi.executeconsolecommand" permission_level="0" />
                <permission module="webapi.getstats" permission_level="1000" />
                <permission module="webapi.getplayersonline" permission_level="1000" />
                <permission module="webapi.getplayerslocation" permission_level="1000" />
                <permission module="webapi.viewallplayers" permission_level="1" />
                <permission module="webapi.getlandclaims" permission_level="1000" />
                <permission module="webapi.viewallclaims" permission_level="1" />
                <permission module="webapi.getplayerinventory" permission_level="1" />
                <permission module="webapi.gethostilelocation" permission_level="1" />
                <permission module="webapi.getanimalslocation" permission_level="1" />
        </permissions>
</webpermissions>

User avatar
LHammonds
Site Admin
Site Admin
Posts: 772
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Restart Script

Post: # 787Post LHammonds
Sun Nov 10, 2019 11:18 am

Restart Script

The server instance can shutdown from time to time due to a crash or whatnot. This script is designed to check on the running status of a particular instance and start it if not running.

Create the script file and set appropriate permissions:

Code: Select all

sudo touch /var/scripts/prod/sdtd-crashfix.sh
sudo chown root:root /var/scripts/prod/sdtd-crashfix.sh
sudo chmod 700 /var/scripts/prod/sdtd-crashfix.sh
/var/scripts/prod/sdtd-crashfix.sh

Code: Select all

#!/bin/bash
#############################################################
## Name : sdtd-crashfix.sh
## Version : 1.0
## Date : 2019-11-10
## Author : LHammonds
## Purpose : Check instance status and start if not running.
## Compatibility : Verified on Ubuntu Server 18.04 LTS
##                 7 Days to Die, Alpha 18
###################### CHANGE LOG ###########################
## DATE       VER WHO WHAT WAS CHANGED
## ---------- --- --- ---------------------------------------
## 2019-11-10 1.0 LTH Created script.
#############################################################
InstancePath="/opt/sdtd/instances"
DoNotStart="/tmp/sdtd-donotstart.txt"
ServerInstance=$1

## Check for override and make sure the instances are not stopped for a reason.
## We do not want to start an instance if something has it down on purpose.
if [[ -f ${DoNotStart} ]]; then
  echo "[WARN] Cannot start server. A 'DoNotStart' file detected."
  exit 0
fi

## Make sure a valid instance was passed to the script.
if [[ ! -f "${InstancePath}/${ServerInstance}/config.xml" ]];then
  echo "[ERROR] Cannot detect server instance called ${ServerInstance}"
  exit 1
fi

## Start instance if not running.
if [[ `/usr/local/bin/7dtd.sh status ${ServerInstance} | grep "Status: Running"` ]]; then
  echo "[INFO] ${ServerInstance} is running"
else
  echo "[INFO] ${ServerInstance} is stopped. Starting instance now..."
  /usr/local/bin/7dtd.sh start ${ServerInstance}
fi
exit 0
Edit your root crontab schedule:

Code: Select all

sudo crontab -u root -e
Here are the lines to run the script every 5 minutes for game instances called hamcraft and navezgane:

Code: Select all

*/5 * * * * /var/scripts/prod/sdtd-crashfix.sh hamcraft > /dev/null 2>&1
*/5 * * * * /var/scripts/prod/sdtd-crashfix.sh navezgane > /dev/null 2>&1

Post Reply