How to Install Avorion on Ubuntu Server 20.04 LTS

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

How to Install Avorion on Ubuntu Server 20.04 LTS

Post: # 965Post LHammonds »

------------- WORK-IN-PROGRESS -------------

Table of Contents
=================
Installation of Ubuntu Server (DONE)
Firewall Rules (DONE)
Credentials (DONE)
Install SteamCMD/Avorion (DONE)
Create Your Galaxies (DONE)
Modify Avorion Configuration (DONE)
Start / Stop / Update Avorion Manually (DONE)
Server Logs (DONE)
RCON Utility (DONE)
Script Configuration File (DONE)
Script - Start (DONE)
Script - Stop (DONE)
Script - Update (DONE)
Avorion As A Service (DONE)
Script - Fix Permissions
Script - Backup / Restore / Encrypt / Decrypt
Installing Mods
Script - Might make an "install.sh" script that does everything in this tutorial for you. "might"

Overview

This article will cover how to install and maintain a dedicated Avorion server on Ubuntu.

Bash scripts and an RCON utility will be utilized to manage the server.

Two instances will be configured to demonstrate how to manage multiple instances. Two mods will also be used to demonstrate how to install, use and update mods.

These are the locations that will be utilized:

Code: Select all

/var/scripts/prod (custom Bash scripts)
/opt/avorion/savegame (folder to hold game instances)
/opt/avorion/bak (folder to hold backup archives)
/etc (holds configuration files)
/lib/systemd/system/avservice@ (holds configuration files related to systemctl start/stop commands)
These are the port settings that will be used for each instance. Feel free to use different settings but these should not conflict with anything else or themselves:

Code: Select all

Galaxy   Game Port  Steam Master  Steam Query  Query Port  RCON Port  Seed
-------- ---------  ------------  -----------  ----------  ---------  ---------
galaxy1      27101         27102        27103       27104      27105   11111111
galaxy2      27111         27112        27113       27114      27115   22222222
Tools utilized in this process
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Firewall Rules

Post: # 966Post LHammonds »

Firewall Rules

Here are the rules for running two galaxies. The RCON rule is commented out since we will not need to access RCON remotely but I left it in there in case you did. Adjust as necessary.

Code: Select all

echo "Adding Avorion Server rules"
ufw allow proto udp to any port 27101 comment 'Galaxy1 Port' 1>/dev/null 2>&1
ufw allow proto udp to any port 27102 comment 'G1 Steam Master' 1>/dev/null 2>&1
ufw allow proto udp to any port 27103 comment 'G1 Steam Query' 1>/dev/null 2>&1
ufw allow proto udp to any port 27104 comment 'G1 Query' 1>/dev/null 2>&1
#ufw allow proto tcp to any port 27105 comment 'G1 RCON' 1>/dev/null 2>&1

ufw allow proto udp to any port 27111 comment 'Galaxy2 Port' 1>/dev/null 2>&1
ufw allow proto udp to any port 27112 comment 'G2 Steam Master' 1>/dev/null 2>&1
ufw allow proto udp to any port 27113 comment 'G2 Steam Query' 1>/dev/null 2>&1
ufw allow proto udp to any port 27114 comment 'G2 Query' 1>/dev/null 2>&1
#ufw allow proto tcp to any port 27115 comment 'G2 RCON' 1>/dev/null 2>&1
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Credentials

Post: # 967Post LHammonds »

Credentials

There will be 3 levels of user access:
  1. root (system-level access for script schedules, backups and service control)
  2. avserver (owner/update account that has read/write access to all Avorion files and ability to use sudo command)
  3. avservice (runtime account that belongs to the avserver group which has the least permissions possible)
One group will be created called "avserver" and will contain the minimum permissions necessary to run the server (read-only access everywhere except necessary locations such as savegame data)

Let's create the game folders, the user accounts and setup correct access.

Code: Select all

sudo mkdir --parents /opt/avorion/savegame
sudo addgroup avserver
sudo useradd --comment "Avorion" --shell /bin/bash --home /opt/avorion/ --no-create-home --no-user-group --gid avserver avserver
sudo useradd --comment "Avorion Service" --shell /bin/bash --home /opt/avorion/ --no-create-home --no-user-group --gid avserver avservice
sudo usermod -aG sudo avserver
sudo chown --recursive avserver:avserver /opt/avorion
sudo chmod g+s /opt/avorion
sudo chmod 777 /opt/avorion/savegame
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Installation

Post: # 968Post LHammonds »

Install SteamCMD

Code: Select all

sudo apt update
sudo apt install steamcmd
Install Avorion

Download and install standard Avorion

Code: Select all

su --command="steamcmd +login anonymous +force_install_dir /opt/avorion +app_update 565060 validate +exit" avserver
or
Download and install BETA Avorion

Code: Select all

su --command="steamcmd +login anonymous +force_install_dir /opt/avorion +app_update 565060 -beta beta validate +exit" avserver
Create Galaxy #1

Code: Select all

su --command="/opt/avorion/server.sh --galaxy-name galaxy1 --admin 76561197970730192 --port 27101 --datapath /opt/avorion/savegame" avserver
>> Wait for initilization to complete. Look for "Server startup complete." <<

Code: Select all

/save
/stop
Create Galaxy #2

Code: Select all

su --command="/opt/avorion/server.sh --galaxy-name galaxy2 --admin 76561197970730192 --port 27102 --datapath /opt/avorion/savegame" avserver
>> Wait for initilization to complete <<

Code: Select all

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

Avorion Configuration

Post: # 969Post LHammonds »

Avorion Configuration
Reference: Documentation: Server Configuration

NOTE: Only make changes to the config file when the server is NOT running.

The most-basic changes you need to make are setting the RCON password and RCON port (which must be unique and unused)

Code: Select all

vi /opt/avorion/savegame/galaxy1/server.ini

Code: Select all

rconPassword=SET_PASSWORD_HERE
rconPort=27201
name=galaxy1
description=Avorion Server: galaxy1

Code: Select all

vi /opt/avorion/savegame/galaxy2/server.ini

Code: Select all

rconPassword=SET_PASSWORD_HERE
rconPort=27202
name=galaxy2
description=Avorion Server: galaxy2
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Commands

Post: # 970Post LHammonds »

Start Server Manually

Code: Select all

su --command="/opt/avorion/server.sh --galaxy-name galaxy1 --admin 76561197970730192 --datapath /opt/avorion/savegame" avserver
su --command="/opt/avorion/server.sh --galaxy-name galaxy2 --admin 76561197970730192 --datapath /opt/avorion/savegame" avserver
Stop Server Manually

At the console, type /save and then /stop
Or via RCON, use /save and /stop commands.

Update Server Manually

Stop the server cleanly using /save and /stop
Backup galaxy data
Run the same steamcmd used to install the app:

Stable Version

Code: Select all

su --command="steamcmd +login anonymous +force_install_dir /opt/avorion +app_update 565060 validate +exit" avserver
BETA Version

Code: Select all

su --command="steamcmd +login anonymous +force_install_dir /opt/avorion +app_update 565060 -beta beta validate +exit" avserver
Then start the server like normal.

Server Logs

Server logs can be found in locations such as this which is based on galaxy name:
Galaxy1 = /opt/avorion/savegame/galaxy1/serverlog*.txt
Galaxy2 = /opt/avorion/savegame/galaxy2/serverlog*.txt

To edit the most-recent log file:

Code: Select all

read recentfile < <(ls -t /opt/avorion/savegame/galaxy1/serverlog*.txt)&& vi "$recentfile"
read recentfile < <(ls -t /opt/avorion/savegame/galaxy2/serverlog*.txt)&& vi "$recentfile"
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

RCON

Post: # 971Post LHammonds »

RCON Utility

Reference: My Steam Guide: RCON Command-Line Utility

The game instances will be running as a service and thus, the console will not be available. This is where RCON comes in handy. Avorion has built-in support for RCON clients sending console commands such as /save, /stop, /status, /players, /version, etc.

Avorion does not ship with an RCON client though and neither does Ubuntu.

You can get source code written in C by [ASY]Zyrain that you can compile for use with your server. However, I did not like the fact that his version required the password to be passed as a command-line parameter which exposes it to anyone that is watching the process list. So I modified it to pull the password from a configuration file and a few other minor tweaks documented in the change log. Both versions are on my github so you can easily see what was changed if interested.

All the scripts that interact with the service will be using this RCON utility.

Here are the steps to download and compile my variation of the RCON utility.

Code: Select all

sudo apt install gcc
mkdir --parents /var/script/prod
wget https://raw.githubusercontent.com/LHammonds/rcon/main/rcon.c --output-document /var/scripts/prod/rcon.c
sudo gcc -o /var/scripts/prod/rcon /var/scripts/prod/rcon.c
sudo chown avserver:avserver /var/scripts/prod/rcon
sudo chmod 0750 /var/scripts/prod/rcon
sudo apt remove gcc
(I know, super difficult wasn't it!)

Might as well grab the manual for RCON and copy it where you can reference it anywhere:

Code: Select all

wget https://raw.githubusercontent.com/LHammonds/rcon/main/rcon.man --output-document /var/scripts/prod/rcon.man
sudo mkdir -p /usr/local/share/man/man1
sudo cp /var/scripts/prod/rcon.man /usr/local/share/man/man1/rcon.1
sudo chown root:root /usr/local/share/man/man1/rcon.1
sudo chmod 0644 /usr/local/share/man/man1/rcon.1
Now you can pull up the help page anytime you want:

Code: Select all

man rcon
Create an RCON configuration file for use with galaxy1:

Code: Select all

sudo touch /etc/rcon-galaxy1.ini
sudo chown avserver:avserver /etc/rcon-galaxy1.ini
sudo chmod 0640 /etc/rcon-galaxy1.ini
cat << EOF > /etc/rcon-galaxy1.ini
[rcon]
password=YOUR_RCON_PASSWORD
ipaddress=127.0.0.1
port=27201
EOF
Create an RCON configuration file for use with galaxy2:

Code: Select all

sudo touch /etc/rcon-galaxy2.ini
sudo chown avserver:avserver /etc/rcon-galaxy2.ini
sudo chmod 0640 /etc/rcon-galaxy2.ini
cat << EOF > /etc/rcon-galaxy2.ini
[rcon]
password=YOUR_RCON_PASSWORD
ipaddress=127.0.0.1
port=27202
EOF
Be sure to edit the RCON config files and match the password to what you will / have set for "rconPassword" in your server.ini file(s).

Usage Examples

Run a Save command using a generic config file for a common password but specify a different IP/port:

Code: Select all

rcon -f "/etc/rcon.ini" -a 127.0.0.1 -p 27110 "/save"
Run a Stop command using a pre-defined password, IP address and port in a specific instance config file:

Code: Select all

rcon -f "/etc/rcon-galaxy1.ini" "/stop"
Run a Status command using a pre-defined password, IP address and port in a specific instance config file:

Code: Select all

rcon -f "/etc/rcon-galaxy2.ini" "/status"
Run a Players command using a pre-defined password, IP address and port in a specific instance config file:

Code: Select all

rcon -f "/etc/rcon-galaxy3.ini" "/players"
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Script Configuration File

Post: # 972Post LHammonds »

Script Configuration File

This is a configuration file for use by these custom scripts which contain global variables/settings used by the various scripts.

Make sure each variable matches what you want for your system.

Code: Select all

wget https://raw.githubusercontent.com/LHammonds/avorion-bash/main/avorion.conf --output-document /var/scripts/prod/avorion-start.sh
sudo chown avserver:avserver /var/scripts/prod/avorion.conf
sudo chmod 0640 /var/scripts/prod/avorion.conf
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Script - Start

Post: # 980Post LHammonds »

Avorion Start Script

Code: Select all

wget https://raw.githubusercontent.com/LHammonds/avorion-bash/main/avorion-start.sh --output-document /var/scripts/prod/avorion-start.sh
sudo chown avserver:avserver /var/scripts/prod/avorion-start.sh
sudo chmod 0750 /var/scripts/prod/avorion-start.sh
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Script - Stop

Post: # 981Post LHammonds »

Avorion Stop Script

NOTE: Always ensure a save command is issued before a stop command.

Code: Select all

wget https://raw.githubusercontent.com/LHammonds/avorion-bash/main/avorion-stop.sh --output-document /var/scripts/prod/avorion-stop.sh
sudo chown avserver:avserver /var/scripts/prod/avorion-stop.sh
sudo chmod 0750 /var/scripts/prod/avorion-stop.sh
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Script - Update

Post: # 982Post LHammonds »

Avorion Update Script

Code: Select all

wget https://raw.githubusercontent.com/LHammonds/avorion-bash/main/avorion-update.sh --output-document /var/scripts/prod/avorion-update.sh
sudo chown avserver:avserver /var/scripts/prod/avorion-update.sh
sudo chmod 0750 /var/scripts/prod/avorion-update.sh
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Avorion as a Service

Post: # 983Post LHammonds »

Avorion as a Service

A generic system service will be created that will work for every instance by passing it the instance name as a parameter. This will allow the operating system to start each service when the server boots up and stop each service upon shutdown or reboot. This also means that the user can start and stop the instances just like any other standard Ubuntu service using the "systemctl" command such as "sudo systemctl stop avservice@galaxy1"

The steps below demonstrate how to create two services so you can see what changes are needed for each instance. Adjust the following commands to fit your needs.

Code: Select all

sudo touch /lib/systemd/system/avservice@.service
sudo chown root:root /lib/systemd/system/avservice@.service
sudo chmod 0644 /lib/systemd/system/avservice@.service
Now edit the file:

Code: Select all

sudo vi /lib/systemd/system/avservice\@.service
Copy/paste the following into the file.

Code: Select all

[Unit]
Description=Avorion: %i
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target
[Service]
Type=simple
Restart=on-failure
RestartSec=30
StartLimitInterval=180s
StartLimitBurst=3
KillMode=control-group
KillSignal=SIGQUIT
SendSIGHUP=no
SendSIGKILL=yes
FinalKillSignal=SIGKILL
RuntimeMaxSec=infinity
LimitNOFILE=100000
#ExecStartPre=/var/scripts/prod/avorion-sync-1.sh %i
TimeoutStartSec=180
ExecStart=/var/scripts/prod/avorion-start.sh %i
ExecReload=
TimeoutStopSec=120
ExecStop=/var/scripts/prod/avorion-stop.sh %i
User=avservice
Group=avserver
[Install]
WantedBy=multi-user.target
Make sure the paths to the scripts are correct and that the "User" matches "GameUser" in /etc/avorion.conf and "Group" matches "GameService" in /etc/avorion.conf

Now reload the systemd daemon so it can see the newly created service file.

Code: Select all

sudo systemctl daemon-reload
Now we enable the service(s) so the operating system will start and stop the service automatically whenever the server starts up or shuts down.

Tailor the following commands to suit your environment:

Code: Select all

sudo systemctl enable avservice@galaxy1
sudo systemctl enable avservice@galaxy2
To manually start galaxy1 instance, you can run the following command:

Code: Select all

sudo systemctl start avservice@galaxy1
To check status of galaxy1 instance:

Code: Select all

sudo systemctl status avservice@galaxy1
To stop galaxy1 instance:

Code: Select all

sudo systemctl stop avservice@galaxy1
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Backup and Restore

Post: # 984Post LHammonds »

Backup

------------- WORK-IN-PROGRESS -------------

Reference: Database Backup Script

I will turn these into easy-to-run scripts but for now, this is the meat of what they will do.

Code: Select all

tar -cpf - /opt/avorion/savegame/* | 7z a -si -mx=9 -w/tmp /bak/avorion/2021-09-22-avorion.tar.7z 1>/dev/null 2>&1
Restore

Code: Select all

7z x -so -w/tmp /bak/avorion/2021-09-22-avorion.tar.7z | tar -C /tmp/avorion --strip-components=3 -xf -
Encrypt

Code: Select all

touch /etc/passenc
chown root:root /etc/passenc
chmod 600 /etc/passenc
echo 'CryptPass="abc123"' >> /etc/passenc
gpg --cipher-algo aes256 --output /bak/avorion/2021-09-22-avorion.enc --passphrase-file /etc/passenc --batch --yes --no-tty --symmetric /bak/avorion/2021-09-22-avorion.tar.7z
rm /bak/avorion/2021-09-22-avorion.tar.7z
Decrypt

Code: Select all

gpg --cipher-algo aes256 --output /tmp/avorion/decrypted.tar.7z --passphrase-file /etc/passenc --quiet --batch --yes --no-tty --decrypt /bak/avorion/2021-09-22-avorion.enc
User avatar
LHammonds
Site Admin
Site Admin
Posts: 963
Joined: Fri Jul 31, 2009 6:27 pm
Are you a filthy spam bot?: No
Location: Behind You
Contact:

Installing Mods

Post: # 985Post LHammonds »

Installing Mods

------------- WORK-IN-PROGRESS -------------

Not finished with this section, these are just notes for me to try out and refine.

Code: Select all

sudo touch /opt/avorion/savegame/galaxy1/modconfig.lua
sudo chown avserver:avserver /opt/avorion/savegame/galaxy1/modconfig.lua
sudo chmod 0640 /opt/avorion/savegame/galaxy1/modconfig.lua
cat << EOF > /opt/avorion/savegame/galaxy1/modconfig.lua
--------------------------------
-- Mod Configuration File
-- Version: 1.0
-- Date: 2021-09-11
--------------------------------
-- Location of a mods folder other then the default one of /mods in your galaxy folder.
modLocation = ""
-- It is recommended by the developers of Avorion that force enabling be left turned off.
forceEnabling = false
-- List of Steam Workshop mods to enable.
mods =
{
    {workshopid = "2559722572"},
    {workshopid = "445220"}
}
-- List of Steam Workshop client-side mods allowed while on this server. Same format as mods section.
allowed =
{
}
EOF
Post Reply