diff --git a/CounterStrike/csserver b/CounterStrike/csserver index 8a485bad3..fe41e6293 100644 --- a/CounterStrike/csserver +++ b/CounterStrike/csserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -17,7 +17,9 @@ defaultmap="de_aztec" port="27015" clientport="27005" maxplayers="16" -parms="-game cstrike +map ${defaultmap} -strictportbind -port ${port} +clientport ${clientport} -maxplayers ${maxplayers}" +ip="0.0.0.0" +# https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 +parms="-game cstrike +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers}" #### Advanced Variables #### @@ -59,41 +61,49 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${filesdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" +if [ ! -e ${filesdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} + fi fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -109,6 +119,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -121,16 +132,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${filesdir} @@ -151,20 +161,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -198,7 +208,7 @@ while true; do esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -209,49 +219,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') -rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT" -echo "INBOUND Game/Rcon Port ${port}" -if [ "${engine}" = "source" ];then - echo "INBOUND SourceTV Port ${sourcetvport}" -fi -echo "OUTBOUND Client Port ${clientport}" -echo "" -echo "You can change ports by editing the" -echo "start parameters in ${selfname}" -echo "" -echo "${servername} Details" -echo "=======================" -echo "Server name: ${servername}" -echo "Rcon Password: ${rcon}" -echo "" -echo "Config file:" -echo "${servercfg}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -285,48 +263,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -334,27 +314,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -362,39 +382,52 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} cd ${rootdir} cd steamcmd @@ -411,15 +444,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -429,28 +462,69 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${filesdir} tmux new-session -d -s ${servicename} "./hlds_run ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_details(){ +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') +rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT" +echo "INBOUND Game/Rcon Port ${port}" +if [ "${engine}" = "source" ]; then + echo "INBOUND SourceTV Port ${sourcetvport}" +fi +echo "OUTBOUND Client Port ${clientport}" +echo "" +echo "You can change ports by editing the" +echo "start parameters in ${selfname}" +echo "" +echo "${servername} Details" +echo "=======================" +echo "Server name: ${servername}" +echo "Rcon Password: ${rcon}" +echo "" +echo "Config file:" +echo "${servercfg}" +echo "" +} + # ## Installer # @@ -472,7 +546,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -487,7 +561,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -496,7 +570,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${filesdir} ];then +if [ -d ${filesdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -504,7 +578,7 @@ if [ -d ${filesdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -517,7 +591,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -678,4 +752,4 @@ case "$1" in echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac -exit +exit \ No newline at end of file diff --git a/CounterStrikeGlobalOffensive/csgoserver b/CounterStrikeGlobalOffensive/csgoserver index ecdf44373..233697335 100644 --- a/CounterStrikeGlobalOffensive/csgoserver +++ b/CounterStrikeGlobalOffensive/csgoserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -18,7 +18,9 @@ port="27015" sourcetvport="27020" clientport="27005" maxplayers="16" -parms="-game csgo +map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" +ip="0.0.0.0" +# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server +parms="-game csgo +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" #### Advanced Variables #### @@ -60,41 +62,49 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${filesdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" +if [ ! -e ${filesdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} + fi fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -110,6 +120,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -122,16 +133,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${filesdir} @@ -152,20 +162,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -199,7 +209,7 @@ while true; do esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -210,49 +220,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') -rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT" -echo "INBOUND Game/Rcon Port ${port}" -if [ "${engine}" = "source" ];then - echo "INBOUND SourceTV Port ${sourcetvport}" -fi -echo "OUTBOUND Client Port ${clientport}" -echo "" -echo "You can change ports by editing the" -echo "start parameters in ${selfname}" -echo "" -echo "${servername} Details" -echo "=======================" -echo "Server name: ${servername}" -echo "Rcon Password: ${rcon}" -echo "" -echo "Config file:" -echo "${servercfg}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -286,48 +264,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -335,27 +315,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -363,39 +383,52 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} cd ${rootdir} cd steamcmd @@ -412,15 +445,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -430,28 +463,69 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${filesdir} tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_details(){ +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') +rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT" +echo "INBOUND Game/Rcon Port ${port}" +if [ "${engine}" = "source" ]; then + echo "INBOUND SourceTV Port ${sourcetvport}" +fi +echo "OUTBOUND Client Port ${clientport}" +echo "" +echo "You can change ports by editing the" +echo "start parameters in ${selfname}" +echo "" +echo "${servername} Details" +echo "=======================" +echo "Server name: ${servername}" +echo "Rcon Password: ${rcon}" +echo "" +echo "Config file:" +echo "${servercfg}" +echo "" +} + # ## Installer # @@ -473,7 +547,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -488,7 +562,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -497,7 +571,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${filesdir} ];then +if [ -d ${filesdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -505,7 +579,7 @@ if [ -d ${filesdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -518,7 +592,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -543,7 +617,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done diff --git a/CounterStrikeSource/cssserver b/CounterStrikeSource/cssserver index 5a801f0aa..772070713 100644 --- a/CounterStrikeSource/cssserver +++ b/CounterStrikeSource/cssserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -18,7 +18,9 @@ port="27015" sourcetvport="27020" clientport="27005" maxplayers="16" -parms="-game cstrike +map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" +ip="0.0.0.0" +# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server +parms="-game cstrike +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" #### Advanced Variables #### @@ -60,41 +62,49 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${filesdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" +if [ ! -e ${filesdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} + fi fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -110,6 +120,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -122,16 +133,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${filesdir} @@ -152,20 +162,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -194,12 +204,12 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -210,49 +220,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') -rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT" -echo "INBOUND Game/Rcon Port ${port}" -if [ "${engine}" = "source" ];then - echo "INBOUND SourceTV Port ${sourcetvport}" -fi -echo "OUTBOUND Client Port ${clientport}" -echo "" -echo "You can change ports by editing the" -echo "start parameters in ${selfname}" -echo "" -echo "${servername} Details" -echo "=======================" -echo "Server name: ${servername}" -echo "Rcon Password: ${rcon}" -echo "" -echo "Config file:" -echo "${servercfg}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -286,48 +264,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -335,27 +315,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -363,39 +383,52 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} cd ${rootdir} cd steamcmd @@ -412,15 +445,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -430,28 +463,69 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${filesdir} tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_details(){ +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') +rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT" +echo "INBOUND Game/Rcon Port ${port}" +if [ "${engine}" = "source" ]; then + echo "INBOUND SourceTV Port ${sourcetvport}" +fi +echo "OUTBOUND Client Port ${clientport}" +echo "" +echo "You can change ports by editing the" +echo "start parameters in ${selfname}" +echo "" +echo "${servername} Details" +echo "=======================" +echo "Server name: ${servername}" +echo "Rcon Password: ${rcon}" +echo "" +echo "Config file:" +echo "${servercfg}" +echo "" +} + # ## Installer # @@ -473,7 +547,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -488,7 +562,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -497,7 +571,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${filesdir} ];then +if [ -d ${filesdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -505,7 +579,7 @@ if [ -d ${filesdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -518,7 +592,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -543,7 +617,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done diff --git a/DayOfDefeatSource/dodsserver b/DayOfDefeatSource/dodsserver index 843ab546f..de3f3c0e9 100644 --- a/DayOfDefeatSource/dodsserver +++ b/DayOfDefeatSource/dodsserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -18,7 +18,9 @@ port="27015" sourcetvport="27020" clientport="27005" maxplayers="16" -parms="-game dod +map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" +ip="0.0.0.0" +# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server +parms="-game dod +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" #### Advanced Variables #### @@ -60,41 +62,49 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${filesdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" +if [ ! -e ${filesdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} + fi fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -110,6 +120,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -122,16 +133,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${filesdir} @@ -152,20 +162,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -199,7 +209,7 @@ while true; do esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -210,49 +220,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') -rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT" -echo "INBOUND Game/Rcon Port ${port}" -if [ "${engine}" = "source" ];then - echo "INBOUND SourceTV Port ${sourcetvport}" -fi -echo "OUTBOUND Client Port ${clientport}" -echo "" -echo "You can change ports by editing the" -echo "start parameters in ${selfname}" -echo "" -echo "${servername} Details" -echo "=======================" -echo "Server name: ${servername}" -echo "Rcon Password: ${rcon}" -echo "" -echo "Config file:" -echo "${servercfg}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -286,48 +264,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -335,27 +315,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -363,39 +383,52 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} cd ${rootdir} cd steamcmd @@ -412,15 +445,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -430,28 +463,69 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${filesdir} tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_details(){ +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') +rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT" +echo "INBOUND Game/Rcon Port ${port}" +if [ "${engine}" = "source" ]; then + echo "INBOUND SourceTV Port ${sourcetvport}" +fi +echo "OUTBOUND Client Port ${clientport}" +echo "" +echo "You can change ports by editing the" +echo "start parameters in ${selfname}" +echo "" +echo "${servername} Details" +echo "=======================" +echo "Server name: ${servername}" +echo "Rcon Password: ${rcon}" +echo "" +echo "Config file:" +echo "${servercfg}" +echo "" +} + # ## Installer # @@ -473,7 +547,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -488,7 +562,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -497,7 +571,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${filesdir} ];then +if [ -d ${filesdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -505,7 +579,7 @@ if [ -d ${filesdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -518,7 +592,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -543,7 +617,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done @@ -637,4 +711,4 @@ case "$1" in echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac -exit +exit \ No newline at end of file diff --git a/GameServerQuery/gsquery.py b/GameServerQuery/gsquery.py new file mode 100644 index 000000000..0519b2ff3 --- /dev/null +++ b/GameServerQuery/gsquery.py @@ -0,0 +1,119 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# Source Game Server Query +# Author: Anonymous & Daniel Gibbs +# # Website: http://danielgibbs.co.uk +# Version: 251213 + +import optparse +import socket +import sys + +class GameServer: + def __init__( self, options, arguments ): + self.option = options + self.argument = arguments + # + self.server_response_timeout = 5 + self.default_buffer_length = 1024 + # + if self.option.engine == 'source': + self.query_prompt_string = '\xFF\xFF\xFF\xFFTSource Engine Query\0' + if self.option.engine == 'goldsource': + self.query_prompt_string = '\xFF\xFF\xFF\xFFTSource Engine Query\0' + if self.option.engine == 'spark': + self.query_prompt_string = '\xFF\xFF\xFF\xFFTSource Engine Query\0' + elif self.option.engine == 'unreal': + self.query_prompt_string = '\x5C\x69\x6E\x66\x6F\x5C' + elif self.option.engine == 'unreal2': + self.query_prompt_string = '\x79\x00\x00\x00\x00' + self.connected = False + self.response = None + self.sanity_checks() + + def fatal_error( self, error_message, error_code=1 ): + sys.stderr.write( 'ERROR: ' + str(error_message) + '\n' ) + sys.exit( error_code ) + + def exit_success( self, success_message='' ): + sys.stdout.write( 'OK: ' + str(success_message) + '\n' ) + sys.exit( 0 ) + + def responding( self ): + # Connect. + connection = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) + connection.settimeout( self.server_response_timeout ) + try: + self.connected = connection.connect( ( self.option.address, int(self.option.port) ) ) + except socket.timeout: + self.fatal_error( 'Request timed out', 1 ) + except: + self.fatal_error( 'Unable to connect', 1 ) + # Send. + connection.send( self.query_prompt_string ) + # Receive. + try: + self.response = connection.recv( self.default_buffer_length ) + except socket.error: + self.fatal_error( 'Unable to receive', 2 ) + connection.close() + # Response. + if self.response == None: + self.fatal_error( 'No response', 3 ) + if len( self.response ) < 10 : + sys.exit( 'Short response.', 3 ) + else: + self.exit_success( str( self.response ) ) + + def sanity_checks( self ): + if not self.option.address: + self.fatal_error( 'No IPv4 address supplied.', 4 ) + if not self.option.port: + self.fatal_error( 'No port supplied.', 4 ) + +if __name__ == '__main__': + parser = optparse.OptionParser( + usage = 'usage: python %prog [options]', + version = '%prog 0.0.1' + ) + parser.add_option( + '-a', '--address', + action = 'store', + dest = 'address', + default = False, + help = 'The IPv4 address of the server.' + ) + parser.add_option( + '-p', '--port', + action = 'store', + dest = 'port', + default = False, + help = 'The IPv4 port of the server.' + ) + parser.add_option( + '-e', '--engine', + action = 'store', + dest = 'engine', + default = False, + help = 'Engine type. source, goldsource, unreal, unreal2, spark' + ) + parser.add_option( + '-v', '--verbose', + action = 'store_true', + dest = 'verbose', + default = False, + help = 'Display verbose output.' + ) + parser.add_option( + '-d', '--debug', + action = 'store_true', + dest = 'debug', + default = False, + help = 'Display debugging output.' + ) + options, arguments = parser.parse_args() + # + server = GameServer( options, arguments ) + server.responding() + + diff --git a/HalfLife2Deathmatch/hl2dmserver b/HalfLife2Deathmatch/hl2dmserver index d6c513d3e..480528c39 100644 --- a/HalfLife2Deathmatch/hl2dmserver +++ b/HalfLife2Deathmatch/hl2dmserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -18,7 +18,9 @@ port="27015" sourcetvport="27020" clientport="27005" maxplayers="16" -parms="-game hl2mp +map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" +ip="0.0.0.0" +# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server +parms="-game hl2mp +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" #### Advanced Variables #### @@ -27,6 +29,7 @@ appid="232370" # Server Details servicename="hl2dm-server" + gamename="Half Life 2: Deathmatch" engine="source" @@ -60,41 +63,49 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${filesdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" +if [ ! -e ${filesdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} + fi fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -110,6 +121,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -122,16 +134,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${filesdir} @@ -152,20 +163,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -194,12 +205,12 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -210,49 +221,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') -rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT" -echo "INBOUND Game/Rcon Port ${port}" -if [ "${engine}" = "source" ];then - echo "INBOUND SourceTV Port ${sourcetvport}" -fi -echo "OUTBOUND Client Port ${clientport}" -echo "" -echo "You can change ports by editing the" -echo "start parameters in ${selfname}" -echo "" -echo "${servername} Details" -echo "=======================" -echo "Server name: ${servername}" -echo "Rcon Password: ${rcon}" -echo "" -echo "Config file:" -echo "${servercfg}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -286,48 +265,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -335,27 +316,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -363,39 +384,52 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} cd ${rootdir} cd steamcmd @@ -412,15 +446,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -430,28 +464,69 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${filesdir} tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_details(){ +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') +rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT" +echo "INBOUND Game/Rcon Port ${port}" +if [ "${engine}" = "source" ]; then + echo "INBOUND SourceTV Port ${sourcetvport}" +fi +echo "OUTBOUND Client Port ${clientport}" +echo "" +echo "You can change ports by editing the" +echo "start parameters in ${selfname}" +echo "" +echo "${servername} Details" +echo "=======================" +echo "Server name: ${servername}" +echo "Rcon Password: ${rcon}" +echo "" +echo "Config file:" +echo "${servercfg}" +echo "" +} + # ## Installer # @@ -473,7 +548,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -488,7 +563,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -497,7 +572,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${filesdir} ];then +if [ -d ${filesdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -505,7 +580,7 @@ if [ -d ${filesdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -518,7 +593,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -543,7 +618,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done @@ -637,4 +712,4 @@ case "$1" in echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac -exit +exit \ No newline at end of file diff --git a/KillingFloor/kfserver b/KillingFloor/kfserver index 990e5c53c..8811e8f28 100644 --- a/KillingFloor/kfserver +++ b/KillingFloor/kfserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -36,7 +36,6 @@ servername=$(grep -s ServerName= ${systemdir}/${ini} | sed 's/ServerName=//g') # Logging logdays="7" - scriptlogdir="${rootdir}/log/script" consolelogdir="${rootdir}/log/console" @@ -50,7 +49,8 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- # Start Variables defaultmap="KF-BioticsLab.rom" parms="server ${defaultmap}?game=KFmod.KFGameType?VACSecured=true -nohomedir ini=${ini} log=${logfile}" -# Example Parameters for Objective mode + +# Start Variables for Objective mode #defaultmap="KFO-Steamland" #parms="server ${defaultmap}?Game=KFStoryGame.KFStoryGame?VACSecured=true -nohomedir ini=${ini} log=${logfile}" @@ -60,110 +60,49 @@ parms="server ${defaultmap}?game=KFmod.KFGameType?VACSecured=true -nohomedir ini # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${systemdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" +if [ ! -e ${filesdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit -fi -} - -fn_compressmaps(){ -fn_rootcheck -clear -echo "${gamename} Map Compressor" -echo "============================" -echo "Will compress all maps in:" -echo "" -pwd -echo "" -echo "Compressed maps saved to:" -echo "" -echo "${compressedmapsdir}" -echo "" -while true; do - read -p "Start compression [y/N]" yn - case $yn in - [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; - * ) echo "Please answer yes or no.";; - esac -done -mkdir ${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 - ./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir - else - ./ucc-bin compress ../Maps/${map} --nohomedir +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} fi -done -mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir} -} - -fn_steamguard(){ -fn_rootcheck -fn_syscheck -clear -fn_header -fn_steamdl -clear -fn_header -echo "If you are gettng an error:" -echo "" -echo "Login Failure: Account Logon Denied Failed." -echo "" -echo "You should now get an email from Steam with a Steam Guard code" -echo "" -read -p "Press [Enter] key to when you have the code..." -clear -fn_header -echo "Please enter Steam Guard Code" -echo "==============================" -echo -n "Code: " -read CODE -touch guard.txt -chmod 0600 guard.txt -echo "set_steam_guard_code $CODE" > guard.txt -echo "login ${steamuser} ${steampass}" >> guard.txt -echo "quit" >> guard.txt -STEAMEXE=steamcmd ./steamcmd.sh +runscript guard.txt -rm guard.txt -cd ../ -echo "==============================" -echo "Complete!" -cd ${rootdir} +fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -179,6 +118,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -191,16 +131,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${systemdir} @@ -221,20 +160,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -263,12 +202,12 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -279,72 +218,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') -queryport=$((${gameport} + 1)) -gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g') -udplinkport=$((${gameport} + 2)) -webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g') -if [ "${engine}" == "unreal" ];then - webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g') -else - webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g') -fi -webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT INI VARIABLE" -echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" -echo "INBOUND Query Port ${queryport} UDP n/a" -if [ "${engine}" == "unreal" ];then - echo "OUTBOUND UdpLink Port (random) ${udplinkport}+ UDP n/a" -fi -if [ "${engine}" != "unreal" ] && [ "${appid}" != "223250" ];then - echo "INBOUND GameSpy Query Port ${gsqueryport} UDP OldQueryPortNumber=${gsqueryport}" -fi -if [ "${appid}" == "215360" ];then - echo "OUTBOUND Master Server port 28852 TCP/UDP n/a" -else - echo "OUTBOUND Master Server port 28900/28902 TCP/UDP n/a" -fi -if [ "${appid}" ];then - if [ "${appid}" == "223250" ];then - echo "OUTBOUND Steam Port 20610 UDP n/a" - else - echo "OUTBOUND Steam Port 20660 UDP n/a" - fi -fi -echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}" -echo "" -echo "${servername} WebAdmin" -echo "=======================" -echo "WebAdmin URL: http://localhost:${webadminport}" -echo "WebAdmin Username: ${webadminuser}" -echo "WebAdmin Password: ${webadminpass}" -echo "" -echo "Config file" -echo "${systemdir}/${ini}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -378,48 +262,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -427,27 +313,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -455,39 +381,52 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} cd ${rootdir} cd steamcmd @@ -511,15 +450,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -529,28 +468,162 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${systemdir} tmux new-session -d -s ${servicename} "./ucc-bin ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_utdetails(){ +fn_autoip +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') +queryport=$((${gameport} + 1)) +gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g') +udplinkport=$((${gameport} + 2)) +webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g') +if [ "${engine}" == "unreal" ]; then + webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g') +else + webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g') +fi +webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT INI VARIABLE" +echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" +echo "INBOUND Query Port ${queryport} UDP n/a" +if [ "${engine}" == "unreal" ]; then + echo "OUTBOUND UdpLink Port (random) ${udplinkport}+ UDP n/a" +fi +if [ "${engine}" != "unreal" ] && [ "${appid}" != "223250" ]; then + echo "INBOUND GameSpy Query Port ${gsqueryport} UDP OldQueryPortNumber=${gsqueryport}" +fi +if [ "${appid}" == "215360" ]; then + echo "OUTBOUND Master Server port 28852 TCP/UDP n/a" +else + echo "OUTBOUND Master Server port 28900/28902 TCP/UDP n/a" +fi +if [ "${appid}" ]; then + if [ "${appid}" == "223250" ]; then + echo "OUTBOUND Steam Port 20610 UDP n/a" + else + echo "OUTBOUND Steam Port 20660 UDP n/a" + fi +fi +echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}" +echo "" +echo "${servername} WebAdmin" +echo "=======================" +echo "WebAdmin URL: http://{$ip}:${webadminport}" +echo "WebAdmin Username: ${webadminuser}" +echo "WebAdmin Password: ${webadminpass}" +echo "" +echo "Config file" +echo "${systemdir}/${ini}" +echo "" +} + +fn_compressmaps(){ +fn_rootcheck +clear +echo "${gamename} Map Compressor" +echo "============================" +echo "Will compress all maps in:" +echo "" +pwd +echo "" +echo "Compressed maps saved to:" +echo "" +echo "${compressedmapsdir}" +echo "" +while true; do + read -p "Start compression [y/N]" yn + case $yn in + [Yy]* ) break;; + [Nn]* ) echo Exiting; return 1;; + * ) echo "Please answer yes or no.";; + esac +done +mkdir ${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 + ./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir + else + ./ucc-bin compress ../Maps/${map} --nohomedir + fi +done +mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir} +} + +fn_steamguard(){ +fn_rootcheck +fn_syscheck +clear +fn_header +fn_steamdl +clear +fn_header +echo "If you are gettng an error:" +echo "" +echo "Login Failure: Account Logon Denied Failed." +echo "" +echo "You should now get an email from Steam with a Steam Guard code" +echo "" +read -p "Press [Enter] key to when you have the code..." +clear +fn_header +echo "Please enter Steam Guard Code" +echo "==============================" +echo -n "Code: " +read CODE +touch guard.txt +chmod 0600 guard.txt +echo "set_steam_guard_code $CODE" > guard.txt +echo "login ${steamuser} ${steampass}" >> guard.txt +echo "quit" >> guard.txt +STEAMEXE=steamcmd ./steamcmd.sh +runscript guard.txt +rm guard.txt +cd ../ +echo "==============================" +echo "Complete!" +cd ${rootdir} +} + # ## Installer # @@ -572,7 +645,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -587,7 +660,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -596,7 +669,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${systemdir} ];then +if [ -d ${systemdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -604,7 +677,7 @@ if [ -d ${systemdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -617,9 +690,9 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; - esac + esac done fn_header fn_steamdl @@ -642,7 +715,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done @@ -685,7 +758,7 @@ echo "=================================" ${selfname} stop sleep 5 fn_header - fn_details + fn_utdetails echo "=================================" echo "Install Complete!" echo "" @@ -710,7 +783,7 @@ case "$1" in email-test) fn_emailtest;; details) - fn_details;; + fn_utdetails;; backup) fn_backupserver;; console) diff --git a/Left4Dead2/l4d2server b/Left4Dead2/l4d2server index fe92dfa5c..2f91a888e 100644 --- a/Left4Dead2/l4d2server +++ b/Left4Dead2/l4d2server @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -18,7 +18,9 @@ port="27015" sourcetvport="27020" clientport="27005" maxplayers="16" -parms="-game left4dead2 +map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" +ip="0.0.0.0" +# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server +parms="-game left4dead2 +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" #### Advanced Variables #### @@ -60,41 +62,49 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${filesdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" +if [ ! -e ${filesdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} + fi fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -110,6 +120,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -122,16 +133,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${filesdir} @@ -152,20 +162,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -194,12 +204,12 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -210,49 +220,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') -rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT" -echo "INBOUND Game/Rcon Port ${port}" -if [ "${engine}" = "source" ];then - echo "INBOUND SourceTV Port ${sourcetvport}" -fi -echo "OUTBOUND Client Port ${clientport}" -echo "" -echo "You can change ports by editing the" -echo "start parameters in ${selfname}" -echo "" -echo "${servername} Details" -echo "=======================" -echo "Server name: ${servername}" -echo "Rcon Password: ${rcon}" -echo "" -echo "Config file:" -echo "${servercfg}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -286,48 +264,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -335,27 +315,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -363,39 +383,52 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} cd ${rootdir} cd steamcmd @@ -412,15 +445,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -430,28 +463,69 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${filesdir} tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_details(){ +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') +rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT" +echo "INBOUND Game/Rcon Port ${port}" +if [ "${engine}" = "source" ]; then + echo "INBOUND SourceTV Port ${sourcetvport}" +fi +echo "OUTBOUND Client Port ${clientport}" +echo "" +echo "You can change ports by editing the" +echo "start parameters in ${selfname}" +echo "" +echo "${servername} Details" +echo "=======================" +echo "Server name: ${servername}" +echo "Rcon Password: ${rcon}" +echo "" +echo "Config file:" +echo "${servercfg}" +echo "" +} + # ## Installer # @@ -473,7 +547,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -488,7 +562,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -497,7 +571,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${filesdir} ];then +if [ -d ${filesdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -505,7 +579,7 @@ if [ -d ${filesdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -518,7 +592,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -543,7 +617,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done diff --git a/NaturalSelection2/ns2server b/NaturalSelection2/ns2server index fc9e5fc42..1f7de7f65 100644 --- a/NaturalSelection2/ns2server +++ b/NaturalSelection2/ns2server @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -63,41 +63,49 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${filesdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" +if [ ! -e ${filesdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} + fi fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -113,6 +121,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -125,16 +134,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${filesdir} @@ -155,20 +163,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -197,12 +205,12 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -213,42 +221,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_ns2details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT" -echo "INBOUND Game/Rcon Port ${port}" -echo "INBOUND WebAdmin ${webadminport}" -echo "" -echo "${servername} WebAdmin" -echo "=======================" -echo "WebAdmin URL: http://localhost:${webadminport}" -echo "WebAdmin Username: ${webadminuser}" -echo "WebAdmin Password: ${webadminpass}" -echo "" -echo "You can change various parameters by editing the" -echo "start parameters in ${selfname}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -282,48 +265,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -331,27 +316,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -359,43 +384,63 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} 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 ${logfile} +if [ $(grep Denied ${logfile}|wc -l) -ge 1 ];then + echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: STEAMAUTH error detected!: Server update failed" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: STEAMAUTH error detected!: Server update failed" >> ${logfile} + if [ "${emailnotification}" = "on" ];then + mail -s "${servername}: Steam Auth Failure" ${email}< ${logfile} + fi +fi } fn_restartserver(){ @@ -408,15 +453,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -426,28 +471,99 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${filesdir} tmux new-session -d -s ${servicename} "./server_linux32 ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_ns2details(){ +fn_autoip +queryport=$((${port} + 1)) +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT" +echo "INBOUND Game/Rcon Port ${port}" +echo "INBOUND Query Port ${queryport}" +echo "INBOUND WebAdmin ${webadminport}" +echo "" +echo "${servername} WebAdmin" +echo "=======================" +echo "WebAdmin URL: http://${ip}:${webadminport}" +echo "WebAdmin Username: ${webadminuser}" +echo "WebAdmin Password: ${webadminpass}" +echo "" +echo "You can change various parameters by editing the" +echo "start parameters in ${selfname}" +echo "" +} + +fn_steamguard(){ +fn_rootcheck +fn_syscheck +clear +fn_header +fn_steamdl +clear +fn_header +echo "If you are gettng an error:" +echo "" +echo "Login Failure: Account Logon Denied Failed." +echo "" +echo "You should now get an email from Steam with a Steam Guard code" +echo "" +read -p "Press [Enter] key to when you have the code..." +clear +fn_header +echo "Please enter Steam Guard Code" +echo "==============================" +echo -n "Code: " +read CODE +touch guard.txt +chmod 0600 guard.txt +echo "set_steam_guard_code $CODE" > guard.txt +echo "login ${steamuser} ${steampass}" >> guard.txt +echo "quit" >> guard.txt +STEAMEXE=steamcmd ./steamcmd.sh +runscript guard.txt +rm guard.txt +cd ../ +echo "==============================" +echo "Complete!" +cd ${rootdir} +} + # ## Installer # @@ -469,7 +585,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -484,7 +600,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -493,7 +609,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${filesdir} ];then +if [ -d ${filesdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -501,7 +617,7 @@ if [ -d ${filesdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -514,7 +630,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -539,7 +655,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done @@ -566,8 +682,8 @@ echo "=================================" sleep 1 echo "" echo "Applying steamclient.so fix" - mkdir -v ${rootdir}/.steam - mkdir -v ${rootdir}/.steam/sdk32 + mkdir -v ${HOME}/.steam + mkdir -v ${HOME}/.steam/sdk32 cp -v ${filesdir}/steamclient.so ${HOME}/.steam/sdk32/steamclient.so sleep 1 fn_header @@ -605,8 +721,11 @@ case "$1" in fn_debugserver;; install) fn_install;; + steam-auth) + fn_updateserver + fn_steamguard;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|steam-auth}" exit 1;; esac exit \ No newline at end of file diff --git a/NoMoreRoomInHell/nmrihserver b/NoMoreRoomInHell/nmrihserver index 3d1fd53aa..62fc775b6 100644 --- a/NoMoreRoomInHell/nmrihserver +++ b/NoMoreRoomInHell/nmrihserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -22,7 +22,9 @@ port="27015" sourcetvport="27020" clientport="27005" maxplayers="8" -parms="+map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" +ip="0.0.0.0" +# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server +parms="+map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" #### Advanced Variables #### @@ -64,41 +66,49 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${filesdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" +if [ ! -e ${filesdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} + fi fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -114,6 +124,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -126,16 +137,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${filesdir}/srcds @@ -156,20 +166,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -198,12 +208,12 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -214,49 +224,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') -rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT" -echo "INBOUND Game/Rcon Port ${port}" -if [ "${engine}" = "source" ];then - echo "INBOUND SourceTV Port ${sourcetvport}" -fi -echo "OUTBOUND Client Port ${clientport}" -echo "" -echo "You can change ports by editing the" -echo "start parameters in ${selfname}" -echo "" -echo "${servername} Details" -echo "=======================" -echo "Server name: ${servername}" -echo "Rcon Password: ${rcon}" -echo "" -echo "Config file:" -echo "${servercfg}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -290,48 +268,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -339,27 +319,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -367,43 +387,63 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} 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 ${logfile} +if [ $(grep Denied ${logfile}|wc -l) -ge 1 ];then + echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: STEAMAUTH error detected!: Server update failed" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: STEAMAUTH error detected!: Server update failed" >> ${logfile} + if [ "${emailnotification}" = "on" ];then + mail -s "${servername}: Steam Auth Failure" ${email}< ${logfile} + fi +fi } fn_restartserver(){ @@ -416,15 +456,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -434,28 +474,103 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${filesdir}/srcds tmux new-session -d -s ${servicename} "./srcds_nmrih ${parms} -debug|tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_details(){ +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') +rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT" +echo "INBOUND Game/Rcon Port ${port}" +if [ "${engine}" = "source" ]; then + echo "INBOUND SourceTV Port ${sourcetvport}" +fi +echo "OUTBOUND Client Port ${clientport}" +echo "" +echo "You can change ports by editing the" +echo "start parameters in ${selfname}" +echo "" +echo "${servername} Details" +echo "=======================" +echo "Server name: ${servername}" +echo "Rcon Password: ${rcon}" +echo "" +echo "Config file:" +echo "${servercfg}" +echo "" +} + +fn_steamguard(){ +fn_rootcheck +fn_syscheck +clear +fn_header +fn_steamdl +clear +fn_header +echo "If you are gettng an error:" +echo "" +echo "Login Failure: Account Logon Denied Failed." +echo "" +echo "You should now get an email from Steam with a Steam Guard code" +echo "" +read -p "Press [Enter] key to when you have the code..." +clear +fn_header +echo "Please enter Steam Guard Code" +echo "==============================" +echo -n "Code: " +read CODE +touch guard.txt +chmod 0600 guard.txt +echo "set_steam_guard_code $CODE" > guard.txt +echo "login ${steamuser} ${steampass}" >> guard.txt +echo "quit" >> guard.txt +STEAMEXE=steamcmd ./steamcmd.sh +runscript guard.txt +rm guard.txt +cd ../ +echo "==============================" +echo "Complete!" +cd ${rootdir} +} + # ## Installer # @@ -477,7 +592,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -492,7 +607,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -501,7 +616,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${filesdir} ];then +if [ -d ${filesdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -509,7 +624,7 @@ if [ -d ${filesdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -522,7 +637,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -547,7 +662,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done @@ -643,8 +758,11 @@ case "$1" in fn_debugserver;; install) fn_install;; + steam-auth) + fn_updateserver + fn_steamguard;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|steam-auth}" exit 1;; esac -exit +exit \ No newline at end of file diff --git a/RedOrchestra/roserver b/RedOrchestra/roserver index da9fb791a..165ed0faf 100644 --- a/RedOrchestra/roserver +++ b/RedOrchestra/roserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -56,8 +56,8 @@ parms="server ${defaultmap}?game=ROGame.ROTeamGame?VACSecured=true -nohomedir in # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } @@ -69,97 +69,36 @@ if [ ! -e ${systemdir} ];then fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit -fi -} - -fn_compressmaps(){ -fn_rootcheck -clear -echo "${gamename} Map Compressor" -echo "============================" -echo "Will compress all maps in:" -echo "" -pwd -echo "" -echo "Compressed maps saved to:" -echo "" -echo "${compressedmapsdir}" -echo "" -while true; do - read -p "Start compression [y/N]" yn - case $yn in - [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; - * ) echo "Please answer yes or no.";; - esac -done -mkdir ${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 - ./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir - else - ./ucc-bin compress ../Maps/${map} --nohomedir +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} fi -done -mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir} -} - -fn_steamguard(){ -fn_rootcheck -fn_syscheck -clear -fn_header -fn_steamdl -clear -fn_header -echo "If you are gettng an error:" -echo "" -echo "Login Failure: Account Logon Denied Failed." -echo "" -echo "You should now get an email from Steam with a Steam Guard code" -echo "" -read -p "Press [Enter] key to when you have the code..." -clear -fn_header -echo "Please enter Steam Guard Code" -echo "==============================" -echo -n "Code: " -read CODE -touch guard.txt -chmod 0600 guard.txt -echo "set_steam_guard_code $CODE" > guard.txt -echo "login ${steamuser} ${steampass}" >> guard.txt -echo "quit" >> guard.txt -STEAMEXE=steamcmd ./steamcmd.sh +runscript guard.txt -rm guard.txt -cd ../ -echo "==============================" -echo "Complete!" -cd ${rootdir} +fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -175,6 +114,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -187,16 +127,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${systemdir} @@ -217,20 +156,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -259,12 +198,12 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -275,72 +214,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') -queryport=$((${gameport} + 1)) -gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g') -udplinkport=$((${gameport} + 2)) -webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g') -if [ "${engine}" == "unreal" ];then - webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g') -else - webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g') -fi -webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT INI VARIABLE" -echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" -echo "INBOUND Query Port ${queryport} UDP n/a" -if [ "${engine}" == "unreal" ];then - echo "OUTBOUND UdpLink Port (random) ${udplinkport}+ UDP n/a" -fi -if [ "${engine}" != "unreal" ] && [ "${appid}" != "223250" ];then - echo "INBOUND GameSpy Query Port ${gsqueryport} UDP OldQueryPortNumber=${gsqueryport}" -fi -if [ "${appid}" == "215360" ];then - echo "OUTBOUND Master Server port 28852 TCP/UDP n/a" -else - echo "OUTBOUND Master Server port 28900/28902 TCP/UDP n/a" -fi -if [ "${appid}" ];then - if [ "${appid}" == "223250" ];then - echo "OUTBOUND Steam Port 20610 UDP n/a" - else - echo "OUTBOUND Steam Port 20660 UDP n/a" - fi -fi -echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}" -echo "" -echo "${servername} WebAdmin" -echo "=======================" -echo "WebAdmin URL: http://localhost:${webadminport}" -echo "WebAdmin Username: ${webadminuser}" -echo "WebAdmin Password: ${webadminpass}" -echo "" -echo "Config file" -echo "${systemdir}/${ini}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -374,48 +258,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -423,27 +309,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -451,39 +377,52 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} cd ${rootdir} cd steamcmd @@ -507,15 +446,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -525,29 +464,162 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${systemdir} - tmux new-session -d -s ${servicename} "./ucc-bin ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_utdetails(){ +fn_autoip +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') +queryport=$((${gameport} + 1)) +gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g') +udplinkport=$((${gameport} + 2)) +webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g') +if [ "${engine}" == "unreal" ]; then + webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g') +else + webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g') +fi +webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT INI VARIABLE" +echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" +echo "INBOUND Query Port ${queryport} UDP n/a" +if [ "${engine}" == "unreal" ]; then + echo "OUTBOUND UdpLink Port (random) ${udplinkport}+ UDP n/a" +fi +if [ "${engine}" != "unreal" ] && [ "${appid}" != "223250" ]; then + echo "INBOUND GameSpy Query Port ${gsqueryport} UDP OldQueryPortNumber=${gsqueryport}" +fi +if [ "${appid}" == "215360" ]; then + echo "OUTBOUND Master Server port 28852 TCP/UDP n/a" +else + echo "OUTBOUND Master Server port 28900/28902 TCP/UDP n/a" +fi +if [ "${appid}" ]; then + if [ "${appid}" == "223250" ]; then + echo "OUTBOUND Steam Port 20610 UDP n/a" + else + echo "OUTBOUND Steam Port 20660 UDP n/a" + fi +fi +echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}" +echo "" +echo "${servername} WebAdmin" +echo "=======================" +echo "WebAdmin URL: http://{$ip}:${webadminport}" +echo "WebAdmin Username: ${webadminuser}" +echo "WebAdmin Password: ${webadminpass}" +echo "" +echo "Config file" +echo "${systemdir}/${ini}" +echo "" +} + +fn_compressmaps(){ +fn_rootcheck +clear +echo "${gamename} Map Compressor" +echo "============================" +echo "Will compress all maps in:" +echo "" +pwd +echo "" +echo "Compressed maps saved to:" +echo "" +echo "${compressedmapsdir}" +echo "" +while true; do + read -p "Start compression [y/N]" yn + case $yn in + [Yy]* ) break;; + [Nn]* ) echo Exiting; return 1;; + * ) echo "Please answer yes or no.";; + esac +done +mkdir ${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 + ./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir + else + ./ucc-bin compress ../Maps/${map} --nohomedir + fi +done +mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir} +} + +fn_steamguard(){ +fn_rootcheck +fn_syscheck +clear +fn_header +fn_steamdl +clear +fn_header +echo "If you are gettng an error:" +echo "" +echo "Login Failure: Account Logon Denied Failed." +echo "" +echo "You should now get an email from Steam with a Steam Guard code" +echo "" +read -p "Press [Enter] key to when you have the code..." +clear +fn_header +echo "Please enter Steam Guard Code" +echo "==============================" +echo -n "Code: " +read CODE +touch guard.txt +chmod 0600 guard.txt +echo "set_steam_guard_code $CODE" > guard.txt +echo "login ${steamuser} ${steampass}" >> guard.txt +echo "quit" >> guard.txt +STEAMEXE=steamcmd ./steamcmd.sh +runscript guard.txt +rm guard.txt +cd ../ +echo "==============================" +echo "Complete!" +cd ${rootdir} +} + # ## Installer # @@ -569,7 +641,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -584,7 +656,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -593,7 +665,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${systemdir} ];then +if [ -d ${systemdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -601,7 +673,7 @@ if [ -d ${systemdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -614,9 +686,9 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; - esac + esac done fn_header fn_steamdl @@ -639,7 +711,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done @@ -682,7 +754,7 @@ echo "=================================" ${selfname} stop sleep 5 fn_header - fn_details + fn_utdetails echo "=================================" echo "Install Complete!" echo "" @@ -707,7 +779,7 @@ case "$1" in email-test) fn_emailtest;; details) - fn_details;; + fn_utdetails;; backup) fn_backupserver;; console) diff --git a/TeamFortress2/tf2server b/TeamFortress2/tf2server index 0335b7a34..e9c9c8820 100644 --- a/TeamFortress2/tf2server +++ b/TeamFortress2/tf2server @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 081213 +# Version: 251213 #### Variables #### @@ -18,7 +18,9 @@ port="27015" sourcetvport="27020" clientport="27005" maxplayers="16" -parms="-game tf +map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" +ip="0.0.0.0" +# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server +parms="-game tf +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" #### Advanced Variables #### @@ -31,7 +33,7 @@ gamename="Team Fortress 2" engine="source" # Directorys -rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" selfname="$0" filesdir="${rootdir}/serverfiles" servercfg="${filesdir}/tf/cfg/${servicename}.cfg" @@ -60,41 +62,49 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${filesdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" +if [ ! -e ${filesdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} + fi fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -110,6 +120,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -122,16 +133,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${filesdir} @@ -152,20 +162,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -199,7 +209,7 @@ while true; do esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -210,49 +220,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') -rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT" -echo "INBOUND Game/Rcon Port ${port}" -if [ "${engine}" = "source" ];then - echo "INBOUND SourceTV Port ${sourcetvport}" -fi -echo "OUTBOUND Client Port ${clientport}" -echo "" -echo "You can change ports by editing the" -echo "start parameters in ${selfname}" -echo "" -echo "${servername} Details" -echo "=======================" -echo "Server name: ${servername}" -echo "Rcon Password: ${rcon}" -echo "" -echo "Config file:" -echo "${servercfg}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -286,48 +264,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -335,27 +315,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -363,39 +383,52 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } fn_updateserver(){ fn_rootcheck fn_syscheck -echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" +sleep 0.5 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog} cd ${rootdir} cd steamcmd @@ -412,15 +445,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -430,28 +463,69 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${filesdir} tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_details(){ +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +servername=$(grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g') +rcon=$(grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT" +echo "INBOUND Game/Rcon Port ${port}" +if [ "${engine}" = "source" ]; then + echo "INBOUND SourceTV Port ${sourcetvport}" +fi +echo "OUTBOUND Client Port ${clientport}" +echo "" +echo "You can change ports by editing the" +echo "start parameters in ${selfname}" +echo "" +echo "${servername} Details" +echo "=======================" +echo "Server name: ${servername}" +echo "Rcon Password: ${rcon}" +echo "" +echo "Config file:" +echo "${servercfg}" +echo "" +} + # ## Installer # @@ -473,7 +547,7 @@ echo "=================================" cd ${rootdir} mkdir steamcmd cd steamcmd -if [ ! -f steamcmd.sh ];then +if [ ! -f steamcmd.sh ]; then wget http://media.steampowered.com/client/steamcmd_linux.tar.gz tar --verbose -zxf steamcmd_linux.tar.gz rm -v steamcmd_linux.tar.gz @@ -488,7 +562,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -497,7 +571,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${filesdir} ];then +if [ -d ${filesdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -505,7 +579,7 @@ if [ -d ${filesdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -518,7 +592,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -543,7 +617,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done @@ -594,9 +668,9 @@ echo "=================================" sleep 1 echo "" echo "Applying steamclient.so fix" - mkdir -v ${rootdir}/.steam - mkdir -v ${rootdir}/.steam/sdk32 - cp -v ${filesdir}/bin/steamclient.so ${rootdir}/.steam/sdk32/steamclient.so + mkdir -v ${HOME}/.steam + mkdir -v ${HOME}/.steam/sdk32 + cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so sleep 1 fn_header fn_details diff --git a/UnrealTournament2004/ut2k4server b/UnrealTournament2004/ut2k4server index 762ca81b4..693bf4d72 100644 --- a/UnrealTournament2004/ut2k4server +++ b/UnrealTournament2004/ut2k4server @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 221113 +# Version: 251213 #### Variables #### @@ -49,76 +49,49 @@ parms="server ${defaultmap}?game=XGame.xDMGame -nohomedir ini=${ini} log=${logfi # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${systemdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" +if [ ! -e ${systemdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit -fi -} - -fn_compressmaps(){ -fn_rootcheck -clear -echo "${gamename} Map Compressor" -echo "============================" -echo "Will compress all maps in:" -echo "" -pwd -echo "" -echo "Compressed maps saved to:" -echo "" -echo "${compressedmapsdir}" -echo "" -while true; do - read -p "Start compression [y/N]" yn - case $yn in - [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; - * ) echo "Please answer yes or no.";; - esac -done -mkdir ${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 - ./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir - else - ./ucc-bin compress ../Maps/${map} --nohomedir +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} fi -done -mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir} +fi } fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -134,6 +107,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -146,16 +120,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${systemdir} @@ -181,20 +154,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -223,12 +196,12 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -239,72 +212,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') -queryport=$((${gameport} + 1)) -gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g') -udplinkport=$((${gameport} + 2)) -webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g') -if [ "${engine}" == "unreal" ];then - webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g') -else - webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g') -fi -webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT INI VARIABLE" -echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" -echo "INBOUND Query Port ${queryport} UDP n/a" -if [ "${engine}" == "unreal" ];then - echo "OUTBOUND UdpLink Port (random) ${udplinkport}+ UDP n/a" -fi -if [ "${engine}" != "unreal" ] && [ "${appid}" != "223250" ];then - echo "INBOUND GameSpy Query Port ${gsqueryport} UDP OldQueryPortNumber=${gsqueryport}" -fi -if [ "${appid}" == "215360" ];then - echo "OUTBOUND Master Server port 28852 TCP/UDP n/a" -else - echo "OUTBOUND Master Server port 28900/28902 TCP/UDP n/a" -fi -if [ "${appid}" ];then - if [ "${appid}" == "223250" ];then - echo "OUTBOUND Steam Port 20610 UDP n/a" - else - echo "OUTBOUND Steam Port 20660 UDP n/a" - fi -fi -echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}" -echo "" -echo "${servername} WebAdmin" -echo "=======================" -echo "WebAdmin URL: http://localhost:${webadminport}" -echo "WebAdmin Username: ${webadminuser}" -echo "WebAdmin Password: ${webadminpass}" -echo "" -echo "Config file" -echo "${systemdir}/${ini}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -338,48 +256,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -387,27 +307,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -415,32 +375,43 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } @@ -454,15 +425,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -472,13 +443,23 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${systemdir} if [ `getconf LONG_BIT` = "64" ] then @@ -488,17 +469,107 @@ else 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[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_utdetails(){ +fn_autoip +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') +queryport=$((${gameport} + 1)) +gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g') +udplinkport=$((${gameport} + 2)) +webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g') +if [ "${engine}" == "unreal" ]; then + webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g') +else + webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g') +fi +webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT INI VARIABLE" +echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" +echo "INBOUND Query Port ${queryport} UDP n/a" +if [ "${engine}" == "unreal" ]; then + echo "OUTBOUND UdpLink Port (random) ${udplinkport}+ UDP n/a" +fi +if [ "${engine}" != "unreal" ] && [ "${appid}" != "223250" ]; then + echo "INBOUND GameSpy Query Port ${gsqueryport} UDP OldQueryPortNumber=${gsqueryport}" +fi +if [ "${appid}" == "215360" ]; then + echo "OUTBOUND Master Server port 28852 TCP/UDP n/a" +else + echo "OUTBOUND Master Server port 28900/28902 TCP/UDP n/a" +fi +if [ "${appid}" ]; then + if [ "${appid}" == "223250" ]; then + echo "OUTBOUND Steam Port 20610 UDP n/a" + else + echo "OUTBOUND Steam Port 20660 UDP n/a" + fi +fi +echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}" +echo "" +echo "${servername} WebAdmin" +echo "=======================" +echo "WebAdmin URL: http://{$ip}:${webadminport}" +echo "WebAdmin Username: ${webadminuser}" +echo "WebAdmin Password: ${webadminpass}" +echo "" +echo "Config file" +echo "${systemdir}/${ini}" +echo "" +} + +fn_compressmaps(){ +fn_rootcheck +clear +echo "${gamename} Map Compressor" +echo "============================" +echo "Will compress all maps in:" +echo "" +pwd +echo "" +echo "Compressed maps saved to:" +echo "" +echo "${compressedmapsdir}" +echo "" +while true; do + read -p "Start compression [y/N]" yn + case $yn in + [Yy]* ) break;; + [Nn]* ) echo Exiting; return 1;; + * ) echo "Please answer yes or no.";; + esac +done +mkdir ${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 + ./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir + else + ./ucc-bin compress ../Maps/${map} --nohomedir + fi +done +mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir} +} + # ## Installer # @@ -521,7 +592,7 @@ echo "============================" cd ${rootdir} mkdir ${filesdir} cd ${filesdir} -if [ ! -f dedicatedserver3339-bonuspack.zip ];then +if [ ! -f dedicatedserver3339-bonuspack.zip ]; then wget http://downloads.unrealadmin.org/UT2004/Server/dedicatedserver3339-bonuspack.zip else echo "dedicatedserver3339-bonuspack.zip already downloaded!" @@ -531,12 +602,12 @@ sleep 1 echo "MD5 checksum: d3f28c5245c4c02802d48e4f0ffd3e34" md5check=$(md5sum dedicatedserver3339-bonuspack.zip| awk '{print $1;}') echo "File returned: ${md5check}" -if [ "${md5check}" != "d3f28c5245c4c02802d48e4f0ffd3e34" ];then +if [ "${md5check}" != "d3f28c5245c4c02802d48e4f0ffd3e34" ]; then echo "MD5 checksum: FAILED!" read -p "Retry download? [y/N]" yn case $yn in [Yy]* ) rm -f dedicatedserver3339-bonuspack.zip; fn_filesdl;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac else @@ -557,7 +628,7 @@ if [ "${md5check}" != "0fa447e05fe5a38e0e32adf171be405e" ];then read -p "Retry download? [y/N]" yn case $yn in [Yy]* ) rm -f ut2004-lnxpatch3369-2.tar.bz2; fn_filesdl;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac else @@ -570,7 +641,7 @@ while true; do read -p "Retry install? [y/N]" yn case $yn in [Yy]* ) fn_install;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac done @@ -579,7 +650,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${systemdir} ];then +if [ -d ${systemdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -587,7 +658,7 @@ if [ -d ${systemdir} ];then read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -600,7 +671,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -631,7 +702,7 @@ echo "=================================" read -p "Remove ut2004-lnxpatch3369-2.tar.bz2? [y/N]" yn case $yn in [Yy]* ) rm -iv ut2004-lnxpatch3369-2.tar.bz2 ; break;; - [Nn]* ) break ;; + [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done @@ -639,7 +710,7 @@ echo "=================================" read -p "Remove dedicatedserver3339-bonuspack.zip? [y/N]" yn case $yn in [Yy]* ) rm -iv dedicatedserver3339-bonuspack.zip ; break;; - [Nn]* ) break ;; + [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done @@ -697,7 +768,7 @@ echo "=================================" ${selfname} stop sleep 5 fn_header - fn_details + fn_utdetails echo "=================================" echo "Install Complete!" echo "" @@ -718,7 +789,7 @@ case "$1" in email-test) fn_emailtest;; details) - fn_details;; + fn_utdetails;; backup) fn_backupserver;; console) diff --git a/UnrealTournament99/ut99server b/UnrealTournament99/ut99server index a93566b13..a20adefd7 100644 --- a/UnrealTournament99/ut99server +++ b/UnrealTournament99/ut99server @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 221113 +# Version: 251213 #### Variables #### @@ -49,71 +49,49 @@ parms="server ${defaultmap}.unr ini=${systemdir}/${ini}" # what you are doing fn_rootcheck(){ -if [ `whoami` = "root" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!" +if [ `whoami` = "root" ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" exit fi } fn_syscheck(){ -if [ ! -e ${systemdir} ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" +if [ ! -e ${systemdir} ]; then + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" exit fi } -fn_runcheck(){ -tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 1 ];then - fn_serverquery - echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} - sleep 0.5 - echo -en "\n" - exit +fn_autoip(){ +# Identifies the server interface IP +# If multiple interfaces this will need to be set manually +getip=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) +getipwc=$(ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|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 interfaces.\n\n" + echo -en "Manually specify the IP in ${selfname}\n" + echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" + echo -en "${getip}\n" + exit + else + ip=${getip} + fi fi } -fn_compressmaps(){ -fn_rootcheck -clear -echo "${gamename} Map Compressor" -echo "============================" -echo "Will compress all maps in:" -echo "" -pwd -echo "" -echo "Compressed maps saved to:" -echo "" -echo "${compressedmapsdir}" -echo "" -while true; do - read -p "Start compression [y/N]" yn - case $yn in - [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; - * ) echo "Please answer yes or no.";; - esac -done -mkdir ${compressedmapsdir} > /dev/null 2>&1 -rm -rfv ${filesdir}/Maps/*.unr.uz -cd ${systemdir} -for map in `ls ${filesdir}/Maps`; do - ./ucc-bin compress ../Maps/${map} --nohomedir -done -mv -fv ${filesdir}/Maps/*.unr.uz ${compressedmapsdir} -} - fn_logmanager(){ -if [ ! -e ${consolelog} ];then +if [ ! -e ${consolelog} ]; then touch ${consolelog} fi # log manager will active if finds logs older than ${logdays} -if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then - echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" +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" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog} + sleep 1 echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog} + sleep 1 find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) @@ -129,6 +107,7 @@ fi fn_debugserver(){ fn_rootcheck fn_syscheck +fn_autoip echo "" echo "${gamename} Debug" echo "============================" @@ -141,16 +120,15 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done fn_stopserver -echo -en "[ .... ] Starting ${servicename}: ${servername} debug mode" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} debug mode" >> ${scriptlog} +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} sleep 0.5 echo -en "\n" cd ${systemdir} @@ -171,20 +149,20 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done -echo -en "\r[ .... ] Starting ${servicename} console" +echo -en "\r\033[K[ .... ] Starting ${servicename} console" sleep 0.5 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[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} console accessed" >> ${scriptlog} +if [ ${tmuxwc} -eq 1 ]; then + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} sleep 1 tmux attach-session -t ${servicename} else - echo -e "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" sleep 0.5 while true; do read -p "Do you want to start the server? [y/N]" yn @@ -213,12 +191,12 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done 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 "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running" while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn @@ -229,72 +207,17 @@ if [ ${tmuxwc} -eq 1 ];then esac done fi -echo -en "[ .... ] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog} -sleep 0.5 -echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog} +echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +sleep 1 +echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog} sleep 1 echo -en "\n" cd ${rootdir} mkdir ${backupdir} > /dev/null 2>&1 tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * -echo -en "\r${servicename} backup complete" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog} -} - -fn_details(){ -echo "" -echo "${gamename} Server Details" -echo "============================" -echo "" -echo "${servername} Ports" -echo "=======================" -gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') -queryport=$((${gameport} + 1)) -gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g') -udplinkport=$((${gameport} + 2)) -webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g') -if [ "${engine}" == "unreal" ];then - webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g') -else - webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g') -fi -webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g') -echo "Ports the server is currently using" -echo "" -echo "DIRECTION DESCRIPTION PORT INI VARIABLE" -echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" -echo "INBOUND Query Port ${queryport} UDP n/a" -if [ "${engine}" == "unreal" ];then - echo "OUTBOUND UdpLink Port (random) ${udplinkport}+ UDP n/a" -fi -if [ "${engine}" != "unreal" ] && [ "${appid}" != "223250" ];then - echo "INBOUND GameSpy Query Port ${gsqueryport} UDP OldQueryPortNumber=${gsqueryport}" -fi -if [ "${appid}" == "215360" ];then - echo "OUTBOUND Master Server port 28852 TCP/UDP n/a" -else - echo "OUTBOUND Master Server port 28900/28902 TCP/UDP n/a" -fi -if [ "${appid}" ];then - if [ "${appid}" == "223250" ];then - echo "OUTBOUND Steam Port 20610 UDP n/a" - else - echo "OUTBOUND Steam Port 20660 UDP n/a" - fi -fi -echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}" -echo "" -echo "${servername} WebAdmin" -echo "=======================" -echo "WebAdmin URL: http://localhost:${webadminport}" -echo "WebAdmin Username: ${webadminuser}" -echo "WebAdmin Password: ${webadminpass}" -echo "" -echo "Config file" -echo "${systemdir}/${ini}" -echo "" +echo -en "\r\033[K${servicename} Backup complete" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} } fn_distro(){ @@ -328,48 +251,50 @@ fn_distro fn_uptime fn_load { -echo -e "========================================\n${servicename} details\n========================================\n" -echo -e "Service: ${servicename}" -echo -e "Game: ${gamename}" -echo -e "Server: ${servername}" -echo -e "Failure reason: ${failurereason}" -echo -e "Action Taken: ${actiontaken}\n" -echo -e "========================================\nServer details\n========================================\n" -echo -e "Date: $(date)" -echo -e "Distro: ${os}" -echo -e "Arch: ${arch}" -echo -e "Kernel: ${kernel}" -echo -e "Hostname: $HOSTNAME" -echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" -echo -e "Avg Load${load}\n" -echo -e "========================================\nLogs\n========================================\n" -echo -e "Script log\n===================\n" + echo -e "========================================\n${servicename} details\n========================================\n" + echo -e "Service: ${servicename}" + echo -e "Server: ${servername}" + echo -e "Game: ${gamename}" + echo -e "Failure reason: ${failurereason}" + echo -e "Action Taken: ${actiontaken}\n" + echo -e "========================================\nServer details\n========================================\n" + echo -e "Date: $(date)" + echo -e "Distro: ${os}" + echo -e "Arch: ${arch}" + echo -e "Kernel: ${kernel}" + echo -e "Hostname: $HOSTNAME" + echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m" + echo -e "Avg Load${load}\n" + echo -e "========================================\nLogs\n========================================\n" + echo -e "Script log\n===================\n" }|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1 tail -25 ${scriptlog} >> ${emaillog} -if [ ! -z ${consolelog} ];then +if [ ! -z ${consolelog} ]; then echo -e "\n\nConsole log\n====================\n" >> ${emaillog} tail -25 ${consolelog} >> ${emaillog} fi -if [ ! -z ${gamelogdir} ];then +if [ ! -z ${gamelogdir} ]; then echo -e "\n\nServer log\n====================\n" >> ${emaillog} 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}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog} +sleep 1 +echo -en "\n" } fn_emailtest(){ fn_rootcheck fn_syscheck echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} -if [ "${emailnotification}" = "on" ];then +if [ "${emailnotification}" = "on" ]; then subject="${servicename} Email Test Notification - Testing ${servername}" failurereason="Testing ${servicename} email notification" actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} fi sleep 0.5 @@ -377,27 +302,67 @@ echo -en "\n" } fn_serverquery(){ -# uses serverquery.py to directly query the server +# uses gsquery.py to directly query the server # detects if the server locks up -if [ -f serverquery.py ];then - echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${scriptlog} - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${scriptlog} - serverquery=$(./serverquery.py 127.0.0.1 ${port} 2>&1) +if [ -f gsquery.py ]; then + if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then + gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') + port=$((${gameport} + 1)) + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog} sleep 1 - if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then - echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} - sleep 1 - echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${scriptlog} + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog} + 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}" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog} sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="Failed to query ${servicename}: ${serverquery}" + actiontaken="restarted ${servicename}" + fn_emailnotification + fi 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} + sleep 1 + echo -en "\n" + echo "Attempting to resolve automatically" + chmod +x -v gsquery.py + exitcode=$? + if [ "${exitcode}" == "0" ]; then + fn_serverquery + else + echo -en "\nUnable to resolve automatically. Please manually fix permissions\n" + owner=$(ls -al gsquery.py|awk '{ print $3 }') + echo "As user ${owner} or root run the following command" + whoami=$(whoami) + echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n" + exit + fi else - echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${scriptlog} + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog} sleep 1 + echo -en "\n" + ./gsquery.py -a ${ip} -p ${port} -e ${engine} + exit fi fi } @@ -405,32 +370,43 @@ fi fn_monitorserver(){ fn_rootcheck fn_syscheck -fn_logmanager -echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}" -echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog} -sleep 0.5 +fn_autoip +echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" +echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} +sleep 1 updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) -if [ "${updatecheck}" = "0" ];then - fn_runcheck - echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog} - if [ "${emailnotification}" = "on" ];then - subject="${servicename} Monitor - Starting ${servername}" - failurereason="${servicename} process was not running" - actiontaken="restarted ${servicename}" - sleep 0.5 +if [ "${updatecheck}" = "0" ]; then + echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} + 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" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} + sleep 1 echo -en "\n" - fn_emailnotification + fn_serverquery + exit + else + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog} + sleep 1 + echo -en "\n" + if [ "${emailnotification}" = "on" ]; then + subject="${servicename} Monitor - Starting ${servername}" + failurereason="${servicename} process not running" + actiontaken="${servicename} has been restarted" + fn_emailnotification + fi + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} + fn_startserver fi - sleep 0.5 - echo -en "\n" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog} - fn_startserver else - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${scriptlog} - echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete" - echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${scriptlog} + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog} + sleep 1 + echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} fi } @@ -444,15 +420,15 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "[ .... ] Stopping ${servicename}: ${servername}" +echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} sleep 0.5 -if [ "${pid}" == "0" ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" +if [ "${pid}" == "0" ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} else tmux kill-session -t ${servicename} - echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} fi sleep 0.5 @@ -462,28 +438,128 @@ echo -en "\n" fn_startserver(){ fn_rootcheck fn_syscheck -echo -en "[ .... ] Starting ${servicename}: ${servername}" +fn_autoip +fn_logmanager +tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) +if [ ${tmuxwc} -eq 0 ]; then + mv ${scriptlog} ${scriptlogdate} + mv ${consolelog} ${consolelogdate} +fi +echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog} sleep 0.5 -fn_runcheck -fn_logmanager -mv ${scriptlog} ${scriptlogdate} -mv ${consolelog} ${consolelogdate} +if [ ${tmuxwc} -eq 1 ]; then + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" + echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} + sleep 0.5 + echo -en "\n" + exit +fi cd ${systemdir} tmux new-session -d -s ${servicename} "./ucc-bin ${parms} |tee -a ${consolelog}" sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -if [ ${tmuxwc} -eq 0 ];then - echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" +if [ ${tmuxwc} -eq 0 ]; then + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog} else - echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog} fi sleep 0.5 echo -en "\n" } +fn_utdetails(){ +fn_autoip +echo "" +echo "${gamename} Server Details" +echo "============================" +echo "" +echo "${servername} Ports" +echo "=======================" +gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g') +queryport=$((${gameport} + 1)) +gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g') +udplinkport=$((${gameport} + 2)) +webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g') +if [ "${engine}" == "unreal" ]; then + webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g') +else + webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g') +fi +webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g') +echo "Ports the server is currently using" +echo "" +echo "DIRECTION DESCRIPTION PORT INI VARIABLE" +echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" +echo "INBOUND Query Port ${queryport} UDP n/a" +if [ "${engine}" == "unreal" ]; then + echo "OUTBOUND UdpLink Port (random) ${udplinkport}+ UDP n/a" +fi +if [ "${engine}" != "unreal" ] && [ "${appid}" != "223250" ]; then + echo "INBOUND GameSpy Query Port ${gsqueryport} UDP OldQueryPortNumber=${gsqueryport}" +fi +if [ "${appid}" == "215360" ]; then + echo "OUTBOUND Master Server port 28852 TCP/UDP n/a" +else + echo "OUTBOUND Master Server port 28900/28902 TCP/UDP n/a" +fi +if [ "${appid}" ]; then + if [ "${appid}" == "223250" ]; then + echo "OUTBOUND Steam Port 20610 UDP n/a" + else + echo "OUTBOUND Steam Port 20660 UDP n/a" + fi +fi +echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}" +echo "" +echo "${servername} WebAdmin" +echo "=======================" +echo "WebAdmin URL: http://{$ip}:${webadminport}" +echo "WebAdmin Username: ${webadminuser}" +echo "WebAdmin Password: ${webadminpass}" +echo "" +echo "Config file" +echo "${systemdir}/${ini}" +echo "" +} + +fn_compressmaps(){ +fn_rootcheck +clear +echo "${gamename} Map Compressor" +echo "============================" +echo "Will compress all maps in:" +echo "" +pwd +echo "" +echo "Compressed maps saved to:" +echo "" +echo "${compressedmapsdir}" +echo "" +while true; do + read -p "Start compression [y/N]" yn + case $yn in + [Yy]* ) break;; + [Nn]* ) echo Exiting; return 1;; + * ) echo "Please answer yes or no.";; + esac +done +mkdir ${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 + ./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir + else + ./ucc-bin compress ../Maps/${map} --nohomedir + fi +done +mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir} +} + # ## Installer # @@ -506,7 +582,7 @@ echo "============================" cd ${rootdir} mkdir ${filesdir} cd ${filesdir} -if [ ! -f ut-server-436.tar.gz ];then +if [ ! -f ut-server-436.tar.gz ]; then wget http://danielgibbs.co.uk/wp-content/uploads/ut-server-436.tar.gz else echo "ut-server-436.tar.gz already downloaded!" @@ -516,18 +592,18 @@ sleep 1 echo "MD5 checksum: 10cd7353aa9d758a075c600a6dd193fd" md5check=$(md5sum ut-server-436.tar.gz| awk '{print $1;}') echo "File returned: ${md5check}" -if [ "${md5check}" != "10cd7353aa9d758a075c600a6dd193fd" ];then +if [ "${md5check}" != "10cd7353aa9d758a075c600a6dd193fd" ]; then echo "MD5 checksum: FAILED!" read -p "Retry download? [y/N]" yn case $yn in [Yy]* ) rm -f ut-server-436.tar.gz; fn_filesdl;; - [Nn]* ) echo Exiting; exit ;; + [Nn]* ) echo Exiting; exit;; * ) echo "Please answer yes or no.";; esac fi echo "MD5 checksum: PASSED" echo "" -if [ ! -f UTPGPatch451.tar.bz2 ];then +if [ ! -f UTPGPatch451.tar.bz2 ]; then wget http://danielgibbs.co.uk/wp-content/uploads/UTPGPatch451.tar.bz2 else echo "UTPGPatch451.tar.bz2 already downloaded!" @@ -537,7 +613,7 @@ sleep 1 echo "MD5 checksum: 77a735a78b1eb819042338859900b83b" md5check=$(md5sum UTPGPatch451.tar.bz2| awk '{print $1;}') echo "File returned: ${md5check}" -if [ "${md5check}" != "77a735a78b1eb819042338859900b83b" ];then +if [ "${md5check}" != "77a735a78b1eb819042338859900b83b" ]; then echo "MD5 checksum: FAILED!" read -p "Retry download? [y/N]" yn case $yn in @@ -564,7 +640,7 @@ done fn_install(){ fn_rootcheck fn_header -if [ -d ${systemdir} ];then +if [ -d ${systemdir} ]; then echo "${gamename} Server is already installed here:" pwd echo "" @@ -585,7 +661,7 @@ while true; do read -p "Continue [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1 ;; + [Nn]* ) echo Exiting; return 1;; * ) echo "Please answer yes or no.";; esac done @@ -603,7 +679,7 @@ echo "=================================" read -p "Was the install successful? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) fn_retryinstall ;; + [Nn]* ) fn_retryinstall;; * ) echo "Please answer yes or no.";; esac done @@ -611,16 +687,16 @@ echo "=================================" while true; do read -p "Remove ut-server-436.tar.gz? [y/N]" yn case $yn in - [Yy]* ) rm -iv ut-server-436.tar.gz; break ;; - [Nn]* ) break ;; + [Yy]* ) rm -iv ut-server-436.tar.gz; break;; + [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done while true; do read -p "Remove UTPGPatch451.tar.bz2? [y/N]" yn case $yn in - [Yy]* ) rm -iv UTPGPatch451.tar.bz2; break ;; - [Nn]* ) break ;; + [Yy]* ) rm -iv UTPGPatch451.tar.bz2; break;; + [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done @@ -686,7 +762,7 @@ case "$1" in email-test) fn_emailtest;; details) - fn_details;; + fn_utdetails;; backup) fn_backupserver;; console)