Dedicated Server Setup: Linux and Wine

==Introduction==
This guide is an collection of all steps that can or need to be taken to set up an working Conan Exiles Server. Additionally side info about settings and adding mods is included.
==Basic requirements==
* A computer with the minimum dedicated server system requirements is required.
* Basic knowledge of the OS you will be using. (Linux)
* Basic knowledge of SteamCMD.
* Knowledge of Wine.
==Installation for Ubuntu 22.04==
===General notes===
For some reason I use VIM to edit text, if you're not comfortable with vim feel free to replace vim with nano or your preferred editor anywhere you see me use vim.
===Install Software===
Run sudo add-apt-repository multiverse to enable the multiverse repo that contains steamcmd 
Run sudo dpkg --add-architecture i386 to enable installing 32 bit packages on a 64 bit OS 
Run sudo apt update to update the apt repos 
Run sudo apt upgrade to upgrade the currently installed packages 
Run sudo apt install software-properties-common lib32gcc-s1 steamcmd to install steamcmd and its prerequisites 
Run sudo apt install wine xvfb to install Wine and xvfb. Wine will run the server and xvfb will allow you to run it headless.
If prompted to restart certain services hit TAB to select OK and then SPACE or ENTER to continue
===Configure Firewall===
Add rules to the firewall to avoid problems in the future
Add rule for the UDP ports used by the conan server: 
sudo ufw allow proto udp from any to any port 7777,7778,27015
Add rule for the TCP ports used by the conan server:
sudo ufw allow proto tcp from any to any port 7777,25575
I'm generally configuring these servers via SSH so I also add a rule for that but if you're running the server directly on hardware or using a console you can ignore this step. 
sudo ufw allow ssh
Enable the firewall, choose Y when you get the warning about possibly interrupting connections sudo ufw enable
If you have problems later and you're worried about it being the firewall you can disable UFW with: sudo ufw disable
===Install the Conan Exiles server===
Create the steam user that you'll use to run the server: 
sudo useradd -m -s /bin/bash steam
Log into the steam account with sudo and change to its home directory:
sudo -iu steam 
cd $HOME
Create a directory for the Conan server and move into it:
mkdir conan_exiles
cd conan_exiles
I had to add the path to steamcmd to my PATH variable, I'm not sure if that means I did something wrong earlier but if you get a not found message when trying to run steamcmd you can modify the .profile file in the steam user home directory by adding the line below to the bottom of the file.
export PATH="/usr/games/:$PATH"
Then:
source .profile
To set the new PATH or log out / back into the steam account.
Run the command below to start steam, force the platform type to Windows then set the installation directory, login to steam, install the conan exiles dedicated server and finally quit steamcmd.
steamcmd +@sSteamCmdForcePlatformType windows +force_install_dir /home/steam/conan_exiles +login anonymous +app_update 443030 +quit
Next you need to set some environment variables for wine. You can run these commands from the terminal or add them at the end of the .profile file to make sure they're set automatically any time the steam account logs in. Later we'll be configuring a service file that also includes this information so you can run these commands from the terminal if you just want to set the variables temporarily:
export WINEARCH=win64
export WINEPREFIX=/home/steam/.wine64
To start the server run:
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' wine /home/steam/conan_exiles/ConanSandboxServer.exe -log 
Making sure to modify the path to ConanSandboxServer.exe if you used a different folder. Running the server once will create the configuration files you'll be modifying below.
Hit CTRL+C to stop the server
Type exit to stop running commands as the steam user, you'll need to be a user with sudo privileges to create the service.
===Create a service===
Creating a service will allow you to start and stop the server more easily, it'll also allow you to have it run automatically if the server restarts.
Create a .service file that describes the service you're running with: vim /etc/systemd/system/conanexiles.service
Add the following contents to the file:
[Unit]
Description=Conan Exiles Server
After=network.target
[Service]
# If you define the environment variables here you can remove them from your .profile
# but I don't think it'll do any harm to have them defined twice, as long as the definitions
# are the same
Environment=WINEARCH=win64
Environment=WINEPREFIX=/home/steam/.wine64
# Set the user, group and relative directory
WorkingDirectory=/home/steam/conan_exiles/
User=steam
Group=steam
# Run xvfb-run to start the server
ExecStart=/usr/bin/xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' wine /home/steam/conan_exiles/ConanSandboxServer.exe -log
[Install]
WantedBy=multi-user.target
Alias=conan.service
Start the service with: sudo systemctl start conanexiles
Check the status with:
sudo systemctl status conanexiles
Stop the service with:
sudo systemctl stop conanexiles
Set the service to run at boot wtih:
sudo systemctl enable conanexiles
Or restart it with:
sudo systemctl restart conanexiles
Now you can configure the server as you like.
Known Issues
The service runs fine but doesn't like stopping, I've just set it to start automatically with the machine and I reboot 
the whole thing if I need to restart the server. I suspect it has to do with xvfb-run but I'm not sure what option would fix that.
===Configuring the Server===
There are various settings within various files in the directory. To make this as easy as possible, only Settings that can't or shouldn't be changed in game are listed. Various Additional Commands can be found below.
All .ini files are located under <Server Directory>/ConanSandbox/Saved/Config/WindowsServer/
====Engine.ini====
Add these lines in this order at the Bottom of your .ini.
 [URL]
 Port=7777 ;The Port for your Server
 [OnlineSubsystemSteam]
 ServerName= ;The Name of your Server which is shown in the Server Browser
 ServerQueryPort=27015 ;The Port the SteamAPI will query your Server from
 ServerPassword= ;The Password needed to access the Server
====ServerSettings.ini====
Add these lines at the Bottom of your .ini if they don't exist yet.
 MaxNudity= ;Either 0, 1 or 2. 2=Full, 1= Partial, 0=None
 LogoutCharactersRemainInTheWorld=False ;This option currently should be disabled as there is an issue with Bodies
 PVPEnabled=False ;Add this line to disable PVP
 AdminPassword= ;This option is important: Use this to change all Settings ingame later.
====Game.ini====
Add these lines at the Bottom of your .ini if they don't exist yet.
 [ConanSandbox]
 UserID=steam
 [/script/engine.gamesession]
 MaxPlayers=20 ;you can choose the max allowed players on the server
 [/script/engine.gamenetworkmanager]
 TotalNetBandwidth=4000000 ;careful changing the bandwith values as it may cause lags to your players
 MaxDynamicBandwidth=100000
 MinDynamicBandwidth=40000
===Updating and Additions===
To Update the Server, simply stop it using the above described method. After the Server has stopped, open SteamCMD in the Terminal by typing:
 steamcmd +@sSteamCmdForcePlatformType windows
After that type:
 login anonymous
After the login process is done, use this Command to update the Server:
 app_update 443030
When this process is finished, your Server should be up to date.
Shell script update Example update.sh inside update.sh you need to have the below information.
#!/bin/sh
screen steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +app_update 443030 +exit
===Known Problems===
* Running SteamCMD using scripts sometimes leads to problems that render the Server unusable. Solution: Do the manual steps as described above.
* Dreamworld:Display: SQLite database open FAILED. Solution: Run as root account.
* to unimplemented function msvcp140.dll.?_IsNonBlockingThread@_Task_impl_base@details@Concurrency@@SA_NXZ Solution: Delete game-db.shm and game-db.wal, additionally delete the Logs Folder.
==Adding Mods==
Adding mods can be done. See the SteamCMD command example shown below. 
steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +workshop_download_item 440900 999999999
This is only an example of a mod but what you need is the workshop id number which is shown in the address bar of your web browser.
Example: https://steamcommunity.com/sharedfiles/filedetails/?id= After the = sign there is a long number this number is associated with the workshop mod your looking at subscribing to or modding your server to. That number goes into what is shown up at the top as the 999999999 number above.
Ended up writing a shell script to kill the server process then update the game and then the workshop items I am using. The reason I automated this process is because mods are constantly being updated and if users have a miss match on there mods they won't be able to login to the server..
Below is an examples of shell scripts i wrote for this process.. 
Create a new shell script by using nano an editor in linux. By using the command: nano update.sh Place below code in the document the use ctrl - x and save it.
#!/bin/sh
killall 9 ConanSandboxServer.exe
killall 9 ConanSandboxServer-Win64-Test.exe
killall 9 Xvfb
/usr/bin/screen -d -m steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +force_install_dir /home/user/server +app_update 443030 +exit
sleep 2s
#sh /home/user/workshopmapupdate.sh
## Uncomment workshopmapupdate.sh for use of mods.
## Make sure you point +force_install_dir /home/user/server to the correct directory!
## This command must be installed otherwise the server will not update its self correctly!
Next you will want to create workshopmapupdate.sh To do this use nano as the editor as performed above for the first part of the process and create the file. Example: nano workshopmapupdate.sh Once the below information is copied and pasted and adjusted for the mods you wish to add use ctrl - x then save it.
#!/bin/sh
/usr/bin/screen -d -m steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +workshop_download_item 440900 111111111111111 +workshop_download_item 440900 2222222222222222 +exit
The above should be written all in one line do not use enter to go to the next line.. This is a very very long command line. In place of the 1's you will want to put your first id number as gathered at the end of that hit space and put a plus sign to start the next command in this case we start off with the second workshop item 2's. You can add as many workshop mods that you want but they All must be on the same line. End the command process by using a plus sign then exit after the last work shop map has been placed in your shell script.
The Mods will be downloaded to a file located in the home directory of the steam user that you are using.. This directory is hidden but can be accessed by using the cd commands like listed below. 
Example: 
cd /home/user/.steam/SteamApps/workshop/content/440900
The folders located in this place is the mods that you are using you will need to later direct your modlist.txt to the .pak files located inside each of the folders.
Next we need to create the Mods folder.
Go into your saved directory where you have stored the server in our case we used a folder called server. Inside this folder look for ConanSandbox folder. You will want to change director into this folder by using the cd command like this.. Example: cd ~/server/ConanSandbox 
After you are inside the ConanSandbox folder you will want to make a directory called: Mods Example command: mkdir Mods
Now you will want to change directory into mods to do this type: cd ./Mods 
Use nano to create a file called modlist.txt Example command: nano modlist.txt
Here you will want to add the file locations to the .pak files of the mods you are using for your server.
Below is an example.
/home/user/.steam/SteamApps/workshop/content/440900/1111111111/Modlist1.pak
/home/user/.steam/SteamApps/workshop/content/440900/2222222222/Modlist2.pak
/home/user/.steam/SteamApps/workshop/content/440900/3333333333/Modlist3.pak
/home/user/.steam/SteamApps/workshop/content/440900/4444444444/Modlist4.pak
/home/user/.steam/SteamApps/workshop/content/440900/5555555555/Modlist5.pak
Use ctrl-x command to save the file .
Now you will eventually want to automate this process by crontab. To access crontab type in commandline: crontab -e
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
@reboot cs /home/user/server && sh start.sh
00 3 * * * cd /home/user && sh update.sh
12 3 * * * cd /home/user/server && sh start.sh
00 9 * * * cd /home/user && sh update.sh
12 9 * * * cd /home/user/server && sh start.sh
00 14 * * * cd /home/user && sh update.sh
12 14 * * * cd /home/user/server && sh start.sh
00 20 * * * cd /home/user && sh update.sh
12 20 * * * cd /home/user/server && sh start.sh
UPDATE
Your start script should look like this if your using cron to start the game for automation. In this case the script is named start.sh and we located it in /home/user/server/ folder.
#!/bin/sh
/usr/bin/screen -d -m xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' wine /home/user/server/ConanSandboxServer.exe -log
#### This should be placed in your home directory some where.. 
#### The above line of code needs to be on one line.
So the above is an example the file locations and how you can use crontab to automatically update your game server and the workshop mods using linux.
09-08-2019
Up until this point the above worked but some thing changed in the way SteamCMD handles shell scripts so now we update our severs like this here is an updated view of 
Also where it says harby replace that with what username your using.. It's my bad I should have done cleaner copy and paste for the directions. LorenTedford
crontab -e
@reboot DISPLAY=:0.0 /usr/games/steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +force_install_dir /home/harby/server +app_update 443030 +workshop_download_item 440900 880454836 +workshop_download_item 440900 1763829520 +workshop_download_item 440900 864199675 +workshop_download_item 440900 1598693222 +workshop_download_item 440900 1369802940 +workshop_download_item 440900 1555101525 +workshop_download_item 440900 1389908968 +workshop_download_item 440900 1125427722 +workshop_download_item 440900 1390768358 +workshop_download_item 440900 1212764185 +workshop_download_item 440900 884155321 +workshop_download_item 440900 901911361 +workshop_download_item 440900 1367404881 +exit && /usr/bin/screen -d -m xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' wine /home/harby/server/ConanSandboxServer.exe -log -MaxPlayers=70
00 3 * * * sh /home/harby/killall.sh
01 3 * * * DISPLAY=:0.0 /usr/games/steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +force_install_dir /home/harby/server +app_update 443030 +workshop_download_item 440900 880454836 +workshop_download_item 440900 1763829520 +workshop_download_item 440900 864199675 +workshop_download_item 440900 1598693222 +workshop_download_item 440900 1369802940 +workshop_download_item 440900 1555101525 +workshop_download_item 440900 1389908968 +workshop_download_item 440900 1125427722 +workshop_download_item 440900 1390768358 +workshop_download_item 440900 1212764185 +workshop_download_item 440900 884155321 +workshop_download_item 440900 901911361 +workshop_download_item 440900 1367404881 +exit && /usr/bin/screen -d -m xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' wine /home/harby/server/ConanSandboxServer.exe -log -MaxPlayers=70
00 9 * * * sh /home/harby/killall.sh
01 9 * * * DISPLAY=:0.0 /usr/games/steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +force_install_dir /home/harby/server +app_update 443030 +workshop_download_item 440900 880454836 +workshop_download_item 440900 1763829520 +workshop_download_item 440900 864199675 +workshop_download_item 440900 1598693222 +workshop_download_item 440900 1369802940 +workshop_download_item 440900 1555101525 +workshop_download_item 440900 1389908968 +workshop_download_item 440900 1125427722 +workshop_download_item 440900 1390768358 +workshop_download_item 440900 1212764185 +workshop_download_item 440900 884155321 +workshop_download_item 440900 901911361 +workshop_download_item 440900 1367404881 +exit && /usr/bin/screen -d -m xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' wine /home/harby/server/ConanSandboxServer.exe -log -MaxPlayers=70
00 11 * * * sh /home/harby/killall.sh
01 11 * * * DISPLAY=:0.0 /usr/games/steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +force_install_dir /home/harby/server +app_update 443030 +workshop_download_item 440900 880454836 +workshop_download_item 440900 1763829520 +workshop_download_item 440900 864199675 +workshop_download_item 440900 1598693222 +workshop_download_item 440900 1369802940 +workshop_download_item 440900 1555101525 +workshop_download_item 440900 1389908968 +workshop_download_item 440900 1125427722 +workshop_download_item 440900 1390768358 +workshop_download_item 440900 1212764185 +workshop_download_item 440900 884155321 +workshop_download_item 440900 901911361 +workshop_download_item 440900 1367404881 +exit && /usr/bin/screen -d -m xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' wine /home/harby/server/ConanSandboxServer.exe -log -MaxPlayers=70
00 14 * * * sh /home/harby/killall.sh
01 14 * * * DISPLAY=:0.0 /usr/games/steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +force_install_dir /home/harby/server +app_update 443030 +workshop_download_item 440900 880454836 +workshop_download_item 440900 1763829520 +workshop_download_item 440900 864199675 +workshop_download_item 440900 1598693222 +workshop_download_item 440900 1369802940 +workshop_download_item 440900 1555101525 +workshop_download_item 440900 1389908968 +workshop_download_item 440900 1125427722 +workshop_download_item 440900 1390768358 +workshop_download_item 440900 1212764185 +workshop_download_item 440900 884155321 +workshop_download_item 440900 901911361 +workshop_download_item 440900 1367404881 +exit && /usr/bin/screen -d -m xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' wine /home/harby/server/ConanSandboxServer.exe -log -MaxPlayers=70
00 20 * * * sh /home/harby/killall.sh
01 20 * * * DISPLAY=:0.0 /usr/games/steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +force_install_dir /home/harby/server +app_update 443030 +workshop_download_item 440900 880454836 +workshop_download_item 440900 1763829520 +workshop_download_item 440900 864199675 +workshop_download_item 440900 1598693222 +workshop_download_item 440900 1369802940 +workshop_download_item 440900 1555101525 +workshop_download_item 440900 1389908968 +workshop_download_item 440900 1125427722 +workshop_download_item 440900 1390768358 +workshop_download_item 440900 1212764185 +workshop_download_item 440900 884155321 +workshop_download_item 440900 901911361 +workshop_download_item 440900 1367404881 +exit && /usr/bin/screen -d -m xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' wine /home/harby/server/ConanSandboxServer.exe -log -MaxPlayers=70
For some reason this wiki has word wrap turned on so I have uploaded a backup copy here to pastebin in hopes it helps. https://pastebin.com/7b6yX42a
Here is an example of killall.sh
#!/bin/sh
killall 9 screen
killall 9 ConanSandboxServer.exe
killall 9 ConanSandboxServer-Win64-Test.exe
killall 9 Xvfb
chmod 777 -R /home/harby/*
chown harby:harby -R /home/harby/*
==Backing Up and Savefiles==
In crontab -e you will want to put the correct file locations when running your script Here is an example of what crontab might look like.
# m h dom mon dow command
59 2 * * * sh /home/user/autobackup.sh
Here is what that shell script might look like. Change the locations needed for your setup. Backup script name is autobackup.sh
#!/bin/bash
##################################################################
# SRCDIR="" #
# DESTDIR="/home/user/Backup" #
# FILENAME=test-server-$(date +%-Y%-m%-d)-$(date +%-T).tgz #
# tar --create --file=$DESTDIR$FILENAME $SRCDIR #
########Failed Backup Script Above ###############################
##################################################################
##################################################################
#
# Backup to NFS mount script.
#
################################################################
# What to backup.
backup_files="/home/user/server/ConanSandbox/Saved"
backup_files2="/home/user/server/ConanSandbox/Mods"
# Where to backup to.
dest="/home/user/Backup"
# Create archive filename.
day=$(date +%-Y%-m%-d)
time=$(date +%-T)
archive_file="Saved-$day-$time.tgz"
# Print start status message.
#echo "Backing up $backup_files and $backup_files2 to $dest/$archive_file"
#date
#echo
# Backup the files using tar.
tar czf $dest/$archive_file $backup_files $backup_files2
# Print end status message.
#echo
#echo "Backup finished"
#date
# Long listing of files in $dest to check file sizes.
#ls -lh $dest
exit
Now you will want to make a directory for backup folder "mkdir /home/user/Backup"
You can also run the backup script manually by running the command "sh autobackup.sh"
==Removing Mods==
Removing a mod from the server and using the same database may cause issues.
When you remove a mod, those mods leave a lot of garbage behind.
This can cause undesired effects. Removing a mod is sometimes paired with wiping the database clean for a fresh install of the server.
==Wiping your Savefiles==
Be careful doing so, because it will erase all progression and saved buildings!
Delete or rename the game.db file. This will recreate a new empty file.
== References ==
a: Screen.html - ss64.com
Category:Servers
Category:Guides