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