Hello everybody,
I had to update the server today and I decided to automate the task because I am so lazy to do it myself all the time.
I run the script as root, but the script will launch the server on the user of your choice (steam in this guide). You can also put the the location of this script in /etc/rc.local to automatically open the game server when the ubuntu server reboot. When launching the game server, it will perform a backup and update the server before officially open the server.
My server installation setup:
I decided to follow the installation setup of this official Conan Exile dedicated server wiki in the section #Linux (I used /home/steam as for the force_install_dir). I cant post the link here, but search conan exile server installation ubuntu gamepedia on google and you will find it.
Before launching the script for the first time, you need to make sure permission on the script itself is set correctly :
chmod +x < path of this script > #mine is at /root/my_script.sh
You also need to check that the permission on the installation folder are good for the steam user to run the game server by doing:
chown -R steam:steam /home/steam
Explanation of the script:
My script is making sure that my iptables rules are OK for my server, in case somebody would break the firewall rules. If you dont need it, you can delete the part about iptables in the script. It will then take a backup of the whole game folder and compress it. After that, it will perform the server update by forcing it (I was not able to update it normally). It then launched a screen session on the user steam.
You can access the server screen my going on the steam user and doing screen -x conan or screen -R conan. The name of this screen can be change in the script easily but changing the value of screen_name.
#!/bin/bash
gameport=7777 #port on which the server will run
adminport=27015 #admin console port
gamefolder=/home/steam #This is the place in your game folder where the ConanSandboxServer.exe is located
serverfolder=$gamefolder/ConanSandbox # This is the name of the server folder
backupfolder=/home/steam/backup #the place where you want your backup to be put
server_ip=X.X.X.X #the IP address on which the game server is bind
screen_name=conan #the name in which the screen will be launched for the server_user
server_user=steam #the user that normally launch your server
if [[ $(sudo iptables -L -v -n | grep $gameport) == "" ]]; then
sudo iptables -A INPUT -p udp --dport $gameport -j ACCEPT
echo "Adding port $gameport to firewall"
fi
if [[ $(sudo iptables -L -v -n | grep $adminport) == "" ]]; then
sudo iptables -A INPUT -p udp --dport $adminport -j ACCEPT
echo "Adding port $adminport to firewall"
fi
su - steam << EOF
mkdir -p $backupfolder
cp -R $serverfolder $backupfolder/backup_$(date +%F_%T)
tar -zcf $backupfolder/backup_$(date +%F_%T).tar.gz $backupfolder/backup_$(date +%F_%T)
rm -Rf $backupfolder/backup_$(date +%F_%T)
find $backupfolder/* -mtime +5 -exec rm {} \;
steamcmd +@sSteamCmdForcePlatformType windows +login anonymous +force_install_dir $gamefolder/ +app_update 443030 +quit
screen -d -mS $screen_name xvfb-run --auto-servernum --server-args='-screen 2 640x480x24:32' wine $gamefolder/ConanSandboxServer.exe -log -Port=$gameport -Multihome=$server_ip
EOF