GS5 - SteamLUG/steamlug-gaming-servers GitHub Wiki

GS5

GS5 is the second US server in the steamlug set, it is OpenRC-based.

There are some assumptions are made in these scripts. First, /home/steam is used as the unprivileged user's home directory. Second, GNU/Screen is used to avoid an endless loop with srcds when disconnecting the underlying terminal that started the daemon. At the time of this writing, only CS:GO and Fistful of Frags dedicated servers are deployed.

Sample CS:GO daemon script

#!/sbin/runscript

depend() {
	need net
}

GAME="csgo"
GAME_LONG="Counter-Strike: GO Dedicated Server"
DAEMON="srcds_run"
DAEMON_OPTS="-game ${GAME} +game_type 0 +game_mode 0 +mapgroup mg_active +map de_dust2 -port 27015"
SHARD="csgods"
PIDFILE=/run/steam/${SHARD}.pid

start_pre() {
	checkpath -o steam -d "$(dirname $PIDFILE)"
}

start() {
	ebegin "Starting ${GAME_LONG}: ${SHARD}"
	start-stop-daemon --start --pidfile ${PIDFILE} --exec su -- steam -c \
	"cd /home/steam/${GAME}; screen -mdS ${SHARD} ./$DAEMON $DAEMON_OPTS"
	ps ax | grep -i SCREEN | grep -i ${SHARD} | awk '{print $1}' > $PIDFILE
	eend $?
}

stop() {
	ebegin "Stopping ${GAME_LONG}: ${SHARD}"
	start-stop-daemon --stop --pidfile ${PIDFILE}
	eend $?
}

update script

#!/bin/bash
APPID="$1"
GAME="$2"
cd "${HOME}/steamcmd"
localbuild=$(grep buildid "${HOME}/${GAME}/steamapps/appmanifest_${APPID}.acf"\
             | tr '"' ' ' | awk '{print $2}')

#way too aggressive fix for old remote buildid
rm "${HOME}/Steam/appcache/appinfo.vdf"

remotebuild=$(./steamcmd.sh +login anonymous +app_info_print "${APPID}" +quit \
              | grep -EA 1000 "^\s+\"branches\"$" | grep -EA 5 \
              "^\s+\"public\"$" | grep -m 1 -EB 10 "^\s+}$" | grep -E \
              "^\s+\"buildid\"\s+" | tr '"' ' ' | awk '{print $2}')
if [ -n "${remotebuild}" ] && [ "${localbuild}" != "${remotebuild}" ]; then
    find /etc/init.d/ -name "${GAME}*ds" -exec sh -c 'screen -S \
      $(basename "{}") -p 0 -X stuff \
      "say Automated server update detected...$(printf \\r)"' \;
    ./steamcmd.sh +login anonymous +force_install_dir ../${GAME} \
    +app_update ${APPID} +quit
    #if buildid does not match after update, then do a validate pass
    localbuild=$(grep buildid \
                 "${HOME}/${GAME}/steamapps/appmanifest_${APPID}.acf" \
                 | tr '"' ' ' | awk '{print $2}')
    if [ "${localbuild}" != "${remotebuild}" ]; then
        echo "[$(date '+%F %T')] ${GAME}: ${localbuild} != ${remotebuild}" \
        >> ${HOME}/update.log
        find /etc/init.d/ -name "${GAME}*ds" -exec sh -c 'screen -S \
          $(basename "{}") -p 0 -X stuff \
          "say Oh No! Something went wrong! Trying harder...$(printf \\r)"' \;
        ./steamcmd.sh +login anonymous +force_install_dir ../${GAME} \
        +app_update ${APPID} validate +quit
    fi
    find /etc/init.d/ -name "${GAME}*ds" -exec sh -c 'screen -S \
      $(basename "{}") -p 0 -X stuff \
      "say Update complete, restarting server.$(printf \\r)"' \;
    touch ${HOME}/restart_${GAME}
fi

The cron job that calls the update script

#!/bin/bash
update ()
{
    su - steam -c "/home/steam/update.sh ${APPID} ${GAME}"
    if [ -f /home/steam/restart_${GAME} ]; then
        #restart all services that start with the game's name and ends with ds
        find /etc/init.d/ -name "${GAME}*ds" -exec '{}' restart \;
        rm /home/steam/restart_${GAME}
    fi
}

APPID="90"
GAME="cstrike"
update

APPID="740"
GAME="csgo"
update

APPID="295230"
GAME="fof"
update

check script to see if the game is up to date

#!/bin/bash
GAME="$1"
case $GAME in
cstrike)
    APPID="90" ;;
csgo)
    APPID="740" ;;
nucleardawn)
    APPID="111710" ;;
fof)
    APPID="295230" ;;
*)
    echo "Specify cstrike, csgo, nucleardawn or fof"
    exit 1 ;;
esac
cd "${HOME}/steamcmd"
localbuild=$(grep buildid "${HOME}/${GAME}/steamapps/appmanifest_${APPID}.acf"\
             | tr '"' ' ' | awk '{print $2}')

#way too aggressive fix for old remote buildid
rm "${HOME}/Steam/appcache/appinfo.vdf"

remotebuild=$(./steamcmd.sh +login anonymous +app_info_print "${APPID}" +quit \
              | grep -EA 1000 "^\s+\"branches\"$" | grep -EA 5 \
              "^\s+\"public\"$" | grep -m 1 -EB 10 "^\s+}$" | grep -E \
              "^\s+\"buildid\"\s+" | tr '"' ' ' | awk '{print $2}')
echo "local:  ${localbuild}"
echo "remote: ${remotebuild}"