(→Create a script to install and update 7 Days:
updated app id to use server app id instead of client app id. Resolves some new bugs when launching.) |
No edit summary |
||
Line 36: | Line 36: | ||
# Install 7 Days to Die pre-reqs |
# Install 7 Days to Die pre-reqs |
||
yum install -y mesa-libGLU libXcursor libXrandr |
yum install -y mesa-libGLU libXcursor libXrandr |
||
− | |||
− | # Install virtual frame buffer |
||
− | # NOTE: This is needed if you will be running in graphic mode |
||
− | # (required as of this writing due to issues running with -no-graphic under |
||
− | # linux) |
||
− | yum install -y xorg-x11-server-Xvfb |
||
− | </pre> |
||
=== Create a location for SteamCMD and Games === |
=== Create a location for SteamCMD and Games === |
||
Line 124: | Line 117: | ||
<pre style="overflow: auto;"> |
<pre style="overflow: auto;"> |
||
#if [ "$(uname -m)" == "x86_64" ]; then |
#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 |
#else |
||
− | ./ |
+ | ./7DaysToDieServer.x86 -logfile 7DaysToDieServer_Data/output_log__`date +%Y-%m-%d__%H-%M-%S`.txt -quit -batchmode -nographics -dedicated $PARAMS |
#fi |
#fi |
||
</pre> |
</pre> |
||
Line 133: | Line 126: | ||
<pre style="overflow: auto;"> |
<pre style="overflow: auto;"> |
||
#if [ "$(uname -m)" == "x86_64" ]; then |
#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 |
#else |
||
− | # ./ |
+ | # ./7DaysToDieServer.x86 -logfile 7DaysToDieServer_Data/output_log__`date +%Y-%m-%d__%H-%M-%S`.txt -quit -batchmode -nographics -dedicated $PARAMS |
#fi |
#fi |
||
</pre> |
</pre> |
||
Line 153: | Line 146: | ||
=== Initial test: can we start the game? === |
=== Initial test: can we start the game? === |
||
+ | Launch the game and watch the log output |
||
− | In one terminal, start up Xvfb to be our "fake" graphical display |
||
− | <pre style="overflow: auto;"> |
||
− | Xvfb :99 -screen 0 640x480x16 |
||
− | </pre> |
||
− | |||
− | In a '''second''' terminal (start another SSH connection), launch the game and watch the log output |
||
<pre style="overflow: auto;"> |
<pre style="overflow: auto;"> |
||
# Start game server |
# 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) |
# Watch the log file (the grep command weeds out some known warnings and blank lines) |
||
− | tail -f /opt/games/7days/7DaysToDie_Data/output_log.txt |
+ | tail -f /opt/games/7days/7DaysToDie_Data/output_log.txt |
</pre> |
</pre> |
||
Line 170: | Line 158: | ||
=== Creating services === |
=== Creating services === |
||
− | Assuming everything is now working, you can turn |
+ | 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. |
||
− | Create the file '''/etc/init.d/Xvfb''' and make it executable: |
||
<pre style="overflow: auto;"> |
<pre style="overflow: auto;"> |
||
+ | # In the terminal you launched the game from, this should do the trick |
||
− | touch /etc/init.d/Xvfb |
||
+ | ps | grep 7DaysToDieServe | cut --delimiter=' ' -f 1 |
||
− | chmod 755 /etc/init.d/Xvfb |
||
</pre> |
</pre> |
||
⚫ | |||
− | Open the file and paste in the following contents: |
||
− | <pre style="overflow: auto;"> |
||
− | #!/bin/bash |
||
− | # |
||
− | # chkconfig: 345 85 15 |
||
− | # processname: xvfb |
||
− | # pidfile: /opt/games/xvfb.pid |
||
− | # |
||
− | ### BEGIN INIT INFO |
||
− | # Provides: Xvfb |
||
− | ### END INIT INFO |
||
− | |||
− | NAME='Xvfb' |
||
− | BIN='/usr/bin/Xvfb' |
||
− | |||
− | ############## |
||
− | ### CONFIG ### |
||
− | ############## |
||
− | # |
||
− | # This is the section to modify for different display |
||
− | # number, resolution, screen settings, etc. |
||
− | # |
||
− | USER='steam' |
||
− | DISPLAY_NUM='99' |
||
− | SCREEN_NUM='0' |
||
− | RESOLUTION='800x600x16' |
||
− | |||
− | BASE_DIR='/opt/games' |
||
− | LOG_NAME='xvfb.log' |
||
− | |||
− | # PID file location |
||
− | pidfile="${BASE_DIR}/xvfb.pid" |
||
− | # Log file location |
||
− | logfile="${BASE_DIR}/${LOG_NAME}" |
||
− | |||
− | options=":${DISPLAY_NUM} -screen ${SCREEN_NUM} ${RESOLUTION}" |
||
− | ################## |
||
− | ### END CONFIG ### |
||
− | ################## |
||
− | |||
− | RETVAL=0 |
||
− | |||
− | # Source function library. |
||
− | . /etc/rc.d/init.d/functions |
||
− | |||
− | start() { |
||
− | echo -n $"Starting ${NAME}: " |
||
⚫ | |||
⚫ | |||
− | service Xvfb status >/dev/null 2>&1 |
||
⚫ | |||
− | then |
||
− | success |
||
− | RETVAL=0 |
||
− | else |
||
− | failure |
||
− | RETVAL=1 |
||
− | fi |
||
− | echo |
||
− | } |
||
− | stop() { |
||
− | echo -n $"Stopping ${NAME}: " |
||
− | killproc -p ${pidfile} -d 10 ${BIN} |
||
− | RETVAL=$? |
||
− | echo |
||
− | } |
||
− | |||
− | # See how we were called. |
||
− | case "$1" in |
||
− | start) |
||
− | start |
||
− | ;; |
||
− | stop) |
||
− | stop |
||
− | ;; |
||
− | status) |
||
− | if ! test -f ${pidfile}; then |
||
− | echo ${NAME} is stopped |
||
− | RETVAL=3 |
||
− | else |
||
− | status -p ${pidfile} ${BIN} |
||
− | RETVAL=$? |
||
− | fi |
||
− | ;; |
||
− | *) |
||
− | echo $"Usage: ${NAME} {start|stop|status}" |
||
− | exit 1 |
||
− | esac |
||
− | |||
− | exit $RETVAL |
||
− | </pre> |
||
− | |||
− | We can now use the '''service''' command to start, stop, or check the status of Xvfb. |
||
− | |||
− | ==== 7days service ==== |
||
⚫ | |||
<pre style="overflow: auto;"> |
<pre style="overflow: auto;"> |
||
touch /etc/init.d/7days |
touch /etc/init.d/7days |
||
Line 280: | Line 173: | ||
</pre> |
</pre> |
||
− | Open the file and paste in the following contents: |
+ | Open the file for editing and paste in the following contents: |
<pre style="overflow: auto;"> |
<pre style="overflow: auto;"> |
||
#!/bin/bash |
#!/bin/bash |
||
Line 312: | Line 205: | ||
# Name of this game |
# Name of this game |
||
# Binary used to start the game |
# Binary used to start the game |
||
− | GAME_BIN_NAME=' |
+ | GAME_BIN_NAME='startserver.sh' |
− | # Display Xvfb is on |
||
− | GAME_DISPLAY=':99.0' |
||
# Derived game dir |
# Derived game dir |
||
game_dir="${GAME_ROOT_DIR}/${GAME_DIR_NAME}" |
game_dir="${GAME_ROOT_DIR}/${GAME_DIR_NAME}" |
||
# Game command line options |
# Game command line options |
||
− | game_options=" |
+ | game_options="-configfile=${game_dir}/serverconfig.xml" |
# PID file location |
# PID file location |
||
pidfile="${game_dir}/server.pid" |
pidfile="${game_dir}/server.pid" |
||
Line 337: | Line 228: | ||
echo -n $"Starting ${GAME_NAME}: " |
echo -n $"Starting ${GAME_NAME}: " |
||
⚫ | |||
− | # Ensure Xvfb is already running |
||
− | + | sleep 1 |
|
− | + | service ${GAME_NAME} status >/dev/null 2>&1 |
|
⚫ | |||
then |
then |
||
− | + | success |
|
− | + | RETVAL=0 |
|
⚫ | |||
failure |
failure |
||
RETVAL=1 |
RETVAL=1 |
||
− | else |
||
− | #daemon --pidfile=${pidfile} ${game_bin} ${game_options} |
||
− | su -l ${GAME_USER} -c "DISPLAY=${GAME_DISPLAY} ${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 |
||
fi |
fi |
||
echo |
echo |
||
Line 393: | Line 273: | ||
</pre> |
</pre> |
||
− | We can now use the '''service''' command to start, stop, or check the status of 7days |
+ | We can now use the '''service''' command to start, stop, or check the status of 7days. |
− | ==== Starting |
+ | ==== Starting 7Days on boot ==== |
− | We can have |
+ | We can have the game server start on boot by turning them on with the chkconfig command: |
<pre style="overflow: auto;"> |
<pre style="overflow: auto;"> |
||
− | # Start Xvfb on boot |
||
− | chkconfig Xvfb on |
||
− | # Start 7days on boot |
||
chkconfig 7days on |
chkconfig 7days on |
||
</pre> |
</pre> |
Revision as of 18:12, 13 December 2015
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 === <pre style="overflow: auto;"> 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 'http://media.steampowered.com/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/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/7DaysToDie_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='startserver.sh' # Derived game dir game_dir="${GAME_ROOT_DIR}/${GAME_DIR_NAME}" # Game command line options game_options="-configfile=${game_dir}/serverconfig.xml" # 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