Linux Server with Amazon Linux AMI
Listed below are the steps required to launch a dedicated game server on an Amazon Linux 64bit HVM EC2 instance. They do not cover any basic or general information regarding linux server administration, but they should be pretty straight forward to follow.
Note that Amazon Linux is a RedHat-like distribution, so a similar set of steps can probably be used to get a server running under Fedora, RHEL, CentOS, etc. (though you will have to have appropriate yum repositories configured and some package names may differ).
The code snippets below should all be directly paste-able into a command prompt (hence the bash comment characters and the creation of scripts using echo). There are a couple of files that will need to be edited though. The AMI should come with vim and nano, but if you prefer something else you will have to install it.
Create EC2 instance and connect
How to use Amazon Web Services and EC2 is beyond the scope of this document, but a few notes are given below:
- You will want an instance with more than 6GB of RAM and enough CPU to not get bogged down as the game runs
- You might want to create a second storage volume in which to store SteamCMD and games (leaving the root volume as the standard 8GB)
- At the time of this writing, a c3.xlarge instance gets your 4 vCPUs, 7.5GB of RAM, and built in Enhanced Networking for around $0.21/hour. An rc3.large is cheaper with more RAM but less CPU.
- Make a new security group and add access for the port you want to run the game on PLUS the 2 ports after it (so if you run on 26900, your policy should allow UDP ports 26900-26902)
Bring server up to date
sudo su -l yum update -y
Install prerequisites
# Install SteamCMD pre-reqs yum install -y glibc.i686 libstdc++48.i686 # Install 7 Days to Die pre-reqs yum install -y mesa-libGLU libXcursor libXrandr
Create a location for SteamCMD and Games
mkdir /opt/games # Format and mount game storage drive, if using another volume for storage # Your device name might be something other than /dev/xvdb, so edit the lines # accordingly mkfs.ext4 /dev/xvdb echo "/dev/xvdb /opt/games ext4 defaults,noatime 1 1" >>/etc/fstab mount /opt/games
Create a user to run games as
# Add a steam user and setup the home directory adduser --home /opt/games steam cp /etc/skel/.* /opt/games chown -R steam:steam /opt/games
Install SteamCMD
# Switch to steam user su -l steam # Create SteamCMD directory mkdir ~/steamcmd && cd ~/steamcmd # Download SteamCMD wget 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz' # Unpack SteamCMD tar -xzvf steamcmd_linux.tar.gz && rm -f steamcmd_linux.tar.gz # Launch SteamCMD ./steamcmd.sh # Downloads updates and all that. Once it is done, verify that logging in # works (and enter SteamGuard code if required) login YOURSTEAMUSERNAME YOURSTEAMPASSWORD # Exit interactive session exit
Create a script to install and update 7 Days
# Create a directory for scripts mkdir /opt/games/bin # Create general app installing/updating script # (re-usable for other games) # NOTE: You will either have to edit the YOURSTEAM lines below, or edit # the script afterwards to put the correct username and password in echo '#!/bin/bash' > /opt/games/bin/steamgame_update.sh echo 'APP_ID=$1' >> /opt/games/bin/steamgame_update.sh echo 'APP_DIR=$2' >> /opt/games/bin/steamgame_update.sh echo 'STEAM_USER="YOURSTEAMUSERNAME"' >> /opt/games/bin/steamgame_update.sh echo 'STEAM_PASS="YOURSTEAMPASSWORD"' >> /opt/games/bin/steamgame_update.sh echo '/opt/games/steamcmd.sh +login ${STEAM_USER} ${STEAM_PASS} +force_install_dir ${APP_DIR} +app_update ${APP_ID} +exit' >> /opt/games/bin/steamgame_update.sh # Create 7days installing/updating script echo '#!/bin/bash' > /opt/games/bin/update_7days.sh echo '/opt/games/bin/steamgame_update.sh 294420 /opt/games/7days' >> /opt/games/bin/update_7days.sh # Set script permissions chmod 750 /opt/games/bin/*.sh # Run update script to download and install 7days # (also used whenever you need to update the game) /opt/games/bin/update_7days.sh
Modify server config and launch scripts
Since our EC2 instance is 64 bit, we need to adjust the server launching script. That script should be located here: /opt/games/7days/startserver.sh
Uncomment the x86_64 start line and comment out the x86 start line, so that this:
#if [ "$(uname -m)" == "x86_64" ]; then # ./7DaysToDieServer.x86_64 -logfile 7DaysToDieServer_Data/output_log__`date +%Y-%m-%d__%H-%M-%S`.txt -quit -batchmode -nographics -dedicated $PARAMS #else ./7DaysToDieServer.x86 -logfile 7DaysToDieServer_Data/output_log__`date +%Y-%m-%d__%H-%M-%S`.txt -quit -batchmode -nographics -dedicated $PARAMS #fi
Becomes this:
#if [ "$(uname -m)" == "x86_64" ]; then ./7DaysToDieServer.x86_64 -logfile 7DaysToDieServer_Data/output_log__`date +%Y-%m-%d__%H-%M-%S`.txt -quit -batchmode -nographics -dedicated $PARAMS #else # ./7DaysToDieServer.x86 -logfile 7DaysToDieServer_Data/output_log__`date +%Y-%m-%d__%H-%M-%S`.txt -quit -batchmode -nographics -dedicated $PARAMS #fi
We will also want to set a few settings in the server config file. That file is located here: /opt/games/7days/serverconfig.xml
Things you might want to change right away:
- ServerPort : If you want to run on something other than 26900-26902
- ServerIsPublic : Defaults to true, should control whether you server gets listed or not
- ServerName : Name of your server
- ServerPassword : Password for your server, if you want it locked
- ServerDescription : Description for your server
- TelnetEnabled : Whether you want the console telnet accessible (recommended for use from localhost only!)
- TelnetPassword : Password required when accessing telnet
- SaveGameFolder : Initially commented out, you can use this option to hardcode where save files go. Make sure the director you specify exists
Initial test: can we start the game?
Launch the game and watch the log output
# Start game server /opt/games/7days/startserver.sh -configfile=serverconfig.xml & # Watch the log file (the grep command weeds out some known warnings and blank lines) tail -f /opt/games/7days/7DaysToDieServer_Data/output_log*.txt
There will be some shader errors, downsize warnings, etc... but eventually you should start to see some stats periodically reported. That means the game thinks it is up! Try launching 7 Days on your computer and see if you can connect!
Creating services
Assuming everything is now working, you can turn 7 Days into a service so it is easily started and stopped.
7days service
If the game is still running, you will want to stop it.
# In the terminal you launched the game from, this should do the trick ps | grep 7DaysToDieServe | cut --delimiter=' ' -f 1
Create the file /etc/init.d/7days and make it executable. This requires elevated privileges, so be sure to exit the out of the steam user shell first:
touch /etc/init.d/7days chmod 755 /etc/init.d/7days
Open the file for editing and paste in the following contents:
#!/bin/bash # # chkconfig: - 90 13 # processname: 7days # pidfile: /opt/games/7days/server.pid # ### BEGIN INIT INFO # Provides: 7days # Required-Start: $local_fs $remote_fs $network Xvfb # Required-Stop: $local_fs $remote_fs $network ### END INIT INFO ############## ### CONFIG ### ############## # # This is the section to modify for different install # directories, game user accounts, etc. # # Parent directory for all games GAME_ROOT_DIR='/opt/games' # Name of the game; assumed to match init script name GAME_NAME='7days' # Directory name for this game GAME_DIR_NAME=${GAME_NAME} # User to run the game as GAME_USER='steam' # Name of this game # Binary used to start the game GAME_BIN_NAME='7DaysToDieServer.x86_64' # Derived game dir game_dir="${GAME_ROOT_DIR}/${GAME_DIR_NAME}" # Game command line options game_options="-configfile=${game_dir}/serverconfig.xml -logfile 7DaysToDieServer_Data/output_log__`date +%Y-%m-%d__%H-%M-%S`.txt -quit -batchmode -nographics -dedicated" # PID file location pidfile="${game_dir}/server.pid" # Game binary full path game_bin="${game_dir}/${GAME_BIN_NAME}" ################## ### END CONFIG ### ################## RETVAL=0 # Source function library. . /etc/rc.d/init.d/functions start() { echo -n $"Starting ${GAME_NAME}: " su -l ${GAME_USER} -c "${game_bin} ${game_options} 1>/dev/null 2>&1 & echo \$! >${pidfile}" sleep 1 service ${GAME_NAME} status >/dev/null 2>&1 if [ "$?" = "0" ] then success RETVAL=0 else failure RETVAL=1 fi echo } stop() { echo -n $"Stopping ${GAME_NAME}: " killproc -p ${pidfile} -d 10 ${game_bin} RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) if ! test -f ${pidfile}; then echo ${GAME_NAME} is stopped RETVAL=3 else status -p ${pidfile} ${game_bin} RETVAL=$? fi ;; *) echo $"Usage: ${GAME_NAME} {start|stop|status}" exit 1 esac exit $RETVAL
We can now use the service command to start, stop, or check the status of 7days.
Starting 7Days on boot
We can have the game server start on boot by turning them on with the chkconfig command:
chkconfig 7days on