Browse Source

major update 050214

* Fixed insserver. Now works on Debian and CentOS
*  Added validate feature now 4 options update, update-restart,
validate, validate-restart
* Improved consistency of error messages thanks to wrelam
* Fixed bug with fn_logmanager
* Added steam_appid.txt file to fix an error where the server would
crash
pull/78/head
Daniel Gibbs 11 years ago
parent
commit
556d101781
  1. 231
      CounterStrike/csserver
  2. 231
      CounterStrikeConditionZero/csczserver
  3. 259
      CounterStrikeGlobalOffensive/csgoserver
  4. 232
      CounterStrikeSource/cssserver
  5. 240
      DayOfDefeat/dodserver
  6. 232
      DayOfDefeatSource/dodsserver
  7. 232
      HalfLife2Deathmatch/hl2dmserver
  8. 235
      HalfLifeDeathmatchClassic/hldmcserver
  9. 244
      Insurgency/insserver
  10. 239
      KillingFloor/kfserver
  11. 234
      Left4Dead2/l4d2server
  12. 236
      NaturalSelection2/ns2server
  13. 231
      NoMoreRoomInHell/nmrihserver
  14. 232
      RedOrchestra/roserver
  15. 234
      TeamFortress2/tf2server
  16. 231
      TeamFortressClassic/tfcserver
  17. 220
      UnrealTournament2004/ut2k4server
  18. 209
      UnrealTournament99/ut99server

231
CounterStrike/csserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -18,13 +18,14 @@ steampass=""
# Start Variables # Start Variables
defaultmap="de_dust2" defaultmap="de_dust2"
maxplayers="16"
port="27015" port="27015"
clientport="27005" clientport="27005"
maxplayers="16"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2
fn_parms(){ fn_parms(){
parms="-game cstrike +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-game cstrike -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -77,16 +78,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -98,7 +143,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -115,20 +160,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -158,11 +211,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -186,21 +239,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -234,17 +287,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -311,10 +364,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -327,10 +380,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -344,23 +397,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -373,15 +427,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -397,10 +451,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -411,24 +465,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -442,10 +496,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -453,12 +508,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -472,18 +547,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -498,14 +573,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -513,13 +588,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -640,8 +715,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -792,8 +867,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -810,7 +893,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

231
CounterStrikeConditionZero/csczserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -18,13 +18,14 @@ steampass=""
# Start Variables # Start Variables
defaultmap="de_dust2" defaultmap="de_dust2"
maxplayers="16"
port="27015" port="27015"
clientport="27005" clientport="27005"
maxplayers="16"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2
fn_parms(){ fn_parms(){
parms="-game czero +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-game czero -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -77,16 +78,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -98,7 +143,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -115,20 +160,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -158,11 +211,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -186,21 +239,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -234,17 +287,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -311,10 +364,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -327,10 +380,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -344,23 +397,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -373,15 +427,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -397,10 +451,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -411,24 +465,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -442,10 +496,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -453,12 +508,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -472,18 +547,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -498,14 +573,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -513,13 +588,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -646,8 +721,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -802,8 +877,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -820,7 +903,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

259
CounterStrikeGlobalOffensive/csgoserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -17,27 +17,33 @@ steamuser="anonymous"
steampass="" steampass=""
# Start Variables # Start Variables
# [Game Modes] game_mode game_type # https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Dedicated_Servers#Starting_the_Server
# [Game Modes] gametype gamemode
# Arms Race 1 0
# Classic Casual 0 0 # Classic Casual 0 0
# Classic Competitive 0 1 # Classic Competitive 0 1
# Arms Race 1 0
# Demolition 1 1 # Demolition 1 1
# Deathmatch 1 2
gamemode="0" gamemode="0"
gametype="0" gametype="0"
defaultmap="de_dust"
mapgroup="random_classic"
maxplayers="16"
defaultmap="de_dust2" defaultmap="de_dust2"
mapgroup="random_classic" mapgroup="random_classic"
maxplayers="16"
tickrate="64"
port="27015" port="27015"
sourcetvport="27020" sourcetvport="27020"
clientport="27005" clientport="27005"
ip="0.0.0.0" ip="0.0.0.0"
# Optional: Workshop Parameters
# https://developer.valvesoftware.com/wiki/CSGO_Workshop_For_Server_Operators
# To get an authkey visit - http://steamcommunity.com/dev/apikey
# authkey=""
# wscollectionid=""
# wsstartmap=""
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
# https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Dedicated_Servers#Starting_the_Server
fn_parms(){ fn_parms(){
parms="-game csgo -usercon +map ${defaultmap} +mapgroup ${mapgroup} +game_mode ${gamemode} +game_type ${gametype} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-game csgo -usercon -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers_override ${maxplayers} +mapgroup ${mapgroup} +game_mode ${gamemode} +game_type ${gametype} +host_workshop_collection ${wh_collection_id} +workshop_start_map ${wh_start_map} -authkey ${authkey}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -90,16 +96,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -111,7 +161,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -128,20 +178,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -150,6 +208,7 @@ fn_debugserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
fn_csgoappidfix
fn_parms fn_parms
echo "" echo ""
echo "${gamename} Debug" echo "${gamename} Debug"
@ -171,11 +230,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -199,21 +258,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -247,17 +306,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -324,10 +383,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -340,10 +399,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -357,23 +416,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -386,15 +446,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -410,10 +470,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -424,24 +484,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -455,10 +515,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -466,12 +527,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -485,18 +566,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -504,6 +585,7 @@ fn_startserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
fn_csgoappidfix
fn_parms fn_parms
fn_logmanager fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
@ -511,14 +593,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -526,13 +608,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -571,6 +653,17 @@ fi
echo "" echo ""
} }
fn_csgoappidfix(){
if [ ! -f "${filesdir}/steam_appid.txt" ]; then
fn_printdots "Applying 730 steam_appid.txt Fix."
sleep 1
fn_printinfo "Applying 730 steam_appid.txt Fix."
sleep 1
echo -en "\n"
echo -n "730" >> ${filesdir}/steam_appid.txt
fi
}
# #
## Installer ## Installer
# #
@ -631,8 +724,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -750,8 +843,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -768,7 +869,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

232
CounterStrikeSource/cssserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -18,14 +18,16 @@ steampass=""
# Start Variables # Start Variables
defaultmap="de_dust2" defaultmap="de_dust2"
maxplayers="16"
tickrate="64"
port="27015" port="27015"
sourcetvport="27020" sourcetvport="27020"
clientport="27005" clientport="27005"
maxplayers="16"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
fn_parms(){ fn_parms(){
parms="-game cstrike +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}" parms="-game cstrike -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -78,16 +80,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -99,7 +145,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -116,20 +162,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -159,11 +213,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -187,21 +241,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -235,17 +289,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -312,10 +366,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -328,10 +382,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -345,23 +399,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -374,15 +429,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -398,10 +453,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -412,24 +467,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -443,10 +498,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -454,12 +510,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -473,18 +549,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -499,14 +575,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -514,13 +590,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -619,8 +695,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -738,8 +814,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -756,7 +840,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

240
DayOfDefeat/dodserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -18,13 +18,14 @@ steampass=""
# Start Variables # Start Variables
defaultmap="dod_Anzio" defaultmap="dod_Anzio"
maxplayers="16"
port="27015" port="27015"
clientport="27005" clientport="27005"
maxplayers="16"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2
fn_parms(){ fn_parms(){
parms="-game dod +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-game dod -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -77,16 +78,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -98,7 +143,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -115,20 +160,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -158,11 +211,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -186,17 +239,17 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
@ -240,11 +293,11 @@ if [ ${tmuxwc} -eq 1 ]; then
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -311,10 +364,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -327,10 +380,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -344,23 +397,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -373,15 +427,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -397,10 +451,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -411,24 +465,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -442,10 +496,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -453,12 +508,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -472,18 +547,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -498,14 +573,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -513,13 +588,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -574,18 +649,18 @@ if [ ${pass} == 1 ]; then
sleep 2 sleep 2
rm -f appmanifest_10.acf appmanifest_70.acf appmanifest_90.acf rm -f appmanifest_10.acf appmanifest_70.acf appmanifest_90.acf
elif [ ${pass} == 2 ]; then elif [ ${pass} == 2 ]; then
echo "Downloading firstpass appmanifest files. (app 90 fix)" echo "Downloading HLDS appmanifest files. (app 90 fix)"
sleep 2 sleep 2
cd "${appdir}" cd "${appdir}"
wget https://raw2.github.com/dgibbs64/linuxgameservers/master/DayOfDefeat/appmanifest/firstpass/appmanifest_10.acf wget https://raw.github.com/dgibbs64/linuxgameservers/master/appmanifest/appmanifest_10.acf
wget https://raw2.github.com/dgibbs64/linuxgameservers/master/DayOfDefeat/appmanifest/firstpass/appmanifest_70.acf wget https://raw.github.com/dgibbs64/linuxgameservers/master/appmanifest/appmanifest_70.acf
wget https://raw2.github.com/dgibbs64/linuxgameservers/master/DayOfDefeat/appmanifest/firstpass/appmanifest_90.acf wget https://raw.github.com/dgibbs64/linuxgameservers/master/appmanifest/appmanifest_90.acf
elif [ ${pass} == 3 ]; then elif [ ${pass} == 3 ]; then
echo "Downloading secondpass appmanifest files. (app 90 fix)" echo "Downloading ${gamename} appmanifest files. (app 90 fix)"
sleep 2 sleep 2
cd "${appdir}" cd "${appdir}"
rm -f appmanifest_90.acf rm -f appmanifest_90.acf
wget https://raw2.github.com/dgibbs64/linuxgameservers/master/DayOfDefeat/appmanifest/secondpass/appmanifest_90.acf wget https://raw2.github.com/dgibbs64/linuxgameservers/master/appmanifest/dod/appmanifest_90.acf
fi fi
} }
@ -646,8 +721,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -711,7 +786,6 @@ while true; do
done done
fn_header fn_header
fn_steamdl fn_steamdl
echo "Installing ${gamename} Server" echo "Installing ${gamename} Server"
echo "=================================" echo "================================="
pass=1 pass=1
@ -803,8 +877,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -821,7 +903,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

232
DayOfDefeatSource/dodsserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -18,14 +18,16 @@ steampass=""
# Start Variables # Start Variables
defaultmap="dod_Anzio" defaultmap="dod_Anzio"
maxplayers="16"
tickrate="64"
port="27015" port="27015"
sourcetvport="27020" sourcetvport="27020"
clientport="27005" clientport="27005"
maxplayers="16"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
fn_parms(){ fn_parms(){
parms="-game dod +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-game dod -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -78,16 +80,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -99,7 +145,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -116,20 +162,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -159,11 +213,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -187,21 +241,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -235,17 +289,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -312,10 +366,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -328,10 +382,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -345,23 +399,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -374,15 +429,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -398,10 +453,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -412,24 +467,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -443,10 +498,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -454,12 +510,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -473,18 +549,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -499,14 +575,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -514,13 +590,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -619,8 +695,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -738,8 +814,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -756,7 +840,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

232
HalfLife2Deathmatch/hl2dmserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -18,14 +18,16 @@ steampass=""
# Start Variables # Start Variables
defaultmap="dm_lockdown" defaultmap="dm_lockdown"
maxplayers="16"
tickrate="64"
port="27015" port="27015"
sourcetvport="27020" sourcetvport="27020"
clientport="27005" clientport="27005"
maxplayers="16"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
fn_parms(){ fn_parms(){
parms="-game hl2mp +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-game hl2mp -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -78,16 +80,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -99,7 +145,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -116,20 +162,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -159,11 +213,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -187,21 +241,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -235,17 +289,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -312,10 +366,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -328,10 +382,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -345,23 +399,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -374,15 +429,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -398,10 +453,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -412,24 +467,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -443,10 +498,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -454,12 +510,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -473,18 +549,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -499,14 +575,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -514,13 +590,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -619,8 +695,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -738,8 +814,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -756,7 +840,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

235
HalfLifeDeathmatchClassic/hldmcserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -18,13 +18,14 @@ steampass=""
# Start Variables # Start Variables
defaultmap="crossfire" defaultmap="crossfire"
maxplayers="16"
port="27015" port="27015"
clientport="27005" clientport="27005"
maxplayers="16"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2
fn_parms(){ fn_parms(){
parms="-game valve +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-game valve -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -52,8 +53,8 @@ backupdir="backups"
steamclient="${rootdir}/steamcmd/linux32/steamclient.so" steamclient="${rootdir}/steamcmd/linux32/steamclient.so"
# Server Details # Server Details
servername=$(grep -s hostname "${servercfg}"|sed 's/hostname //g'|sed 's/"//g') servername=$(grep -s hostname "${servercfgfullpath}"|sed 's/hostname //g'|sed 's/"//g')
rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g') rcon=$(grep -s rcon_password "${servercfgfullpath}"|sed 's/rcon_password //g'|sed 's/"//g')
# Logging # Logging
logdays="7" logdays="7"
@ -77,16 +78,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -98,7 +143,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -115,20 +160,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -158,11 +211,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -186,21 +239,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -234,17 +287,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -311,10 +364,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -327,10 +380,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -344,23 +397,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -373,15 +427,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -397,10 +451,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -411,24 +465,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -442,10 +496,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -453,12 +508,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -472,18 +547,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -498,14 +573,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -513,13 +588,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -640,8 +715,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -792,8 +867,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -810,7 +893,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

244
Insurgency/insserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -18,14 +18,15 @@ steampass="password"
# Start Variables # Start Variables
defaultmap="ministry" defaultmap="ministry"
maxplayers="16"
port="27015" port="27015"
sourcetvport="27020" sourcetvport="27020"
clientport="27005" clientport="27005"
maxplayers="24"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
fn_parms(){ fn_parms(){
parms="+map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -78,16 +79,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -99,7 +144,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -116,20 +161,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -159,11 +212,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -187,21 +240,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -235,17 +288,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -312,10 +365,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -328,10 +381,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -345,23 +398,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -374,15 +428,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -398,10 +452,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -412,24 +466,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -443,10 +497,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -454,12 +509,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -473,18 +548,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -499,14 +574,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -514,13 +589,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -563,6 +638,18 @@ echo ""
## Installer ## Installer
# #
fn_inshdeps(){
echo "Downloading libm.so.6"
echo "================================="
sleep 1
cd "${filesdir}/bin"
wget https://github.com/dgibbs64/linuxgameservers/raw/master/Insurgency/dependencies/libc.so.6
wget https://github.com/dgibbs64/linuxgameservers/raw/master/Insurgency/dependencies/libpthread.so.0
wget https://github.com/dgibbs64/linuxgameservers/raw/master/Insurgency/dependencies/librt.so.1
sleep 1
echo ""
}
fn_header(){ fn_header(){
clear clear
echo "=================================" echo "================================="
@ -619,8 +706,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -687,6 +774,7 @@ fn_steamdl
fn_steaminstall fn_steaminstall
fn_steamfix fn_steamfix
fn_loginstall fn_loginstall
fn_inshdeps
echo "Configuring ${gamename} Server" echo "Configuring ${gamename} Server"
echo "=================================" echo "================================="
sleep 1 sleep 1
@ -738,8 +826,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -756,7 +852,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

239
KillingFloor/kfserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -69,16 +69,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -90,7 +134,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -107,20 +151,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -150,11 +202,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} ${executable} ${parms}
@ -178,21 +230,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -226,17 +278,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -303,10 +355,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -319,10 +371,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -336,23 +388,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -365,15 +418,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -389,10 +442,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -403,24 +456,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -434,10 +487,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -445,12 +499,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -464,18 +538,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -490,14 +564,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -505,13 +579,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -532,14 +606,13 @@ webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=/
echo "" echo ""
echo "${gamename} Server Details" echo "${gamename} Server Details"
echo "============================" echo "============================"
echo ""
echo "Server name: ${servername}" echo "Server name: ${servername}"
echo "Server IP: ${ip}:${gameport}" echo "Server IP: ${ip}:${gameport}"
echo "Config file: ${systemdir}/${ini}" echo "Config file: ${systemdir}/${ini}"
echo "" echo ""
echo "${servername} Ports" echo "${servername} Ports"
echo "=======================" echo "============================"
echo "Ports the server is currently using" echo "Ports the server is currently using."
echo "" echo ""
echo "DIRECTION DESCRIPTION PORT INI VARIABLE" echo "DIRECTION DESCRIPTION PORT INI VARIABLE"
echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" echo "INBOUND Game Port ${gameport} UDP Port=${gameport}"
@ -664,6 +737,17 @@ done
echo "" echo ""
} }
fn_steamfix(){
echo "Applying steamclient.so fix"
echo "================================="
sleep 1
mkdir -pv "${HOME}/.steam"
mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1
echo ""
}
fn_loginstall(){ fn_loginstall(){
echo "Creating log directorys" echo "Creating log directorys"
echo "=================================" echo "================================="
@ -723,6 +807,7 @@ done
fn_header fn_header
fn_steamdl fn_steamdl
fn_steaminstall fn_steaminstall
fn_steamfix
fn_loginstall fn_loginstall
echo "Configuring ${gamename} Server" echo "Configuring ${gamename} Server"
echo "=================================" echo "================================="
@ -775,8 +860,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -795,7 +888,7 @@ case "$1" in
map-compressor) map-compressor)
fn_kfcompressmaps;; fn_kfcompressmaps;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|map-compressor}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|map-compressor}"
exit 1;; exit 1;;
esac esac
exit exit

234
Left4Dead2/l4d2server

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -17,15 +17,17 @@ steamuser="anonymous"
steampass="" steampass=""
# Start Variables # Start Variables
defaultmap="c5m1_waterfront" defaultmap="de_dust2"
maxplayers="8"
tickrate="64"
port="27015" port="27015"
sourcetvport="27020" sourcetvport="27020"
clientport="27005" clientport="27005"
maxplayers="8"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
fn_parms(){ fn_parms(){
parms="-game left4dead2 +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-game left4dead2 -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -78,16 +80,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -99,7 +145,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -116,20 +162,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -159,11 +213,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -187,21 +241,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -235,17 +289,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -312,10 +366,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -328,10 +382,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -345,23 +399,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -374,15 +429,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -398,10 +453,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -412,24 +467,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -443,10 +498,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -454,12 +510,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -473,18 +549,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -499,14 +575,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -514,13 +590,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -619,8 +695,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -738,8 +814,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -756,7 +840,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

236
NaturalSelection2/ns2server

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -72,16 +72,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -93,7 +137,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -110,20 +154,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -153,14 +205,14 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} ${executable} ${parms} -debug
} }
fn_console(){ fn_console(){
@ -181,21 +233,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -229,17 +281,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -306,10 +358,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -322,10 +374,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -339,23 +391,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -368,15 +421,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -392,10 +445,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -406,24 +459,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -437,10 +490,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -448,12 +502,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -467,18 +541,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -493,14 +567,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -508,13 +582,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -529,11 +603,11 @@ echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}" echo "Server IP: ${ip}:${port}"
echo "" echo ""
echo "${servername} Ports" echo "${servername} Ports"
echo "=======================" echo "============================"
echo "Ports the server is currently using" echo "Ports the server is currently using."
echo "" echo ""
echo "DIRECTION DESCRIPTION PORT" echo "DIRECTION DESCRIPTION PORT"
echo "INBOUND Game/RCON Port ${port}" echo "INBOUND Game/RCON port ${port}"
echo "INBOUND Query Port ${queryport}" echo "INBOUND Query Port ${queryport}"
echo "INBOUND WebAdmin ${webadminport}" echo "INBOUND WebAdmin ${webadminport}"
echo "" echo ""
@ -544,7 +618,7 @@ echo "WebAdmin Username: ${webadminuser}"
echo "WebAdmin Password: ${webadminpass}" echo "WebAdmin Password: ${webadminpass}"
echo "" echo ""
echo "You can change various parameters by editing the" echo "You can change various parameters by editing the"
echo "start parameters in ${selfname}" echo "start parameters in ${selfname}."
echo "" echo ""
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
@ -624,8 +698,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -713,8 +787,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -731,7 +813,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

231
NoMoreRoomInHell/nmrihserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -18,14 +18,15 @@ steampass="password"
# Start Variables # Start Variables
defaultmap="nmo_broadway" defaultmap="nmo_broadway"
maxplayers="8"
port="27015" port="27015"
sourcetvport="27020" sourcetvport="27020"
clientport="27005" clientport="27005"
maxplayers="8"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
fn_parms(){ fn_parms(){
parms="+map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -78,16 +79,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -99,7 +144,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -116,20 +161,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -159,11 +212,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -187,21 +240,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -235,17 +288,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -312,10 +365,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -328,10 +381,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -345,23 +398,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -374,15 +428,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -398,10 +452,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -412,24 +466,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -443,10 +497,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -454,12 +509,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -473,18 +548,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -499,14 +574,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -514,13 +589,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -629,8 +704,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -749,8 +824,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -767,7 +850,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

232
RedOrchestra/roserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -65,16 +65,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -86,7 +130,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -103,20 +147,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -146,11 +198,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} ${executable} ${parms}
@ -174,21 +226,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -222,17 +274,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -299,10 +351,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -315,10 +367,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -332,23 +384,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -361,15 +414,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -385,10 +438,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -399,24 +452,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -430,10 +483,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -441,12 +495,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -460,18 +534,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -486,14 +560,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -501,13 +575,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -528,14 +602,13 @@ webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=/
echo "" echo ""
echo "${gamename} Server Details" echo "${gamename} Server Details"
echo "============================" echo "============================"
echo ""
echo "Server name: ${servername}" echo "Server name: ${servername}"
echo "Server IP: ${ip}:${gameport}" echo "Server IP: ${ip}:${gameport}"
echo "Config file: ${systemdir}/${ini}" echo "Config file: ${systemdir}/${ini}"
echo "" echo ""
echo "${servername} Ports" echo "${servername} Ports"
echo "=======================" echo "============================"
echo "Ports the server is currently using" echo "Ports the server is currently using."
echo "" echo ""
echo "DIRECTION DESCRIPTION PORT INI VARIABLE" echo "DIRECTION DESCRIPTION PORT INI VARIABLE"
echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" echo "INBOUND Game Port ${gameport} UDP Port=${gameport}"
@ -664,8 +737,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -730,6 +803,7 @@ done
fn_header fn_header
fn_steamdl fn_steamdl
fn_steaminstall fn_steaminstall
fn_steamfix
fn_loginstall fn_loginstall
echo "Configuring ${gamename} Server" echo "Configuring ${gamename} Server"
echo "=================================" echo "================================="
@ -782,8 +856,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -802,7 +884,7 @@ case "$1" in
map-compressor) map-compressor)
fn_kfcompressmaps;; fn_kfcompressmaps;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|map-compressor}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|map-compressor}"
exit 1;; exit 1;;
esac esac
exit exit

234
TeamFortress2/tf2server

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -17,15 +17,17 @@ steamuser="anonymous"
steampass="" steampass=""
# Start Variables # Start Variables
defaultmap="ctf_2fort" defaultmap="de_dust2"
maxplayers="16"
tickrate="64"
port="27015" port="27015"
sourcetvport="27020" sourcetvport="27020"
clientport="27005" clientport="27005"
maxplayers="16"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
fn_parms(){ fn_parms(){
parms="-game tf +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-game tf -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -78,16 +80,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -99,7 +145,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -116,20 +162,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -159,11 +213,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -187,21 +241,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -235,17 +289,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -312,10 +366,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -328,10 +382,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -345,23 +399,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -374,15 +429,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -398,10 +453,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -412,24 +467,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -443,10 +498,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -454,12 +510,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -473,18 +549,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -499,14 +575,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -514,13 +590,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -619,8 +695,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -738,8 +814,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -756,7 +840,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

231
TeamFortressClassic/tfcserver

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -18,13 +18,14 @@ steampass=""
# Start Variables # Start Variables
defaultmap="dustbowl" defaultmap="dustbowl"
maxplayers="16"
port="27015" port="27015"
clientport="27005" clientport="27005"
maxplayers="16"
ip="0.0.0.0" ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2
fn_parms(){ fn_parms(){
parms="-game tfc +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" parms="-game tfc -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
} }
#### Advanced Variables #### #### Advanced Variables ####
@ -77,16 +78,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -98,7 +143,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -115,20 +160,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -158,11 +211,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} -debug ${executable} ${parms} -debug
@ -186,21 +239,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -234,17 +287,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -311,10 +364,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -327,10 +380,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -344,23 +397,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -373,15 +427,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -397,10 +451,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -411,24 +465,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -442,10 +496,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -453,12 +508,32 @@ fi
fn_updateserver(){ fn_updateserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" fn_printdots "Updating ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" fn_printok "Updating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Updating ${servername}" fn_scriptlog "Updating ${servername}"
cd "${rootdir}" cd "${rootdir}"
cd "steamcmd" cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}"
}
fn_validateserver(){
fn_rootcheck
fn_syscheck
fn_printwarn "Validating may overwrite some customised files."
sleep 1
echo -en "\n"
echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate"
sleep 5
echo -en "\n"
fn_printdots "Validating ${servicename}: ${servername}"
sleep 1
fn_printok "Validating ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Validating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
} }
@ -472,18 +547,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -498,14 +573,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -513,13 +588,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -646,8 +721,8 @@ fn_steamfix(){
echo "Applying steamclient.so fix" echo "Applying steamclient.so fix"
echo "=================================" echo "================================="
sleep 1 sleep 1
mkdir -pv ${HOME}/.steam mkdir -pv "${HOME}/.steam"
mkdir -pv ${HOME}/.steam/sdk32 mkdir -pv "${HOME}/.steam/sdk32"
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1 sleep 1
echo "" echo ""
@ -802,8 +877,16 @@ case "$1" in
restart) restart)
fn_restartserver;; fn_restartserver;;
update) update)
fn_updateserver;;
update-restart)
fn_stopserver fn_stopserver
fn_updateserver fn_updateserver
fn_startserver;;
validate)
fn_validateserver;;
validate-restart)
fn_stopserver
fn_validateserver
fn_startserver;; fn_startserver;;
monitor) monitor)
fn_monitorserver;; fn_monitorserver;;
@ -820,7 +903,7 @@ case "$1" in
install) install)
fn_install;; fn_install;;
*) *)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}"
exit 1;; exit 1;;
esac esac
exit exit

220
UnrealTournament2004/ut2k4server

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -59,16 +59,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -80,7 +124,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -97,20 +141,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -140,15 +192,14 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
if [ `getconf LONG_BIT` = "64" ] if [ `getconf LONG_BIT` = "64" ]; then
then
${executable64} ${parms} ${executable64} ${parms}
else else
${executable} ${parms} ${executable} ${parms}
@ -173,21 +224,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -221,17 +272,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -298,10 +349,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -314,10 +365,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -331,23 +382,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -360,15 +412,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -384,10 +436,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -398,24 +450,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -429,10 +481,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -447,18 +500,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -473,19 +526,18 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
if [ `getconf LONG_BIT` = "64" ] if [ `getconf LONG_BIT` = "64" ]; then
then
tmux new-session -d -s ${servicename} "${executable64} ${parms}|tee -a '${consolelog}'" tmux new-session -d -s ${servicename} "${executable64} ${parms}|tee -a '${consolelog}'"
else else
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'" tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
@ -493,13 +545,13 @@ fi
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -520,14 +572,13 @@ webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=/
echo "" echo ""
echo "${gamename} Server Details" echo "${gamename} Server Details"
echo "============================" echo "============================"
echo ""
echo "Server name: ${servername}" echo "Server name: ${servername}"
echo "Server IP: ${ip}:${gameport}" echo "Server IP: ${ip}:${gameport}"
echo "Config file: ${systemdir}/${ini}" echo "Config file: ${systemdir}/${ini}"
echo "" echo ""
echo "${servername} Ports" echo "${servername} Ports"
echo "=======================" echo "============================"
echo "Ports the server is currently using" echo "Ports the server is currently using."
echo "" echo ""
echo "DIRECTION DESCRIPTION PORT INI VARIABLE" echo "DIRECTION DESCRIPTION PORT INI VARIABLE"
echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" echo "INBOUND Game Port ${gameport} UDP Port=${gameport}"
@ -591,8 +642,7 @@ mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
rm -rfv "${filesdir}/Maps/*.uz2" rm -rfv "${filesdir}/Maps/*.uz2"
cd "${systemdir}" cd "${systemdir}"
for map in `ls "${filesdir}/Maps"`; do for map in `ls "${filesdir}/Maps"`; do
if [ `getconf LONG_BIT` = "64" ] if [ `getconf LONG_BIT` = "64" ]; then
then
./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir ./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir
else else
./ucc-bin compress ../Maps/${map} --nohomedir ./ucc-bin compress ../Maps/${map} --nohomedir
@ -678,7 +728,7 @@ echo ""
echo "Once you have the key enter it below" echo "Once you have the key enter it below"
echo -n "KEY: " echo -n "KEY: "
read CODE read CODE
echo ""\""CDKey"\""="\""${CODE}"\""" > ${systemdir}/cdkey echo ""\""CDKey"\""="\""${CODE}"\""" > "${systemdir}/cdkey"
echo "" echo ""
} }
@ -705,7 +755,7 @@ done
while true; do while true; do
read -p "Remove ut2004-lnxpatch3369-2.tar.bz2? [y/N]" yn read -p "Remove ut2004-lnxpatch3369-2.tar.bz2? [y/N]" yn
case $yn in case $yn in
[Yy]* ) rm -fv ut2004-lnxpatch3369-2.tar.bz2;break;; [Yy]* ) rm -fv ut2004-lnxpatch3369-2.tar.bz2; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -713,7 +763,7 @@ done
while true; do while true; do
read -p "Remove dedicatedserver3339-bonuspack.zip? [y/N]" yn read -p "Remove dedicatedserver3339-bonuspack.zip? [y/N]" yn
case $yn in case $yn in
[Yy]* ) rm -fv dedicatedserver3339-bonuspack.zip;break;; [Yy]* ) rm -fv dedicatedserver3339-bonuspack.zip; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -785,22 +835,22 @@ echo "================================="
sleep 1 sleep 1
echo "Applying WebAdmin ut2003.css fix!" echo "Applying WebAdmin ut2003.css fix!"
echo "http://forums.tripwireinteractive.com/showpost.php?p=585435&postcount=13" echo "http://forums.tripwireinteractive.com/showpost.php?p=585435&postcount=13"
sed -i 's/none}/none;/g' ${filesdir}/Web/ServerAdmin/ut2003.css sed -i 's/none}/none;/g' "${filesdir}/Web/ServerAdmin/ut2003.css"
sed -i 's/underline}/underline;/g' ${filesdir}/Web/ServerAdmin/ut2003.css sed -i 's/underline}/underline;/g' "${filesdir}/Web/ServerAdmin/ut2003.css"
sleep 1 sleep 1
echo "Applying WebAdmin CharSet fix!" echo "Applying WebAdmin CharSet fix!"
echo "http://forums.tripwireinteractive.com/showpost.php?p=442340&postcount=1" echo "http://forums.tripwireinteractive.com/showpost.php?p=442340&postcount=1"
sed -i 's/CharSet="iso-8859-1"/CharSet="utf-8"/g' ${systemdir}/UWeb.int sed -i 's/CharSet="iso-8859-1"/CharSet="utf-8"/g' "${systemdir}/UWeb.int"
sleep 1 sleep 1
echo "Setting WebAdmin username and password" echo "Setting WebAdmin username and password"
sed -i 's/AdminName=/AdminName=admin/g' ${systemdir}/${ini} sed -i 's/AdminName=/AdminName=admin/g' "${systemdir}/${ini}"
sed -i 's/AdminPassword=/AdminPassword=admin/g' ${systemdir}/${ini} sed -i 's/AdminPassword=/AdminPassword=admin/g' "${systemdir}/${ini}"
sleep 1 sleep 1
echo "Enabling WebAdmin" echo "Enabling WebAdmin"
sed -i 's/bEnabled=False/bEnabled=True/g' ${systemdir}/${ini} sed -i 's/bEnabled=False/bEnabled=True/g' "${systemdir}/${ini}"
sleep 1 sleep 1
echo "Setting WebAdmin port to 8077" echo "Setting WebAdmin port to 8077"
sed -i 's/ListenPort=80/ListenPort=8077/g' ${systemdir}/${ini} sed -i 's/ListenPort=80/ListenPort=8077/g' "${systemdir}/${ini}"
sleep 1 sleep 1
echo "Forcing server to start to get ports/server name to display correctly" echo "Forcing server to start to get ports/server name to display correctly"
sleep 1 sleep 1

209
UnrealTournament99/ut99server

@ -3,7 +3,7 @@
# Server Management Script # Server Management Script
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 010214 # Version: 050214
#### Variables #### #### Variables ####
@ -58,16 +58,60 @@ fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
} }
# [ FAIL ]
fn_printfail(){
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printfailnl(){
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
}
fn_printok(){
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
# [ OK ]
fn_printoknl(){
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
}
fn_printinfo(){
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
# [ INFO ]
fn_printokinfonl(){
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
}
fn_printwarn(){
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
fn_printwarnnl(){
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
}
# [ .... ]
fn_printdots(){
echo -en "\r\033[K[ .... ] $@"
}
fn_rootcheck(){ fn_rootcheck(){
if [ `whoami` = "root" ]; then if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" fn_printfailnl "Script will not run as root!"
exit exit
fi fi
} }
fn_syscheck(){ fn_syscheck(){
if [ ! -e "${systemdir}" ]; then if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" fn_printfailnl "Cannot access ${systemdir}: No such directory"
exit exit
fi fi
} }
@ -79,7 +123,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l)
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
if [ "${getipwc}" -ge "2" ]; then if [ "${getipwc}" -ge "2" ]; then
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" fn_printwarn "Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n" echo -en "${getip}\n"
@ -96,20 +140,28 @@ if [ ! -e "${consolelog}" ]; then
fi fi
# log manager will active if finds logs older than ${logdays} # log manager will active if finds logs older than ${logdays}
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_printdots "Starting log cleaner"
sleep 1
fn_printok "Starting log cleaner"
sleep 1
fn_scriptlog "Starting log cleaner" fn_scriptlog "Starting log cleaner"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -en "\n"
fn_printinfo "Removing logs older than ${logdays} days"
sleep 1
echo -en "\n"
fn_scriptlog "Removing logs older than ${logdays} days" fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1 sleep 1
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" fn_printok "Log cleaner removed ${count} log files"
sleep 1
echo -en "\n"
fn_scriptlog "Log cleaner removed ${count} log files" fn_scriptlog "Log cleaner removed ${count} log files"
fi fi
} }
@ -139,11 +191,11 @@ while true; do
esac esac
done done
fn_stopserver fn_stopserver
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" fn_printdots "Starting debug mode ${servicename}: ${servername}"
sleep 0.5 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" fn_printok "Starting debug mode ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Started debug mode ${servername}" fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n" echo -en "\n"
cd "${executabledir}" cd "${executabledir}"
${executable} ${parms} ${executable} ${parms}
@ -167,21 +219,21 @@ while true; do
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
echo -en "\r\033[K[ .... ] Starting ${servicename} console" fn_printdots "Starting ${servicename} console"
sleep 0.5 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" fn_printoknl "Starting ${servicename} console"
fn_scriptlog "Console accessed"
sleep 1 sleep 1
fn_scriptlog "Console accessed"
tmux attach-session -t ${servicename} tmux attach-session -t ${servicename}
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" fn_printfailnl "Starting ${servicename} console: ${servername} not running"
sleep 0.5 sleep 1
while true; do while true; do
read -p "Do you want to start the server? [y/N]" yn read -p "Do you want to start the server? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_startserver;break;; [Yy]* ) fn_startserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -215,17 +267,17 @@ if [ ${tmuxwc} -eq 1 ]; then
while true; do while true; do
read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn
case $yn in case $yn in
[Yy]* ) fn_stopserver;break;; [Yy]* ) fn_stopserver; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
fi fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" fn_printdots "Starting backup ${servicename}: ${servername}"
sleep 1 sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" fn_printok "Starting backup ${servicename}: ${servername}"
fn_scriptlog "Backup started"
sleep 1 sleep 1
fn_scriptlog "Backup started"
echo -en "\n" echo -en "\n"
cd "${rootdir}" cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1 mkdir -pv "${backupdir}" > /dev/null 2>&1
@ -292,10 +344,10 @@ if [ ! -z "${gamelogdir}" ]; then
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi fi
mail -s "${subject}" ${email} < "${emaillog}" mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" fn_printinfo "Sent email notification to ${email}"
fn_scriptlog "Sent email notification to ${email}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Sent email notification to ${email}"
} }
fn_emailtest(){ fn_emailtest(){
@ -308,10 +360,10 @@ if [ "${emailnotification}" = "on" ]; then
actiontaken="Sent test email...hello is this thing on?" actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification fn_emailnotification
else else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" fn_printfailnl "Email notification not enabled"
fn_scriptlog "Email notification not enabled" fn_scriptlog "Email notification not enabled"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -325,23 +377,24 @@ if [ -f gsquery.py ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
port=$((${port} + 1)) port=$((${port} + 1))
fi fi
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
sleep 1
fn_scriptlog "Detected gsquery.py" fn_scriptlog "Detected gsquery.py"
sleep 1 fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$? exitcode=$?
sleep 1
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
if [[ -z "${secondquery}" ]]; then if [[ -z "${secondquery}" ]]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
sleep 1
fn_scriptlog "Waiting 30 seconds to re-query" fn_scriptlog "Waiting 30 seconds to re-query"
sleep 30 sleep 29
secondquery=1 secondquery=1
fn_serverquery fn_serverquery
fi fi
@ -354,15 +407,15 @@ if [ -f gsquery.py ]; then
fn_restartserver fn_restartserver
exit exit
elif [ "${exitcode}" == "0" ]; then elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: OK" fn_scriptlog "Querying port: ${ip}:${port}: OK"
sleep 1
echo -en "\n" echo -en "\n"
exit exit
elif [ "${exitcode}" == "126" ]; then elif [ "${exitcode}" == "126" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied"
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1 sleep 1
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
echo -en "\n" echo -en "\n"
echo "Attempting to resolve automatically" echo "Attempting to resolve automatically"
chmod +x -v gsquery.py chmod +x -v gsquery.py
@ -378,10 +431,10 @@ if [ -f gsquery.py ]; then
exit exit
fi fi
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
./gsquery.py -a ${ip} -p ${port} -e ${engine} ./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit exit
fi fi
@ -392,24 +445,24 @@ fn_monitorserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
fn_autoip fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" fn_printdots "Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1 sleep 1
fn_scriptlog "Monitoring ${servername}"
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" = "0" ]; then if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" fn_printdots "Monitoring ${servicename}: Checking session: CHECKING"
sleep 1
fn_scriptlog "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" fn_printok "Monitoring ${servicename}: Checking session: OK"
fn_scriptlog "Checking session: OK" sleep 1
sleep 1
echo -en "\n" echo -en "\n"
fn_scriptlog "Checking session: OK"
fn_serverquery fn_serverquery
exit exit
else else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" fn_printfail "Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL" fn_scriptlog "Checking session: FAIL"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
@ -423,10 +476,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_startserver fn_startserver
fi fi
else else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
fn_scriptlog "Detected SteamCMD is checking for updates"
sleep 1 sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" fn_scriptlog "Detected SteamCMD is checking for updates"
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
sleep 1
fn_scriptlog "When updates complete ${servicename} will start" fn_scriptlog "When updates complete ${servicename} will start"
fi fi
} }
@ -441,18 +495,18 @@ fn_stopserver(){
fn_rootcheck fn_rootcheck
fn_syscheck fn_syscheck
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" fn_printdots "Stopping ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Stopping ${servername}" fn_scriptlog "Stopping ${servername}"
sleep 0.5
if [ "${pid}" == "0" ]; then if [ "${pid}" == "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
fn_scriptlog "${servername} is already stopped" fn_scriptlog "${servername} is already stopped"
else else
tmux kill-session -t ${servicename} tmux kill-session -t ${servicename}
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" fn_printok "Stopping ${servicename}: ${servername}"
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -467,14 +521,14 @@ if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}" mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}" mv "${consolelog}" "${consolelogdate}"
fi fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" fn_printdots "Starting ${servicename}: ${servername}"
sleep 1
fn_scriptlog "Starting ${servername}" fn_scriptlog "Starting ${servername}"
sleep 0.5
if [ ${tmuxwc} -eq 1 ]; then if [ ${tmuxwc} -eq 1 ]; then
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" fn_printinfo "Starting ${servicename}: ${servername} is already running"
fn_scriptlog "${servername} is already running" sleep 1
sleep 0.5
echo -en "\n" echo -en "\n"
fn_scriptlog "${servername} is already running"
exit exit
fi fi
cd "${executabledir}" cd "${executabledir}"
@ -482,13 +536,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel
sleep 1 sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then if [ ${tmuxwc} -eq 0 ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" fn_printfail "Starting ${servicename}: Failed to start ${servername}"
fn_scriptlog "failed to start ${servername}" fn_scriptlog "failed to start ${servername}"
else else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" fn_printok "Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}" fn_scriptlog "Started ${servername}"
fi fi
sleep 0.5 sleep 1
echo -en "\n" echo -en "\n"
} }
@ -509,14 +563,13 @@ webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=/
echo "" echo ""
echo "${gamename} Server Details" echo "${gamename} Server Details"
echo "============================" echo "============================"
echo ""
echo "Server name: ${servername}" echo "Server name: ${servername}"
echo "Server IP: ${ip}:${gameport}" echo "Server IP: ${ip}:${gameport}"
echo "Config file: ${systemdir}/${ini}" echo "Config file: ${systemdir}/${ini}"
echo "" echo ""
echo "${servername} Ports" echo "${servername} Ports"
echo "=======================" echo "============================"
echo "Ports the server is currently using" echo "Ports the server is currently using."
echo "" echo ""
echo "DIRECTION DESCRIPTION PORT INI VARIABLE" echo "DIRECTION DESCRIPTION PORT INI VARIABLE"
echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" echo "INBOUND Game Port ${gameport} UDP Port=${gameport}"
@ -614,7 +667,7 @@ fi
echo "Running MD5 checksum to verify the file" echo "Running MD5 checksum to verify the file"
sleep 1 sleep 1
echo "MD5 checksum: 10cd7353aa9d758a075c600a6dd193fd" echo "MD5 checksum: 10cd7353aa9d758a075c600a6dd193fd"
md5check=$(md5sum ut-server-436.tar.gz| awk '{print $1;}') md5check=$(md5sum ut-server-436.tar.gz|awk '{print $1;}')
echo "File returned: ${md5check}" echo "File returned: ${md5check}"
if [ "${md5check}" != "10cd7353aa9d758a075c600a6dd193fd" ]; then if [ "${md5check}" != "10cd7353aa9d758a075c600a6dd193fd" ]; then
echo "MD5 checksum: FAILED!" echo "MD5 checksum: FAILED!"
@ -635,7 +688,7 @@ fi
echo "Running MD5 checksum to verify the file" echo "Running MD5 checksum to verify the file"
sleep 1 sleep 1
echo "MD5 checksum: 77a735a78b1eb819042338859900b83b" echo "MD5 checksum: 77a735a78b1eb819042338859900b83b"
md5check=$(md5sum UTPGPatch451.tar.bz2| awk '{print $1;}') md5check=$(md5sum UTPGPatch451.tar.bz2|awk '{print $1;}')
echo "File returned: ${md5check}" echo "File returned: ${md5check}"
if [ "${md5check}" != "77a735a78b1eb819042338859900b83b" ]; then if [ "${md5check}" != "77a735a78b1eb819042338859900b83b" ]; then
echo "MD5 checksum: FAILED!" echo "MD5 checksum: FAILED!"
@ -675,7 +728,7 @@ done
while true; do while true; do
read -p "Remove ut-server-436.tar.gz? [y/N]" yn read -p "Remove ut-server-436.tar.gz? [y/N]" yn
case $yn in case $yn in
[Yy]* ) rm -fv ut-server-436.tar.gz;break;; [Yy]* ) rm -fv ut-server-436.tar.gz; break;;
[Nn]* ) break;; [Nn]* ) break;;
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
@ -750,7 +803,7 @@ echo "Configuring ${gamename} Server"
echo "=================================" echo "================================="
sleep 1 sleep 1
echo "Copying "${defaultcfg}" to ${systemdir}/${ini}" echo "Copying "${defaultcfg}" to ${systemdir}/${ini}"
tr -d '\r' < "${defaultcfg}" > ${systemdir}/${ini} tr -d '\r' < "${defaultcfg}" > "${systemdir}/${ini}"
sleep 1 sleep 1
echo "Enabling UdpServerUplink" echo "Enabling UdpServerUplink"
{ {
@ -760,19 +813,19 @@ echo "================================="
echo "MasterServerAddress=unreal.epicgames.com" echo "MasterServerAddress=unreal.epicgames.com"
echo "MasterServerPort=27900" echo "MasterServerPort=27900"
echo "Region=0" echo "Region=0"
}|tee -a ${systemdir}/${ini} > /dev/null 2>&1 }|tee -a "${systemdir}/${ini}" > /dev/null 2>&1
sleep 1 sleep 1
echo "Removing dead mplayer.com master server" echo "Removing dead mplayer.com master server"
sed -i '/master.mplayer.com/d' ${systemdir}/${ini} sed -i '/master.mplayer.com/d' "${systemdir}/${ini}"
sleep 1 sleep 1
echo "Inserting qtracker.com master server" echo "Inserting qtracker.com master server"
sed -i '66i\ServerActors=IpServer.UdpServerUplink MasterServerAddress=master.qtracker.com MasterServerPort=27900' ${systemdir}/${ini} sed -i '66i\ServerActors=IpServer.UdpServerUplink MasterServerAddress=master.qtracker.com MasterServerPort=27900' "${systemdir}/${ini}"
sleep 1 sleep 1
echo "Enabling WebAdmin" echo "Enabling WebAdmin"
sed -i 's/bEnabled=False/bEnabled=True/g' ${systemdir}/${ini} sed -i 's/bEnabled=False/bEnabled=True/g' "${systemdir}/${ini}"
sleep 1 sleep 1
echo "Setting WebAdmin port to 8076" echo "Setting WebAdmin port to 8076"
sed -i '467i\ListenPort=8076' ${systemdir}/${ini} sed -i '467i\ListenPort=8076' "${systemdir}/${ini}"
sleep 1 sleep 1
fn_header fn_header

Loading…
Cancel
Save