Browse Source
Mainly updates to make it easier to merger server versions Improved installer Insurgency Server added Fixed fn_autoip not functioning as excpected various other fixespull/62/head
16 changed files with 3515 additions and 2300 deletions
@ -3,7 +3,7 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 251213 |
|||
# Version: 240114 |
|||
|
|||
#### Variables #### |
|||
|
|||
@ -12,14 +12,20 @@ |
|||
emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="anonymous" |
|||
steampass="" |
|||
|
|||
# Start Variables |
|||
defaultmap="de_aztec" |
|||
defaultmap="de_dust2" |
|||
port="27015" |
|||
clientport="27005" |
|||
maxplayers="16" |
|||
ip="0.0.0.0" |
|||
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 |
|||
fn_parms(){ |
|||
parms="-game cstrike +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers}" |
|||
} |
|||
|
|||
#### Advanced Variables #### |
|||
|
|||
@ -35,16 +41,21 @@ engine="goldsource" |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
filesdir="${rootdir}/serverfiles" |
|||
servercfg="${filesdir}/cstrike/${servicename}.cfg" |
|||
systemdir="${filesdir}/cstrike" |
|||
executabledir="${filesdir}" |
|||
executable="./hlds_run" |
|||
servercfg="${systemdir}/${servicename}.cfg" |
|||
defaultcfg="${systemdir}/server.cfg" |
|||
backupdir="backups" |
|||
steamclient="${filesdir}/steamclient.so" |
|||
|
|||
# Server Details |
|||
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') |
|||
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') |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${filesdir}/cstrike/logs" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
|
|||
@ -60,6 +71,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- |
|||
# unless you know |
|||
# what you are doing |
|||
|
|||
fn_scriptlog(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} |
|||
} |
|||
|
|||
fn_rootcheck(){ |
|||
if [ `whoami` = "root" ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" |
|||
@ -68,8 +83,8 @@ fi |
|||
} |
|||
|
|||
fn_syscheck(){ |
|||
if [ ! -e ${filesdir} ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: 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 |
|||
} |
|||
@ -77,42 +92,42 @@ fi |
|||
fn_autoip(){ |
|||
# Identifies the server interface IP |
|||
# If multiple interfaces this will need to be set manually |
|||
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) |
|||
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l) |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active interfaces.\n\n" |
|||
echo -en "Manually specify the IP in ${selfname}\n" |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use in ${selfname}.\n" |
|||
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" |
|||
echo -en "${getip}\n" |
|||
exit |
|||
else |
|||
else |
|||
ip=${getip} |
|||
fi |
|||
fi |
|||
} |
|||
|
|||
fn_logmanager(){ |
|||
if [ ! -e ${consolelog} ]; then |
|||
touch ${consolelog} |
|||
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 |
|||
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} |
|||
fn_scriptlog "Starting log cleaner" |
|||
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} |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) |
|||
consolecount=$(find ${consolelogdir}/* -mtime +${logdays}|wc -l) |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog} |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
fi |
|||
} |
|||
|
|||
@ -120,6 +135,7 @@ fn_debugserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
echo "" |
|||
echo "${gamename} Debug" |
|||
echo "============================" |
|||
@ -128,6 +144,9 @@ echo -e "Use for identifying server issues only!" |
|||
echo -e "Press CTRL+c to drop out of debug mode" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped" |
|||
echo "" |
|||
echo "Start parameters:" |
|||
echo ${parms} |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
@ -140,11 +159,11 @@ fn_stopserver |
|||
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} |
|||
fn_scriptlog "Started debug mode ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd ${filesdir} |
|||
./hlds_run ${parms} -debug |
|||
cd "${executabledir}" |
|||
${executable} ${parms} -debug |
|||
} |
|||
|
|||
fn_console(){ |
|||
@ -170,7 +189,7 @@ 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\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
@ -203,7 +222,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 |
|||
@ -222,14 +241,14 @@ fi |
|||
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} |
|||
fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd ${rootdir} |
|||
mkdir ${backupdir} > /dev/null 2>&1 |
|||
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * |
|||
cd "${rootdir}" |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" * |
|||
echo -en "\r\033[K${servicename} Backup complete" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} |
|||
fn_scriptlog "Backup complete" |
|||
} |
|||
|
|||
fn_distro(){ |
|||
@ -255,7 +274,7 @@ days=$(( uptime/60/60/24 )) |
|||
} |
|||
|
|||
fn_load(){ |
|||
load=$(uptime | awk -F 'load average' '{ print $2 }') |
|||
load=$(uptime|awk -F 'load average' '{ print $2 }') |
|||
} |
|||
|
|||
fn_emailnotification(){ |
|||
@ -279,19 +298,19 @@ fn_load |
|||
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 |
|||
echo -e "\n\nConsole log\n====================\n" >> ${emaillog} |
|||
tail -25 ${consolelog} >> ${emaillog} |
|||
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1 |
|||
tail -25 "${scriptlog}" >> "${emaillog}" |
|||
if [ ! -z "${consolelog}" ]; then |
|||
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}" |
|||
tail -25 "${consolelog}" >> "${emaillog}" |
|||
fi |
|||
if [ ! -z ${gamelogdir} ]; then |
|||
echo -e "\n\nServer log\n====================\n" >> ${emaillog} |
|||
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog} |
|||
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} |
|||
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} |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
} |
|||
@ -299,7 +318,7 @@ echo -en "\n" |
|||
fn_emailtest(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} |
|||
fn_scriptlog "Emailing test notification" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
subject="${servicename} Email Test Notification - Testing ${servername}" |
|||
failurereason="Testing ${servicename} email notification" |
|||
@ -307,7 +326,7 @@ if [ "${emailnotification}" = "on" ]; then |
|||
fn_emailnotification |
|||
else |
|||
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} |
|||
fn_scriptlog "Email notification not enabled" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -317,23 +336,23 @@ fn_serverquery(){ |
|||
# uses gsquery.py to directly query the server |
|||
# detects if the server locks up |
|||
if [ -f gsquery.py ]; then |
|||
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; 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} |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
@ -346,13 +365,13 @@ if [ -f gsquery.py ]; then |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
elif [ "${exitcode}" == "126" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "Attempting to resolve automatically" |
|||
@ -370,11 +389,11 @@ if [ -f gsquery.py ]; then |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
exit |
|||
fi |
|||
fi |
|||
} |
|||
@ -384,41 +403,41 @@ fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: CHECKING" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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} |
|||
fn_scriptlog "Checking session: FAIL" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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 |
|||
fn_scriptlog "Monitor is starting ${servername}" |
|||
fn_startserver |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} |
|||
fn_scriptlog "When updates complete ${servicename} will start" |
|||
fi |
|||
} |
|||
|
|||
@ -428,14 +447,14 @@ fn_syscheck |
|||
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 anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog} |
|||
fn_scriptlog "Updating ${servername}" |
|||
cd "${rootdir}" |
|||
cd "steamcmd" |
|||
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" |
|||
} |
|||
|
|||
fn_restartserver(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Restarting ${servername}" |
|||
fn_stopserver |
|||
fn_startserver |
|||
} |
|||
@ -445,15 +464,15 @@ fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 0.5 |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already stopped" |
|||
else |
|||
tmux kill-session -t ${servicename} |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopped ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -463,65 +482,70 @@ fn_startserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
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} |
|||
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} |
|||
fn_scriptlog "Starting ${servername}" |
|||
sleep 0.5 |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
cd ${filesdir} |
|||
tmux new-session -d -s ${servicename} "./hlds_run ${parms} |tee -a ${consolelog}" |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${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\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} |
|||
fn_scriptlog "failed to start ${servername}" |
|||
else |
|||
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} |
|||
fn_scriptlog "Started ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_details(){ |
|||
fn_autoip |
|||
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') |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo "" |
|||
echo "${gamename} Server Details" |
|||
echo "============================" |
|||
echo "Server name: ${servername}" |
|||
echo "Server IP: ${ip}:${port}" |
|||
echo "RCON password: ${rcon}" |
|||
echo "Config file: ${servercfg}" |
|||
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 "Ports the server is currently using." |
|||
echo "" |
|||
echo "DIRECTION DESCRIPTION PORT" |
|||
echo "INBOUND Game/Rcon Port ${port}" |
|||
echo "INBOUND Game/RCON port ${port}" |
|||
if [ "${engine}" = "source" ]; then |
|||
echo "INBOUND SourceTV Port ${sourcetvport}" |
|||
echo "INBOUND SourceTV port ${sourcetvport}" |
|||
fi |
|||
echo "OUTBOUND Client Port ${clientport}" |
|||
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 "start parameters in ${selfname}." |
|||
echo "" |
|||
echo "Config file:" |
|||
echo "${servercfg}" |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" |
|||
else |
|||
echo -e "Status:\e[0;32m ONLINE\e[0;39m" |
|||
fi |
|||
echo "" |
|||
} |
|||
|
|||
@ -529,11 +553,23 @@ echo "" |
|||
## Installer |
|||
# |
|||
|
|||
fn_csappmanifest(){ |
|||
echo "Downloading appmanifest files (app 90 fix)" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -v "${filesdir}/ec5da605084840d3d7b3ed355e48c098b28a1bd5" |
|||
cd "${filesdir}/ec5da605084840d3d7b3ed355e48c098b28a1bd5" |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_10.acf |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_70.acf |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_90.acf |
|||
echo "" |
|||
} |
|||
|
|||
fn_header(){ |
|||
clear |
|||
echo "=================================" |
|||
echo "${gamename}" |
|||
echo "Server Linux Installer" |
|||
echo "Linux Game Server Manager" |
|||
echo "by Daniel Gibbs" |
|||
echo "http://danielgibbs.co.uk" |
|||
echo "=================================" |
|||
@ -541,19 +577,73 @@ echo "" |
|||
} |
|||
|
|||
fn_steamdl(){ |
|||
echo "Installing Steam" |
|||
echo "Installing SteamCMD" |
|||
echo "=================================" |
|||
cd ${rootdir} |
|||
mkdir steamcmd |
|||
cd steamcmd |
|||
cd "${rootdir}" |
|||
mkdir -pv "steamcmd" |
|||
sleep 1 |
|||
cd "steamcmd" |
|||
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 |
|||
chmod +x steamcmd.sh |
|||
sleep 1 |
|||
else |
|||
echo "" |
|||
echo "Steam already installed!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_steaminstall(){ |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${filesdir}" |
|||
cd "${rootdir}/steamcmd" |
|||
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamfix(){ |
|||
echo "Applying steamclient.so fix" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv ${HOME}/.steam |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_loginstall(){ |
|||
echo "Creating log directorys" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
touch "${scriptlog}" |
|||
mkdir -pv "${consolelogdir}" |
|||
touch "${consolelog}" |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv "${gamelogdir}" "${rootdir}/log/server" |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_retryinstall(){ |
|||
@ -570,20 +660,19 @@ done |
|||
fn_install(){ |
|||
fn_rootcheck |
|||
fn_header |
|||
if [ -d ${filesdir} ]; then |
|||
if [ -d "${filesdir}" ]; then |
|||
echo "${gamename} Server is already installed here:" |
|||
pwd |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Yy]* ) fn_header; break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
fn_header |
|||
echo "Install Directory:" |
|||
pwd |
|||
echo "" |
|||
@ -597,62 +686,24 @@ while true; do |
|||
done |
|||
fn_header |
|||
fn_steamdl |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
rm -f ${servercfg} |
|||
mkdir -v ${filesdir} |
|||
echo "" |
|||
echo "Downloading appmanifest files (app 90 fix)" |
|||
echo "=================================" |
|||
sleep 2 |
|||
mkdir -v ${filesdir}/ec5da605084840d3d7b3ed355e48c098b28a1bd5 |
|||
cd ${filesdir}/ec5da605084840d3d7b3ed355e48c098b28a1bd5 |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_10.acf |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_70.acf |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_90.acf |
|||
echo "Downloading appmanifest files (app 90 fix)" |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
cd ${rootdir}/steamcmd |
|||
touch install.txt |
|||
chmod 0600 install.txt |
|||
echo "login anonymous" > install.txt |
|||
echo "force_install_dir ${filesdir}" >> install.txt |
|||
echo "app_update ${appid} validate" >> install.txt |
|||
echo "quit" >> install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
rm install.txt |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall ;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fn_header |
|||
fn_csappmanifest |
|||
fn_steaminstall |
|||
fn_steamfix |
|||
fn_loginstall |
|||
echo "Configuring ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
read -p "Enter server name: " servername |
|||
read -p "Enter rcon password: " rconpass |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating server.cfg" |
|||
touch ${filesdir}/cstrike/server.cfg |
|||
echo "exec ${servicename}.cfg" > ${filesdir}/cstrike/server.cfg |
|||
echo "Creating server.cfg." |
|||
touch "${defaultcfg}" |
|||
echo "exec ${servicename}.cfg" > "${defaultcfg}" |
|||
sleep 1 |
|||
echo "Creating default config file:" |
|||
sleep 0.5 |
|||
echo "${servercfg}" |
|||
touch ${servercfg} |
|||
touch ${filesdir}/cstrike/listip.cfg |
|||
touch ${filesdir}/cstrike/banned.cfg |
|||
echo "Creating ${servicename}.cfg config file." |
|||
touch "${servercfg}" |
|||
touch "${systemdir}/listip.cfg" |
|||
touch "${systemdir}/banned.cfg" |
|||
{ |
|||
echo -e "// Use this file to configure your DEDICATED server." |
|||
echo -e "// This config file is executed on server start." |
|||
@ -691,28 +742,13 @@ echo "=================================" |
|||
echo -e "sv_logecho 1" |
|||
echo -e "sv_logfile 1" |
|||
echo -e "sv_log_onefile 0" |
|||
}|tee ${servercfg} > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating log directorys" |
|||
mkdir -v ${rootdir}/log |
|||
mkdir -v ${scriptlogdir} |
|||
mkdir -v ${consolelogdir} |
|||
touch ${consolelog} |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv ${gamelogdir} ${rootdir}/log/server |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
}|tee "${servercfg}" > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
echo "Applying steamclient.so fix" |
|||
mkdir -v ${HOME}/.steam |
|||
mkdir -v ${HOME}/.steam/sdk32 |
|||
cp -v ${filesdir}/steamclient.so ${HOME}/.steam/sdk32/steamclient.so |
|||
sleep 1 |
|||
fn_header |
|||
sleep 1 |
|||
fn_details |
|||
sleep 1 |
|||
echo "=================================" |
|||
echo "Install Complete!" |
|||
echo "" |
|||
|
@ -3,7 +3,7 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 060113 |
|||
# Version: 240114 |
|||
|
|||
#### Variables #### |
|||
|
|||
@ -12,14 +12,20 @@ |
|||
emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="anonymous" |
|||
steampass="" |
|||
|
|||
# Start Variables |
|||
defaultmap="de_aztec" |
|||
defaultmap="de_dust2" |
|||
port="27015" |
|||
clientport="27005" |
|||
maxplayers="16" |
|||
ip="0.0.0.0" |
|||
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 |
|||
fn_parms(){ |
|||
parms="-game czero +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers}" |
|||
} |
|||
|
|||
#### Advanced Variables #### |
|||
|
|||
@ -35,16 +41,21 @@ engine="goldsource" |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
filesdir="${rootdir}/serverfiles" |
|||
servercfg="${filesdir}/czero/${servicename}.cfg" |
|||
systemdir="${filesdir}/czero" |
|||
executabledir="${filesdir}" |
|||
executable="./hlds_run" |
|||
servercfg="${systemdir}/${servicename}.cfg" |
|||
defaultcfg="${systemdir}/server.cfg" |
|||
backupdir="backups" |
|||
steamclient="${filesdir}/steamclient.so" |
|||
|
|||
# Server Details |
|||
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') |
|||
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') |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${filesdir}/czero/logs" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
|
|||
@ -60,6 +71,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- |
|||
# unless you know |
|||
# what you are doing |
|||
|
|||
fn_scriptlog(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} |
|||
} |
|||
|
|||
fn_rootcheck(){ |
|||
if [ `whoami` = "root" ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" |
|||
@ -68,8 +83,8 @@ fi |
|||
} |
|||
|
|||
fn_syscheck(){ |
|||
if [ ! -e ${filesdir} ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: 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 |
|||
} |
|||
@ -77,42 +92,42 @@ fi |
|||
fn_autoip(){ |
|||
# Identifies the server interface IP |
|||
# If multiple interfaces this will need to be set manually |
|||
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) |
|||
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l) |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active interfaces.\n\n" |
|||
echo -en "Manually specify the IP in ${selfname}\n" |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use in ${selfname}.\n" |
|||
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" |
|||
echo -en "${getip}\n" |
|||
exit |
|||
else |
|||
else |
|||
ip=${getip} |
|||
fi |
|||
fi |
|||
} |
|||
|
|||
fn_logmanager(){ |
|||
if [ ! -e ${consolelog} ]; then |
|||
touch ${consolelog} |
|||
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 |
|||
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} |
|||
fn_scriptlog "Starting log cleaner" |
|||
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} |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) |
|||
consolecount=$(find ${consolelogdir}/* -mtime +${logdays}|wc -l) |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog} |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
fi |
|||
} |
|||
|
|||
@ -120,6 +135,7 @@ fn_debugserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
echo "" |
|||
echo "${gamename} Debug" |
|||
echo "============================" |
|||
@ -128,6 +144,9 @@ echo -e "Use for identifying server issues only!" |
|||
echo -e "Press CTRL+c to drop out of debug mode" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped" |
|||
echo "" |
|||
echo "Start parameters:" |
|||
echo ${parms} |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
@ -140,11 +159,11 @@ fn_stopserver |
|||
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} |
|||
fn_scriptlog "Started debug mode ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd ${filesdir} |
|||
./hlds_run ${parms} -debug |
|||
cd "${executabledir}" |
|||
${executable} ${parms} -debug |
|||
} |
|||
|
|||
fn_console(){ |
|||
@ -170,7 +189,7 @@ 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\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
@ -203,7 +222,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 |
|||
@ -222,14 +241,14 @@ fi |
|||
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} |
|||
fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd ${rootdir} |
|||
mkdir ${backupdir} > /dev/null 2>&1 |
|||
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * |
|||
cd "${rootdir}" |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" * |
|||
echo -en "\r\033[K${servicename} Backup complete" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} |
|||
fn_scriptlog "Backup complete" |
|||
} |
|||
|
|||
fn_distro(){ |
|||
@ -255,7 +274,7 @@ days=$(( uptime/60/60/24 )) |
|||
} |
|||
|
|||
fn_load(){ |
|||
load=$(uptime | awk -F 'load average' '{ print $2 }') |
|||
load=$(uptime|awk -F 'load average' '{ print $2 }') |
|||
} |
|||
|
|||
fn_emailnotification(){ |
|||
@ -279,19 +298,19 @@ fn_load |
|||
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 |
|||
echo -e "\n\nConsole log\n====================\n" >> ${emaillog} |
|||
tail -25 ${consolelog} >> ${emaillog} |
|||
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1 |
|||
tail -25 "${scriptlog}" >> "${emaillog}" |
|||
if [ ! -z "${consolelog}" ]; then |
|||
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}" |
|||
tail -25 "${consolelog}" >> "${emaillog}" |
|||
fi |
|||
if [ ! -z ${gamelogdir} ]; then |
|||
echo -e "\n\nServer log\n====================\n" >> ${emaillog} |
|||
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog} |
|||
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} |
|||
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} |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
} |
|||
@ -299,7 +318,7 @@ echo -en "\n" |
|||
fn_emailtest(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} |
|||
fn_scriptlog "Emailing test notification" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
subject="${servicename} Email Test Notification - Testing ${servername}" |
|||
failurereason="Testing ${servicename} email notification" |
|||
@ -307,7 +326,7 @@ if [ "${emailnotification}" = "on" ]; then |
|||
fn_emailnotification |
|||
else |
|||
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} |
|||
fn_scriptlog "Email notification not enabled" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -317,23 +336,23 @@ fn_serverquery(){ |
|||
# uses gsquery.py to directly query the server |
|||
# detects if the server locks up |
|||
if [ -f gsquery.py ]; then |
|||
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; 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} |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
@ -346,13 +365,13 @@ if [ -f gsquery.py ]; then |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
elif [ "${exitcode}" == "126" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "Attempting to resolve automatically" |
|||
@ -370,11 +389,11 @@ if [ -f gsquery.py ]; then |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
exit |
|||
fi |
|||
fi |
|||
} |
|||
@ -384,41 +403,41 @@ fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: CHECKING" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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} |
|||
fn_scriptlog "Checking session: FAIL" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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 |
|||
fn_scriptlog "Monitor is starting ${servername}" |
|||
fn_startserver |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} |
|||
fn_scriptlog "When updates complete ${servicename} will start" |
|||
fi |
|||
} |
|||
|
|||
@ -428,14 +447,14 @@ fn_syscheck |
|||
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 anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog} |
|||
fn_scriptlog "Updating ${servername}" |
|||
cd "${rootdir}" |
|||
cd "steamcmd" |
|||
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" |
|||
} |
|||
|
|||
fn_restartserver(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Restarting ${servername}" |
|||
fn_stopserver |
|||
fn_startserver |
|||
} |
|||
@ -445,15 +464,15 @@ fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 0.5 |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already stopped" |
|||
else |
|||
tmux kill-session -t ${servicename} |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopped ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -463,65 +482,70 @@ fn_startserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
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} |
|||
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} |
|||
fn_scriptlog "Starting ${servername}" |
|||
sleep 0.5 |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
cd ${filesdir} |
|||
tmux new-session -d -s ${servicename} "./hlds_run ${parms} |tee -a ${consolelog}" |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${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\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} |
|||
fn_scriptlog "failed to start ${servername}" |
|||
else |
|||
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} |
|||
fn_scriptlog "Started ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_details(){ |
|||
fn_autoip |
|||
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') |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo "" |
|||
echo "${gamename} Server Details" |
|||
echo "============================" |
|||
echo "Server name: ${servername}" |
|||
echo "Server IP: ${ip}:${port}" |
|||
echo "RCON password: ${rcon}" |
|||
echo "Config file: ${servercfg}" |
|||
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 "Ports the server is currently using." |
|||
echo "" |
|||
echo "DIRECTION DESCRIPTION PORT" |
|||
echo "INBOUND Game/Rcon Port ${port}" |
|||
echo "INBOUND Game/RCON port ${port}" |
|||
if [ "${engine}" = "source" ]; then |
|||
echo "INBOUND SourceTV Port ${sourcetvport}" |
|||
echo "INBOUND SourceTV port ${sourcetvport}" |
|||
fi |
|||
echo "OUTBOUND Client Port ${clientport}" |
|||
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 "start parameters in ${selfname}." |
|||
echo "" |
|||
echo "Config file:" |
|||
echo "${servercfg}" |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" |
|||
else |
|||
echo -e "Status:\e[0;32m ONLINE\e[0;39m" |
|||
fi |
|||
echo "" |
|||
} |
|||
|
|||
@ -529,11 +553,24 @@ echo "" |
|||
## Installer |
|||
# |
|||
|
|||
fn_csczappmanifest(){ |
|||
echo "Downloading appmanifest files (app 90 fix)" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -v "${filesdir}/1ea271ace3aa6eb2cbade5b6f37851d19ffb9e6f" |
|||
cd "${filesdir}/1ea271ace3aa6eb2cbade5b6f37851d19ffb9e6f" |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_10.acf |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_70.acf |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_80.acf |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_90.acf |
|||
echo "" |
|||
} |
|||
|
|||
fn_header(){ |
|||
clear |
|||
echo "=================================" |
|||
echo "${gamename}" |
|||
echo "Server Linux Installer" |
|||
echo "Linux Game Server Manager" |
|||
echo "by Daniel Gibbs" |
|||
echo "http://danielgibbs.co.uk" |
|||
echo "=================================" |
|||
@ -541,19 +578,73 @@ echo "" |
|||
} |
|||
|
|||
fn_steamdl(){ |
|||
echo "Installing Steam" |
|||
echo "Installing SteamCMD" |
|||
echo "=================================" |
|||
cd ${rootdir} |
|||
mkdir steamcmd |
|||
cd steamcmd |
|||
cd "${rootdir}" |
|||
mkdir -pv "steamcmd" |
|||
sleep 1 |
|||
cd "steamcmd" |
|||
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 |
|||
chmod +x steamcmd.sh |
|||
sleep 1 |
|||
else |
|||
echo "" |
|||
echo "Steam already installed!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_steaminstall(){ |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${filesdir}" |
|||
cd "${rootdir}/steamcmd" |
|||
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamfix(){ |
|||
echo "Applying steamclient.so fix" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv ${HOME}/.steam |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_loginstall(){ |
|||
echo "Creating log directorys" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
touch "${scriptlog}" |
|||
mkdir -pv "${consolelogdir}" |
|||
touch "${consolelog}" |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv "${gamelogdir}" "${rootdir}/log/server" |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_retryinstall(){ |
|||
@ -570,20 +661,19 @@ done |
|||
fn_install(){ |
|||
fn_rootcheck |
|||
fn_header |
|||
if [ -d ${filesdir} ]; then |
|||
if [ -d "${filesdir}" ]; then |
|||
echo "${gamename} Server is already installed here:" |
|||
pwd |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Yy]* ) fn_header; break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
fn_header |
|||
echo "Install Directory:" |
|||
pwd |
|||
echo "" |
|||
@ -597,63 +687,24 @@ while true; do |
|||
done |
|||
fn_header |
|||
fn_steamdl |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
rm -f ${servercfg} |
|||
mkdir -v ${filesdir} |
|||
echo "" |
|||
echo "Downloading appmanifest files (app 90 fix)" |
|||
echo "=================================" |
|||
sleep 2 |
|||
mkdir -v ${filesdir}/1ea271ace3aa6eb2cbade5b6f37851d19ffb9e6f |
|||
cd ${filesdir}/1ea271ace3aa6eb2cbade5b6f37851d19ffb9e6f |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_10.acf |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_70.acf |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_80.acf |
|||
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_90.acf |
|||
echo "Downloading appmanifest files (app 90 fix)" |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
cd ${rootdir}/steamcmd |
|||
touch install.txt |
|||
chmod 0600 install.txt |
|||
echo "login anonymous" > install.txt |
|||
echo "force_install_dir ${filesdir}" >> install.txt |
|||
echo "app_update ${appid} validate" >> install.txt |
|||
echo "quit" >> install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
rm install.txt |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall ;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fn_header |
|||
fn_csczappmanifest |
|||
fn_steaminstall |
|||
fn_steamfix |
|||
fn_loginstall |
|||
echo "Configuring ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
read -p "Enter server name: " servername |
|||
read -p "Enter rcon password: " rconpass |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating server.cfg" |
|||
touch ${filesdir}/czero/server.cfg |
|||
echo "exec ${servicename}.cfg" > ${filesdir}/czero/server.cfg |
|||
echo "Creating server.cfg." |
|||
touch "${defaultcfg}" |
|||
echo "exec ${servicename}.cfg" > "${defaultcfg}" |
|||
sleep 1 |
|||
echo "Creating default config file:" |
|||
sleep 0.5 |
|||
echo "${servercfg}" |
|||
touch ${servercfg} |
|||
touch ${filesdir}/czero/listip.cfg |
|||
touch ${filesdir}/czero/banned.cfg |
|||
echo "Creating ${servicename}.cfg config file." |
|||
touch "${servercfg}" |
|||
touch "${systemdir}/listip.cfg" |
|||
touch "${systemdir}/banned.cfg" |
|||
{ |
|||
echo -e "// Use this file to configure your DEDICATED server." |
|||
echo -e "// This config file is executed on server start." |
|||
@ -692,28 +743,13 @@ echo "=================================" |
|||
echo -e "sv_logecho 1" |
|||
echo -e "sv_logfile 1" |
|||
echo -e "sv_log_onefile 0" |
|||
}|tee ${servercfg} > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating log directorys" |
|||
mkdir -v ${rootdir}/log |
|||
mkdir -v ${scriptlogdir} |
|||
mkdir -v ${consolelogdir} |
|||
touch ${consolelog} |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv ${gamelogdir} ${rootdir}/log/server |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
}|tee "${servercfg}" > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
echo "Applying steamclient.so fix" |
|||
mkdir -v ${HOME}/.steam |
|||
mkdir -v ${HOME}/.steam/sdk32 |
|||
cp -v ${filesdir}/steamclient.so ${HOME}/.steam/sdk32/steamclient.so |
|||
sleep 1 |
|||
fn_header |
|||
sleep 1 |
|||
fn_details |
|||
sleep 1 |
|||
echo "=================================" |
|||
echo "Install Complete!" |
|||
echo "" |
|||
|
@ -3,7 +3,7 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 251213 |
|||
# Version: 240114 |
|||
|
|||
#### Variables #### |
|||
|
|||
@ -12,6 +12,10 @@ |
|||
emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="anonymous" |
|||
steampass="" |
|||
|
|||
# Start Variables |
|||
# [Game Modes] game_mode game_type |
|||
# Classic Casual 0 0 |
|||
@ -20,16 +24,28 @@ email="[email protected]" |
|||
# Demolition 1 1 |
|||
gamemode="0" |
|||
gametype="0" |
|||
<<<<<<< HEAD |
|||
defaultmap="de_dust" |
|||
mapgroup="random_classic" |
|||
maxplayers="16" |
|||
======= |
|||
defaultmap="de_dust2" |
|||
mapgroup="random_classic" |
|||
>>>>>>> Major update 240114 |
|||
port="27015" |
|||
sourcetvport="27020" |
|||
clientport="27005" |
|||
ip="0.0.0.0" |
|||
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server |
|||
<<<<<<< HEAD |
|||
# Change the parameter "-maxplayers" to "-maxplayers_override" for force the max player limit |
|||
parms="-game csgo -usercon +map ${defaultmap} +mapgroup ${defaultmap} +game_mode ${gamemode} +game_type ${gametype} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}" |
|||
======= |
|||
# https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Dedicated_Servers#Starting_the_Server |
|||
fn_parms(){ |
|||
parms="-game csgo -usercon +map ${defaultmap} +mapgroup ${mapgroup} +game_mode ${gamemode} +game_type ${gametype} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}" |
|||
} |
|||
>>>>>>> Major update 240114 |
|||
|
|||
#### Advanced Variables #### |
|||
|
|||
@ -45,16 +61,21 @@ engine="source" |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
filesdir="${rootdir}/serverfiles" |
|||
servercfg="${filesdir}/csgo/cfg/${servicename}.cfg" |
|||
systemdir="${filesdir}/csgo" |
|||
executabledir="${filesdir}" |
|||
executable="./srcds_run" |
|||
servercfg="${systemdir}/cfg/${servicename}.cfg" |
|||
defaultcfg="${systemdir}/cfg/server.cfg" |
|||
backupdir="backups" |
|||
steamclient="${filesdir}/bin/steamclient.so" |
|||
|
|||
# Server Details |
|||
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') |
|||
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') |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${filesdir}/csgo/logs" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
|
|||
@ -70,6 +91,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- |
|||
# unless you know |
|||
# what you are doing |
|||
|
|||
fn_scriptlog(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} |
|||
} |
|||
|
|||
fn_rootcheck(){ |
|||
if [ `whoami` = "root" ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" |
|||
@ -78,8 +103,8 @@ fi |
|||
} |
|||
|
|||
fn_syscheck(){ |
|||
if [ ! -e ${filesdir} ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: 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 |
|||
} |
|||
@ -87,42 +112,42 @@ fi |
|||
fn_autoip(){ |
|||
# Identifies the server interface IP |
|||
# If multiple interfaces this will need to be set manually |
|||
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) |
|||
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l) |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active interfaces.\n\n" |
|||
echo -en "Manually specify the IP in ${selfname}\n" |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use in ${selfname}.\n" |
|||
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" |
|||
echo -en "${getip}\n" |
|||
exit |
|||
else |
|||
else |
|||
ip=${getip} |
|||
fi |
|||
fi |
|||
} |
|||
|
|||
fn_logmanager(){ |
|||
if [ ! -e ${consolelog} ]; then |
|||
touch ${consolelog} |
|||
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 |
|||
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} |
|||
fn_scriptlog "Starting log cleaner" |
|||
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} |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) |
|||
consolecount=$(find ${consolelogdir}/* -mtime +${logdays}|wc -l) |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog} |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
fi |
|||
} |
|||
|
|||
@ -130,6 +155,7 @@ fn_debugserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
echo "" |
|||
echo "${gamename} Debug" |
|||
echo "============================" |
|||
@ -138,6 +164,9 @@ echo -e "Use for identifying server issues only!" |
|||
echo -e "Press CTRL+c to drop out of debug mode" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped" |
|||
echo "" |
|||
echo "Start parameters:" |
|||
echo ${parms} |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
@ -150,11 +179,11 @@ fn_stopserver |
|||
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} |
|||
fn_scriptlog "Started debug mode ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd ${filesdir} |
|||
./srcds_run ${parms} -debug |
|||
cd "${executabledir}" |
|||
${executable} ${parms} -debug |
|||
} |
|||
|
|||
fn_console(){ |
|||
@ -180,7 +209,7 @@ 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\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
@ -213,7 +242,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 |
|||
@ -232,14 +261,14 @@ fi |
|||
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} |
|||
fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd ${rootdir} |
|||
mkdir ${backupdir} > /dev/null 2>&1 |
|||
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * |
|||
cd "${rootdir}" |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" * |
|||
echo -en "\r\033[K${servicename} Backup complete" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} |
|||
fn_scriptlog "Backup complete" |
|||
} |
|||
|
|||
fn_distro(){ |
|||
@ -265,7 +294,7 @@ days=$(( uptime/60/60/24 )) |
|||
} |
|||
|
|||
fn_load(){ |
|||
load=$(uptime | awk -F 'load average' '{ print $2 }') |
|||
load=$(uptime|awk -F 'load average' '{ print $2 }') |
|||
} |
|||
|
|||
fn_emailnotification(){ |
|||
@ -289,19 +318,19 @@ fn_load |
|||
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 |
|||
echo -e "\n\nConsole log\n====================\n" >> ${emaillog} |
|||
tail -25 ${consolelog} >> ${emaillog} |
|||
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1 |
|||
tail -25 "${scriptlog}" >> "${emaillog}" |
|||
if [ ! -z "${consolelog}" ]; then |
|||
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}" |
|||
tail -25 "${consolelog}" >> "${emaillog}" |
|||
fi |
|||
if [ ! -z ${gamelogdir} ]; then |
|||
echo -e "\n\nServer log\n====================\n" >> ${emaillog} |
|||
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog} |
|||
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} |
|||
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} |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
} |
|||
@ -309,7 +338,7 @@ echo -en "\n" |
|||
fn_emailtest(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} |
|||
fn_scriptlog "Emailing test notification" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
subject="${servicename} Email Test Notification - Testing ${servername}" |
|||
failurereason="Testing ${servicename} email notification" |
|||
@ -317,7 +346,7 @@ if [ "${emailnotification}" = "on" ]; then |
|||
fn_emailnotification |
|||
else |
|||
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} |
|||
fn_scriptlog "Email notification not enabled" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -327,23 +356,23 @@ fn_serverquery(){ |
|||
# uses gsquery.py to directly query the server |
|||
# detects if the server locks up |
|||
if [ -f gsquery.py ]; then |
|||
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; 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} |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
@ -356,13 +385,13 @@ if [ -f gsquery.py ]; then |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
elif [ "${exitcode}" == "126" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "Attempting to resolve automatically" |
|||
@ -380,11 +409,11 @@ if [ -f gsquery.py ]; then |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
exit |
|||
fi |
|||
fi |
|||
} |
|||
@ -394,41 +423,41 @@ fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: CHECKING" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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} |
|||
fn_scriptlog "Checking session: FAIL" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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 |
|||
fn_scriptlog "Monitor is starting ${servername}" |
|||
fn_startserver |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} |
|||
fn_scriptlog "When updates complete ${servicename} will start" |
|||
fi |
|||
} |
|||
|
|||
@ -438,14 +467,14 @@ fn_syscheck |
|||
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 anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog} |
|||
fn_scriptlog "Updating ${servername}" |
|||
cd "${rootdir}" |
|||
cd "steamcmd" |
|||
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" |
|||
} |
|||
|
|||
fn_restartserver(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Restarting ${servername}" |
|||
fn_stopserver |
|||
fn_startserver |
|||
} |
|||
@ -455,15 +484,15 @@ fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 0.5 |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already stopped" |
|||
else |
|||
tmux kill-session -t ${servicename} |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopped ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -473,65 +502,70 @@ fn_startserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
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} |
|||
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} |
|||
fn_scriptlog "Starting ${servername}" |
|||
sleep 0.5 |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
cd ${filesdir} |
|||
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${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\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} |
|||
fn_scriptlog "failed to start ${servername}" |
|||
else |
|||
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} |
|||
fn_scriptlog "Started ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_details(){ |
|||
fn_autoip |
|||
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') |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo "" |
|||
echo "${gamename} Server Details" |
|||
echo "============================" |
|||
echo "Server name: ${servername}" |
|||
echo "Server IP: ${ip}:${port}" |
|||
echo "RCON password: ${rcon}" |
|||
echo "Config file: ${servercfg}" |
|||
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 "Ports the server is currently using." |
|||
echo "" |
|||
echo "DIRECTION DESCRIPTION PORT" |
|||
echo "INBOUND Game/Rcon Port ${port}" |
|||
echo "INBOUND Game/RCON port ${port}" |
|||
if [ "${engine}" = "source" ]; then |
|||
echo "INBOUND SourceTV Port ${sourcetvport}" |
|||
echo "INBOUND SourceTV port ${sourcetvport}" |
|||
fi |
|||
echo "OUTBOUND Client Port ${clientport}" |
|||
echo "OUTBOUND Client port ${clientport}" |
|||
echo "" |
|||
echo "You can change ports by editing the" |
|||
echo "start parameters in ${selfname}" |
|||
echo "start parameters in ${selfname}." |
|||
echo "" |
|||
echo "${servername} Details" |
|||
echo "=======================" |
|||
echo "Server name: ${servername}" |
|||
echo "Rcon Password: ${rcon}" |
|||
echo "" |
|||
echo "Config file:" |
|||
echo "${servercfg}" |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" |
|||
else |
|||
echo -e "Status:\e[0;32m ONLINE\e[0;39m" |
|||
fi |
|||
echo "" |
|||
} |
|||
|
|||
@ -543,7 +577,7 @@ fn_header(){ |
|||
clear |
|||
echo "=================================" |
|||
echo "${gamename}" |
|||
echo "Server Linux Installer" |
|||
echo "Linux Game Server Manager" |
|||
echo "by Daniel Gibbs" |
|||
echo "http://danielgibbs.co.uk" |
|||
echo "=================================" |
|||
@ -551,19 +585,73 @@ echo "" |
|||
} |
|||
|
|||
fn_steamdl(){ |
|||
echo "Installing Steam" |
|||
echo "Installing SteamCMD" |
|||
echo "=================================" |
|||
cd ${rootdir} |
|||
mkdir steamcmd |
|||
cd steamcmd |
|||
cd "${rootdir}" |
|||
mkdir -pv "steamcmd" |
|||
sleep 1 |
|||
cd "steamcmd" |
|||
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 |
|||
chmod +x steamcmd.sh |
|||
sleep 1 |
|||
else |
|||
echo "" |
|||
echo "Steam already installed!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_steaminstall(){ |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${filesdir}" |
|||
cd "${rootdir}/steamcmd" |
|||
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamfix(){ |
|||
echo "Applying steamclient.so fix" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv ${HOME}/.steam |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_loginstall(){ |
|||
echo "Creating log directorys" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
touch "${scriptlog}" |
|||
mkdir -pv "${consolelogdir}" |
|||
touch "${consolelog}" |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv "${gamelogdir}" "${rootdir}/log/server" |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_retryinstall(){ |
|||
@ -580,20 +668,19 @@ done |
|||
fn_install(){ |
|||
fn_rootcheck |
|||
fn_header |
|||
if [ -d ${filesdir} ]; then |
|||
if [ -d "${filesdir}" ]; then |
|||
echo "${gamename} Server is already installed here:" |
|||
pwd |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Yy]* ) fn_header; break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
fn_header |
|||
echo "Install Directory:" |
|||
pwd |
|||
echo "" |
|||
@ -607,44 +694,21 @@ while true; do |
|||
done |
|||
fn_header |
|||
fn_steamdl |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
cd ${rootdir}/steamcmd |
|||
mkdir -v ${filesdir} |
|||
touch install.txt |
|||
chmod 0600 install.txt |
|||
echo "login anonymous" > install.txt |
|||
echo "force_install_dir ${filesdir}" >> install.txt |
|||
echo "app_update ${appid} validate" >> install.txt |
|||
echo "quit" >> install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
rm install.txt |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fn_header |
|||
fn_steaminstall |
|||
fn_steamfix |
|||
fn_loginstall |
|||
echo "Configuring ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
read -p "Enter server name: " servername |
|||
read -p "Enter rcon password: " rconpass |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating server.cfg" |
|||
touch ${filesdir}/csgo/cfg/server.cfg |
|||
echo "exec ${servicename}.cfg" > ${filesdir}/csgo/cfg/server.cfg |
|||
echo "Creating server.cfg." |
|||
touch "${defaultcfg}" |
|||
echo "exec ${servicename}.cfg" > "${defaultcfg}" |
|||
sleep 1 |
|||
echo "Creating default config file:" |
|||
sleep 0.5 |
|||
echo "${servercfg}" |
|||
touch ${servercfg} |
|||
echo "Creating ${servicename}.cfg config file." |
|||
touch "${servercfg}" |
|||
{ |
|||
echo -e "// server name" |
|||
echo -e "hostname \"${servername}\"" |
|||
@ -661,28 +725,13 @@ echo "=================================" |
|||
echo -e "sv_logecho 1" |
|||
echo -e "sv_logfile 1" |
|||
echo -e "sv_log_onefile 0" |
|||
}|tee ${servercfg} > /dev/null 2>&1 |
|||
}|tee "${servercfg}" > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating log directorys" |
|||
mkdir -v ${rootdir}/log |
|||
mkdir -v ${scriptlogdir} |
|||
mkdir -v ${consolelogdir} |
|||
touch ${consolelog} |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv ${gamelogdir} ${rootdir}/log/server |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
echo "Applying steamclient.so fix" |
|||
mkdir -v ${HOME}/.steam |
|||
mkdir -v ${HOME}/.steam/sdk32 |
|||
cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so |
|||
sleep 1 |
|||
fn_header |
|||
sleep 1 |
|||
fn_details |
|||
sleep 1 |
|||
echo "=================================" |
|||
echo "Install Complete!" |
|||
echo "" |
|||
|
@ -3,7 +3,7 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 251213 |
|||
# Version: 240114 |
|||
|
|||
#### Variables #### |
|||
|
|||
@ -12,15 +12,21 @@ |
|||
emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="anonymous" |
|||
steampass="" |
|||
|
|||
# Start Variables |
|||
defaultmap="de_dust" |
|||
defaultmap="de_dust2" |
|||
port="27015" |
|||
sourcetvport="27020" |
|||
clientport="27005" |
|||
maxplayers="16" |
|||
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}" |
|||
fn_parms(){ |
|||
parms="-game cstrike +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}" |
|||
} |
|||
|
|||
#### Advanced Variables #### |
|||
|
|||
@ -36,16 +42,21 @@ engine="source" |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
filesdir="${rootdir}/serverfiles" |
|||
servercfg="${filesdir}/cstrike/cfg/${servicename}.cfg" |
|||
systemdir="${filesdir}/cstrike" |
|||
executabledir="${filesdir}" |
|||
executable="./srcds_run" |
|||
servercfg="${systemdir}/cfg/${servicename}.cfg" |
|||
defaultcfg="${systemdir}/cfg/server.cfg" |
|||
backupdir="backups" |
|||
steamclient="${filesdir}/bin/steamclient.so" |
|||
|
|||
# Server Details |
|||
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') |
|||
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') |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${filesdir}/cstrike/logs" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
|
|||
@ -61,6 +72,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- |
|||
# unless you know |
|||
# what you are doing |
|||
|
|||
fn_scriptlog(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} |
|||
} |
|||
|
|||
fn_rootcheck(){ |
|||
if [ `whoami` = "root" ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" |
|||
@ -69,8 +84,8 @@ fi |
|||
} |
|||
|
|||
fn_syscheck(){ |
|||
if [ ! -e ${filesdir} ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: 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 |
|||
} |
|||
@ -78,42 +93,42 @@ fi |
|||
fn_autoip(){ |
|||
# Identifies the server interface IP |
|||
# If multiple interfaces this will need to be set manually |
|||
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) |
|||
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l) |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active interfaces.\n\n" |
|||
echo -en "Manually specify the IP in ${selfname}\n" |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use in ${selfname}.\n" |
|||
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" |
|||
echo -en "${getip}\n" |
|||
exit |
|||
else |
|||
else |
|||
ip=${getip} |
|||
fi |
|||
fi |
|||
} |
|||
|
|||
fn_logmanager(){ |
|||
if [ ! -e ${consolelog} ]; then |
|||
touch ${consolelog} |
|||
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 |
|||
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} |
|||
fn_scriptlog "Starting log cleaner" |
|||
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} |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) |
|||
consolecount=$(find ${consolelogdir}/* -mtime +${logdays}|wc -l) |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog} |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
fi |
|||
} |
|||
|
|||
@ -121,6 +136,7 @@ fn_debugserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
echo "" |
|||
echo "${gamename} Debug" |
|||
echo "============================" |
|||
@ -129,6 +145,9 @@ echo -e "Use for identifying server issues only!" |
|||
echo -e "Press CTRL+c to drop out of debug mode" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped" |
|||
echo "" |
|||
echo "Start parameters:" |
|||
echo ${parms} |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
@ -141,11 +160,11 @@ fn_stopserver |
|||
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} |
|||
fn_scriptlog "Started debug mode ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd ${filesdir} |
|||
./srcds_run ${parms} -debug |
|||
cd "${executabledir}" |
|||
${executable} ${parms} -debug |
|||
} |
|||
|
|||
fn_console(){ |
|||
@ -171,7 +190,7 @@ 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\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
@ -223,14 +242,14 @@ fi |
|||
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} |
|||
fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd ${rootdir} |
|||
mkdir ${backupdir} > /dev/null 2>&1 |
|||
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * |
|||
cd "${rootdir}" |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" * |
|||
echo -en "\r\033[K${servicename} Backup complete" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} |
|||
fn_scriptlog "Backup complete" |
|||
} |
|||
|
|||
fn_distro(){ |
|||
@ -256,7 +275,7 @@ days=$(( uptime/60/60/24 )) |
|||
} |
|||
|
|||
fn_load(){ |
|||
load=$(uptime | awk -F 'load average' '{ print $2 }') |
|||
load=$(uptime|awk -F 'load average' '{ print $2 }') |
|||
} |
|||
|
|||
fn_emailnotification(){ |
|||
@ -280,19 +299,19 @@ fn_load |
|||
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 |
|||
echo -e "\n\nConsole log\n====================\n" >> ${emaillog} |
|||
tail -25 ${consolelog} >> ${emaillog} |
|||
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1 |
|||
tail -25 "${scriptlog}" >> "${emaillog}" |
|||
if [ ! -z "${consolelog}" ]; then |
|||
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}" |
|||
tail -25 "${consolelog}" >> "${emaillog}" |
|||
fi |
|||
if [ ! -z ${gamelogdir} ]; then |
|||
echo -e "\n\nServer log\n====================\n" >> ${emaillog} |
|||
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog} |
|||
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} |
|||
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} |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
} |
|||
@ -300,7 +319,7 @@ echo -en "\n" |
|||
fn_emailtest(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} |
|||
fn_scriptlog "Emailing test notification" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
subject="${servicename} Email Test Notification - Testing ${servername}" |
|||
failurereason="Testing ${servicename} email notification" |
|||
@ -308,7 +327,7 @@ if [ "${emailnotification}" = "on" ]; then |
|||
fn_emailnotification |
|||
else |
|||
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} |
|||
fn_scriptlog "Email notification not enabled" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -318,23 +337,23 @@ fn_serverquery(){ |
|||
# uses gsquery.py to directly query the server |
|||
# detects if the server locks up |
|||
if [ -f gsquery.py ]; then |
|||
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; 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} |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
@ -347,13 +366,13 @@ if [ -f gsquery.py ]; then |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
elif [ "${exitcode}" == "126" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "Attempting to resolve automatically" |
|||
@ -371,11 +390,11 @@ if [ -f gsquery.py ]; then |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
exit |
|||
fi |
|||
fi |
|||
} |
|||
@ -385,41 +404,41 @@ fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: CHECKING" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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} |
|||
fn_scriptlog "Checking session: FAIL" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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 |
|||
fn_scriptlog "Monitor is starting ${servername}" |
|||
fn_startserver |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} |
|||
fn_scriptlog "When updates complete ${servicename} will start" |
|||
fi |
|||
} |
|||
|
|||
@ -429,14 +448,14 @@ fn_syscheck |
|||
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 anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog} |
|||
fn_scriptlog "Updating ${servername}" |
|||
cd "${rootdir}" |
|||
cd "steamcmd" |
|||
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" |
|||
} |
|||
|
|||
fn_restartserver(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Restarting ${servername}" |
|||
fn_stopserver |
|||
fn_startserver |
|||
} |
|||
@ -446,15 +465,15 @@ fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 0.5 |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already stopped" |
|||
else |
|||
tmux kill-session -t ${servicename} |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopped ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -464,65 +483,70 @@ fn_startserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
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} |
|||
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} |
|||
fn_scriptlog "Starting ${servername}" |
|||
sleep 0.5 |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
cd ${filesdir} |
|||
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${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\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} |
|||
fn_scriptlog "failed to start ${servername}" |
|||
else |
|||
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} |
|||
fn_scriptlog "Started ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_details(){ |
|||
fn_autoip |
|||
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') |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo "" |
|||
echo "${gamename} Server Details" |
|||
echo "============================" |
|||
echo "Server name: ${servername}" |
|||
echo "Server IP: ${ip}:${port}" |
|||
echo "RCON password: ${rcon}" |
|||
echo "Config file: ${servercfg}" |
|||
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 "Ports the server is currently using." |
|||
echo "" |
|||
echo "DIRECTION DESCRIPTION PORT" |
|||
echo "INBOUND Game/Rcon Port ${port}" |
|||
echo "INBOUND Game/RCON port ${port}" |
|||
if [ "${engine}" = "source" ]; then |
|||
echo "INBOUND SourceTV Port ${sourcetvport}" |
|||
echo "INBOUND SourceTV port ${sourcetvport}" |
|||
fi |
|||
echo "OUTBOUND Client Port ${clientport}" |
|||
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 "start parameters in ${selfname}." |
|||
echo "" |
|||
echo "Config file:" |
|||
echo "${servercfg}" |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" |
|||
else |
|||
echo -e "Status:\e[0;32m ONLINE\e[0;39m" |
|||
fi |
|||
echo "" |
|||
} |
|||
|
|||
@ -534,7 +558,7 @@ fn_header(){ |
|||
clear |
|||
echo "=================================" |
|||
echo "${gamename}" |
|||
echo "Server Linux Installer" |
|||
echo "Linux Game Server Manager" |
|||
echo "by Daniel Gibbs" |
|||
echo "http://danielgibbs.co.uk" |
|||
echo "=================================" |
|||
@ -542,19 +566,73 @@ echo "" |
|||
} |
|||
|
|||
fn_steamdl(){ |
|||
echo "Installing Steam" |
|||
echo "Installing SteamCMD" |
|||
echo "=================================" |
|||
cd ${rootdir} |
|||
mkdir steamcmd |
|||
cd steamcmd |
|||
cd "${rootdir}" |
|||
mkdir -pv "steamcmd" |
|||
sleep 1 |
|||
cd "steamcmd" |
|||
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 |
|||
chmod +x steamcmd.sh |
|||
sleep 1 |
|||
else |
|||
echo "" |
|||
echo "Steam already installed!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_steaminstall(){ |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${filesdir}" |
|||
cd "${rootdir}/steamcmd" |
|||
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamfix(){ |
|||
echo "Applying steamclient.so fix" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv ${HOME}/.steam |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_loginstall(){ |
|||
echo "Creating log directorys" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
touch "${scriptlog}" |
|||
mkdir -pv "${consolelogdir}" |
|||
touch "${consolelog}" |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv "${gamelogdir}" "${rootdir}/log/server" |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_retryinstall(){ |
|||
@ -571,20 +649,19 @@ done |
|||
fn_install(){ |
|||
fn_rootcheck |
|||
fn_header |
|||
if [ -d ${filesdir} ]; then |
|||
if [ -d "${filesdir}" ]; then |
|||
echo "${gamename} Server is already installed here:" |
|||
pwd |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Yy]* ) fn_header; break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
fn_header |
|||
echo "Install Directory:" |
|||
pwd |
|||
echo "" |
|||
@ -598,44 +675,21 @@ while true; do |
|||
done |
|||
fn_header |
|||
fn_steamdl |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
cd ${rootdir}/steamcmd |
|||
mkdir -v ${filesdir} |
|||
touch install.txt |
|||
chmod 0600 install.txt |
|||
echo "login anonymous" > install.txt |
|||
echo "force_install_dir ${filesdir}" >> install.txt |
|||
echo "app_update ${appid} validate" >> install.txt |
|||
echo "quit" >> install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
rm install.txt |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fn_header |
|||
fn_steaminstall |
|||
fn_steamfix |
|||
fn_loginstall |
|||
echo "Configuring ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
read -p "Enter server name: " servername |
|||
read -p "Enter rcon password: " rconpass |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating server.cfg" |
|||
touch ${filesdir}/cstrike/cfg/server.cfg |
|||
echo "exec ${servicename}.cfg" > ${filesdir}/cstrike/cfg/server.cfg |
|||
echo "Creating server.cfg." |
|||
touch "${defaultcfg}" |
|||
echo "exec ${servicename}.cfg" > "${defaultcfg}" |
|||
sleep 1 |
|||
echo "Creating default config file:" |
|||
sleep 0.5 |
|||
echo "${servercfg}" |
|||
touch ${servercfg} |
|||
echo "Creating ${servicename}.cfg config file." |
|||
touch "${servercfg}" |
|||
{ |
|||
echo -e "// server name" |
|||
echo -e "hostname \"${servername}\"" |
|||
@ -652,28 +706,13 @@ echo "=================================" |
|||
echo -e "sv_logecho 1" |
|||
echo -e "sv_logfile 1" |
|||
echo -e "sv_log_onefile 0" |
|||
}|tee ${servercfg} > /dev/null 2>&1 |
|||
}|tee "${servercfg}" > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating log directorys" |
|||
mkdir -v ${rootdir}/log |
|||
mkdir -v ${scriptlogdir} |
|||
mkdir -v ${consolelogdir} |
|||
touch ${consolelog} |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv ${gamelogdir} ${rootdir}/log/server |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
echo "Applying steamclient.so fix" |
|||
mkdir -v ${HOME}/.steam |
|||
mkdir -v ${HOME}/.steam/sdk32 |
|||
cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so |
|||
sleep 1 |
|||
fn_header |
|||
sleep 1 |
|||
fn_details |
|||
sleep 1 |
|||
echo "=================================" |
|||
echo "Install Complete!" |
|||
echo "" |
|||
|
@ -3,7 +3,7 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 251213 |
|||
# Version: 240114 |
|||
|
|||
#### Variables #### |
|||
|
|||
@ -12,6 +12,10 @@ |
|||
emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="anonymous" |
|||
steampass="" |
|||
|
|||
# Start Variables |
|||
defaultmap="dod_Anzio" |
|||
port="27015" |
|||
@ -20,7 +24,9 @@ clientport="27005" |
|||
maxplayers="16" |
|||
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}" |
|||
fn_parms(){ |
|||
parms="-game dod +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}" |
|||
} |
|||
|
|||
#### Advanced Variables #### |
|||
|
|||
@ -36,16 +42,21 @@ engine="source" |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
filesdir="${rootdir}/serverfiles" |
|||
servercfg="${filesdir}/dod/cfg/${servicename}.cfg" |
|||
systemdir="${filesdir}/dod" |
|||
executabledir="${filesdir}" |
|||
executable="./srcds_run" |
|||
servercfg="${systemdir}/cfg/${servicename}.cfg" |
|||
defaultcfg="${systemdir}/cfg/server.cfg" |
|||
backupdir="backups" |
|||
steamclient="${filesdir}/bin/steamclient.so" |
|||
|
|||
# Server Details |
|||
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') |
|||
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') |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${filesdir}/dod/logs" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
|
|||
@ -61,6 +72,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- |
|||
# unless you know |
|||
# what you are doing |
|||
|
|||
fn_scriptlog(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} |
|||
} |
|||
|
|||
fn_rootcheck(){ |
|||
if [ `whoami` = "root" ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" |
|||
@ -69,8 +84,8 @@ fi |
|||
} |
|||
|
|||
fn_syscheck(){ |
|||
if [ ! -e ${filesdir} ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: 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 |
|||
} |
|||
@ -78,42 +93,42 @@ fi |
|||
fn_autoip(){ |
|||
# Identifies the server interface IP |
|||
# If multiple interfaces this will need to be set manually |
|||
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) |
|||
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l) |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active interfaces.\n\n" |
|||
echo -en "Manually specify the IP in ${selfname}\n" |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use in ${selfname}.\n" |
|||
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" |
|||
echo -en "${getip}\n" |
|||
exit |
|||
else |
|||
else |
|||
ip=${getip} |
|||
fi |
|||
fi |
|||
} |
|||
|
|||
fn_logmanager(){ |
|||
if [ ! -e ${consolelog} ]; then |
|||
touch ${consolelog} |
|||
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 |
|||
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} |
|||
fn_scriptlog "Starting log cleaner" |
|||
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} |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) |
|||
consolecount=$(find ${consolelogdir}/* -mtime +${logdays}|wc -l) |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog} |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
fi |
|||
} |
|||
|
|||
@ -121,6 +136,7 @@ fn_debugserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
echo "" |
|||
echo "${gamename} Debug" |
|||
echo "============================" |
|||
@ -129,6 +145,9 @@ echo -e "Use for identifying server issues only!" |
|||
echo -e "Press CTRL+c to drop out of debug mode" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped" |
|||
echo "" |
|||
echo "Start parameters:" |
|||
echo ${parms} |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
@ -141,11 +160,11 @@ fn_stopserver |
|||
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} |
|||
fn_scriptlog "Started debug mode ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd ${filesdir} |
|||
./srcds_run ${parms} -debug |
|||
cd "${executabledir}" |
|||
${executable} ${parms} -debug |
|||
} |
|||
|
|||
fn_console(){ |
|||
@ -171,7 +190,7 @@ 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\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
@ -204,7 +223,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 |
|||
@ -223,14 +242,14 @@ fi |
|||
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} |
|||
fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd ${rootdir} |
|||
mkdir ${backupdir} > /dev/null 2>&1 |
|||
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * |
|||
cd "${rootdir}" |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" * |
|||
echo -en "\r\033[K${servicename} Backup complete" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} |
|||
fn_scriptlog "Backup complete" |
|||
} |
|||
|
|||
fn_distro(){ |
|||
@ -256,7 +275,7 @@ days=$(( uptime/60/60/24 )) |
|||
} |
|||
|
|||
fn_load(){ |
|||
load=$(uptime | awk -F 'load average' '{ print $2 }') |
|||
load=$(uptime|awk -F 'load average' '{ print $2 }') |
|||
} |
|||
|
|||
fn_emailnotification(){ |
|||
@ -280,19 +299,19 @@ fn_load |
|||
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 |
|||
echo -e "\n\nConsole log\n====================\n" >> ${emaillog} |
|||
tail -25 ${consolelog} >> ${emaillog} |
|||
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1 |
|||
tail -25 "${scriptlog}" >> "${emaillog}" |
|||
if [ ! -z "${consolelog}" ]; then |
|||
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}" |
|||
tail -25 "${consolelog}" >> "${emaillog}" |
|||
fi |
|||
if [ ! -z ${gamelogdir} ]; then |
|||
echo -e "\n\nServer log\n====================\n" >> ${emaillog} |
|||
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog} |
|||
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} |
|||
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} |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
} |
|||
@ -300,7 +319,7 @@ echo -en "\n" |
|||
fn_emailtest(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} |
|||
fn_scriptlog "Emailing test notification" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
subject="${servicename} Email Test Notification - Testing ${servername}" |
|||
failurereason="Testing ${servicename} email notification" |
|||
@ -308,7 +327,7 @@ if [ "${emailnotification}" = "on" ]; then |
|||
fn_emailnotification |
|||
else |
|||
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} |
|||
fn_scriptlog "Email notification not enabled" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -318,23 +337,23 @@ fn_serverquery(){ |
|||
# uses gsquery.py to directly query the server |
|||
# detects if the server locks up |
|||
if [ -f gsquery.py ]; then |
|||
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; 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} |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
@ -347,13 +366,13 @@ if [ -f gsquery.py ]; then |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
elif [ "${exitcode}" == "126" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "Attempting to resolve automatically" |
|||
@ -371,11 +390,11 @@ if [ -f gsquery.py ]; then |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
exit |
|||
fi |
|||
fi |
|||
} |
|||
@ -385,41 +404,41 @@ fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: CHECKING" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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} |
|||
fn_scriptlog "Checking session: FAIL" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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 |
|||
fn_scriptlog "Monitor is starting ${servername}" |
|||
fn_startserver |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} |
|||
fn_scriptlog "When updates complete ${servicename} will start" |
|||
fi |
|||
} |
|||
|
|||
@ -429,14 +448,14 @@ fn_syscheck |
|||
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 anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog} |
|||
fn_scriptlog "Updating ${servername}" |
|||
cd "${rootdir}" |
|||
cd "steamcmd" |
|||
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" |
|||
} |
|||
|
|||
fn_restartserver(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Restarting ${servername}" |
|||
fn_stopserver |
|||
fn_startserver |
|||
} |
|||
@ -446,15 +465,15 @@ fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 0.5 |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already stopped" |
|||
else |
|||
tmux kill-session -t ${servicename} |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopped ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -464,65 +483,70 @@ fn_startserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
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} |
|||
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} |
|||
fn_scriptlog "Starting ${servername}" |
|||
sleep 0.5 |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
cd ${filesdir} |
|||
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${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\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} |
|||
fn_scriptlog "failed to start ${servername}" |
|||
else |
|||
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} |
|||
fn_scriptlog "Started ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_details(){ |
|||
fn_autoip |
|||
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') |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo "" |
|||
echo "${gamename} Server Details" |
|||
echo "============================" |
|||
echo "Server name: ${servername}" |
|||
echo "Server IP: ${ip}:${port}" |
|||
echo "RCON password: ${rcon}" |
|||
echo "Config file: ${servercfg}" |
|||
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 "Ports the server is currently using." |
|||
echo "" |
|||
echo "DIRECTION DESCRIPTION PORT" |
|||
echo "INBOUND Game/Rcon Port ${port}" |
|||
echo "INBOUND Game/RCON port ${port}" |
|||
if [ "${engine}" = "source" ]; then |
|||
echo "INBOUND SourceTV Port ${sourcetvport}" |
|||
echo "INBOUND SourceTV port ${sourcetvport}" |
|||
fi |
|||
echo "OUTBOUND Client Port ${clientport}" |
|||
echo "OUTBOUND Client port ${clientport}" |
|||
echo "" |
|||
echo "You can change ports by editing the" |
|||
echo "start parameters in ${selfname}" |
|||
echo "start parameters in ${selfname}." |
|||
echo "" |
|||
echo "${servername} Details" |
|||
echo "=======================" |
|||
echo "Server name: ${servername}" |
|||
echo "Rcon Password: ${rcon}" |
|||
echo "" |
|||
echo "Config file:" |
|||
echo "${servercfg}" |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" |
|||
else |
|||
echo -e "Status:\e[0;32m ONLINE\e[0;39m" |
|||
fi |
|||
echo "" |
|||
} |
|||
|
|||
@ -534,7 +558,7 @@ fn_header(){ |
|||
clear |
|||
echo "=================================" |
|||
echo "${gamename}" |
|||
echo "Server Linux Installer" |
|||
echo "Linux Game Server Manager" |
|||
echo "by Daniel Gibbs" |
|||
echo "http://danielgibbs.co.uk" |
|||
echo "=================================" |
|||
@ -542,19 +566,73 @@ echo "" |
|||
} |
|||
|
|||
fn_steamdl(){ |
|||
echo "Installing Steam" |
|||
echo "Installing SteamCMD" |
|||
echo "=================================" |
|||
cd ${rootdir} |
|||
mkdir steamcmd |
|||
cd steamcmd |
|||
cd "${rootdir}" |
|||
mkdir -pv "steamcmd" |
|||
sleep 1 |
|||
cd "steamcmd" |
|||
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 |
|||
chmod +x steamcmd.sh |
|||
sleep 1 |
|||
else |
|||
echo "" |
|||
echo "Steam already installed!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_steaminstall(){ |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${filesdir}" |
|||
cd "${rootdir}/steamcmd" |
|||
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamfix(){ |
|||
echo "Applying steamclient.so fix" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv ${HOME}/.steam |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_loginstall(){ |
|||
echo "Creating log directorys" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
touch "${scriptlog}" |
|||
mkdir -pv "${consolelogdir}" |
|||
touch "${consolelog}" |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv "${gamelogdir}" "${rootdir}/log/server" |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_retryinstall(){ |
|||
@ -571,20 +649,19 @@ done |
|||
fn_install(){ |
|||
fn_rootcheck |
|||
fn_header |
|||
if [ -d ${filesdir} ]; then |
|||
if [ -d "${filesdir}" ]; then |
|||
echo "${gamename} Server is already installed here:" |
|||
pwd |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Yy]* ) fn_header; break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
fn_header |
|||
echo "Install Directory:" |
|||
pwd |
|||
echo "" |
|||
@ -598,44 +675,21 @@ while true; do |
|||
done |
|||
fn_header |
|||
fn_steamdl |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
cd ${rootdir}/steamcmd |
|||
mkdir -v ${filesdir} |
|||
touch install.txt |
|||
chmod 0600 install.txt |
|||
echo "login anonymous" > install.txt |
|||
echo "force_install_dir ${filesdir}" >> install.txt |
|||
echo "app_update ${appid} validate" >> install.txt |
|||
echo "quit" >> install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
rm install.txt |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fn_header |
|||
fn_steaminstall |
|||
fn_steamfix |
|||
fn_loginstall |
|||
echo "Configuring ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
read -p "Enter server name: " servername |
|||
read -p "Enter rcon password: " rconpass |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating server.cfg" |
|||
touch ${filesdir}/dod/cfg/server.cfg |
|||
echo "exec ${servicename}.cfg" > ${filesdir}/dod/cfg/server.cfg |
|||
echo "Creating server.cfg." |
|||
touch "${defaultcfg}" |
|||
echo "exec ${servicename}.cfg" > "${defaultcfg}" |
|||
sleep 1 |
|||
echo "Creating default config file:" |
|||
sleep 0.5 |
|||
echo "${servercfg}" |
|||
touch ${servercfg} |
|||
echo "Creating ${servicename}.cfg config file." |
|||
touch "${servercfg}" |
|||
{ |
|||
echo -e "// server name" |
|||
echo -e "hostname \"${servername}\"" |
|||
@ -652,28 +706,13 @@ echo "=================================" |
|||
echo -e "sv_logecho 1" |
|||
echo -e "sv_logfile 1" |
|||
echo -e "sv_log_onefile 0" |
|||
}|tee ${servercfg} > /dev/null 2>&1 |
|||
}|tee "${servercfg}" > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating log directorys" |
|||
mkdir -v ${rootdir}/log |
|||
mkdir -v ${scriptlogdir} |
|||
mkdir -v ${consolelogdir} |
|||
touch ${consolelog} |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv ${gamelogdir} ${rootdir}/log/server |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
echo "Applying steamclient.so fix" |
|||
mkdir -v ${HOME}/.steam |
|||
mkdir -v ${HOME}/.steam/sdk32 |
|||
cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so |
|||
sleep 1 |
|||
fn_header |
|||
sleep 1 |
|||
fn_details |
|||
sleep 1 |
|||
echo "=================================" |
|||
echo "Install Complete!" |
|||
echo "" |
|||
|
@ -3,7 +3,7 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 251213 |
|||
# Version: 240114 |
|||
|
|||
#### Variables #### |
|||
|
|||
@ -12,6 +12,10 @@ |
|||
emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="anonymous" |
|||
steampass="" |
|||
|
|||
# Start Variables |
|||
defaultmap="dm_lockdown" |
|||
port="27015" |
|||
@ -20,7 +24,9 @@ clientport="27005" |
|||
maxplayers="16" |
|||
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}" |
|||
fn_parms(){ |
|||
parms="-game hl2mp +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}" |
|||
} |
|||
|
|||
#### Advanced Variables #### |
|||
|
|||
@ -29,7 +35,6 @@ appid="232370" |
|||
|
|||
# Server Details |
|||
servicename="hl2dm-server" |
|||
|
|||
gamename="Half Life 2: Deathmatch" |
|||
engine="source" |
|||
|
|||
@ -37,16 +42,21 @@ engine="source" |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
filesdir="${rootdir}/serverfiles" |
|||
servercfg="${filesdir}/hl2mp/cfg/${servicename}.cfg" |
|||
systemdir="${filesdir}/hl2mp" |
|||
executabledir="${filesdir}" |
|||
executable="./srcds_run" |
|||
servercfg="${systemdir}/cfg/${servicename}.cfg" |
|||
defaultcfg="${systemdir}/cfg/server.cfg" |
|||
backupdir="backups" |
|||
steamclient="${filesdir}/bin/steamclient.so" |
|||
|
|||
# Server Details |
|||
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') |
|||
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') |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${filesdir}/hl2mp/logs" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
|
|||
@ -62,6 +72,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- |
|||
# unless you know |
|||
# what you are doing |
|||
|
|||
fn_scriptlog(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} |
|||
} |
|||
|
|||
fn_rootcheck(){ |
|||
if [ `whoami` = "root" ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" |
|||
@ -70,8 +84,8 @@ fi |
|||
} |
|||
|
|||
fn_syscheck(){ |
|||
if [ ! -e ${filesdir} ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: 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 |
|||
} |
|||
@ -79,42 +93,42 @@ fi |
|||
fn_autoip(){ |
|||
# Identifies the server interface IP |
|||
# If multiple interfaces this will need to be set manually |
|||
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) |
|||
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l) |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active interfaces.\n\n" |
|||
echo -en "Manually specify the IP in ${selfname}\n" |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use in ${selfname}.\n" |
|||
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" |
|||
echo -en "${getip}\n" |
|||
exit |
|||
else |
|||
else |
|||
ip=${getip} |
|||
fi |
|||
fi |
|||
} |
|||
|
|||
fn_logmanager(){ |
|||
if [ ! -e ${consolelog} ]; then |
|||
touch ${consolelog} |
|||
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 |
|||
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} |
|||
fn_scriptlog "Starting log cleaner" |
|||
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} |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) |
|||
consolecount=$(find ${consolelogdir}/* -mtime +${logdays}|wc -l) |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog} |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
fi |
|||
} |
|||
|
|||
@ -122,6 +136,7 @@ fn_debugserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
echo "" |
|||
echo "${gamename} Debug" |
|||
echo "============================" |
|||
@ -130,6 +145,9 @@ echo -e "Use for identifying server issues only!" |
|||
echo -e "Press CTRL+c to drop out of debug mode" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped" |
|||
echo "" |
|||
echo "Start parameters:" |
|||
echo ${parms} |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
@ -142,11 +160,11 @@ fn_stopserver |
|||
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} |
|||
fn_scriptlog "Started debug mode ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd ${filesdir} |
|||
./srcds_run ${parms} -debug |
|||
cd "${executabledir}" |
|||
${executable} ${parms} -debug |
|||
} |
|||
|
|||
fn_console(){ |
|||
@ -172,7 +190,7 @@ 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\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
@ -224,14 +242,14 @@ fi |
|||
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} |
|||
fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd ${rootdir} |
|||
mkdir ${backupdir} > /dev/null 2>&1 |
|||
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * |
|||
cd "${rootdir}" |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" * |
|||
echo -en "\r\033[K${servicename} Backup complete" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} |
|||
fn_scriptlog "Backup complete" |
|||
} |
|||
|
|||
fn_distro(){ |
|||
@ -257,7 +275,7 @@ days=$(( uptime/60/60/24 )) |
|||
} |
|||
|
|||
fn_load(){ |
|||
load=$(uptime | awk -F 'load average' '{ print $2 }') |
|||
load=$(uptime|awk -F 'load average' '{ print $2 }') |
|||
} |
|||
|
|||
fn_emailnotification(){ |
|||
@ -281,19 +299,19 @@ fn_load |
|||
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 |
|||
echo -e "\n\nConsole log\n====================\n" >> ${emaillog} |
|||
tail -25 ${consolelog} >> ${emaillog} |
|||
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1 |
|||
tail -25 "${scriptlog}" >> "${emaillog}" |
|||
if [ ! -z "${consolelog}" ]; then |
|||
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}" |
|||
tail -25 "${consolelog}" >> "${emaillog}" |
|||
fi |
|||
if [ ! -z ${gamelogdir} ]; then |
|||
echo -e "\n\nServer log\n====================\n" >> ${emaillog} |
|||
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog} |
|||
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} |
|||
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} |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
} |
|||
@ -301,7 +319,7 @@ echo -en "\n" |
|||
fn_emailtest(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} |
|||
fn_scriptlog "Emailing test notification" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
subject="${servicename} Email Test Notification - Testing ${servername}" |
|||
failurereason="Testing ${servicename} email notification" |
|||
@ -309,7 +327,7 @@ if [ "${emailnotification}" = "on" ]; then |
|||
fn_emailnotification |
|||
else |
|||
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} |
|||
fn_scriptlog "Email notification not enabled" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -319,23 +337,23 @@ fn_serverquery(){ |
|||
# uses gsquery.py to directly query the server |
|||
# detects if the server locks up |
|||
if [ -f gsquery.py ]; then |
|||
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; 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} |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
@ -348,13 +366,13 @@ if [ -f gsquery.py ]; then |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
elif [ "${exitcode}" == "126" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "Attempting to resolve automatically" |
|||
@ -372,11 +390,11 @@ if [ -f gsquery.py ]; then |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
exit |
|||
fi |
|||
fi |
|||
} |
|||
@ -386,41 +404,41 @@ fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: CHECKING" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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} |
|||
fn_scriptlog "Checking session: FAIL" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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 |
|||
fn_scriptlog "Monitor is starting ${servername}" |
|||
fn_startserver |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} |
|||
fn_scriptlog "When updates complete ${servicename} will start" |
|||
fi |
|||
} |
|||
|
|||
@ -430,14 +448,14 @@ fn_syscheck |
|||
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 anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog} |
|||
fn_scriptlog "Updating ${servername}" |
|||
cd "${rootdir}" |
|||
cd "steamcmd" |
|||
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" |
|||
} |
|||
|
|||
fn_restartserver(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Restarting ${servername}" |
|||
fn_stopserver |
|||
fn_startserver |
|||
} |
|||
@ -447,15 +465,15 @@ fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 0.5 |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already stopped" |
|||
else |
|||
tmux kill-session -t ${servicename} |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopped ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -465,65 +483,70 @@ fn_startserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
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} |
|||
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} |
|||
fn_scriptlog "Starting ${servername}" |
|||
sleep 0.5 |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
cd ${filesdir} |
|||
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${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\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} |
|||
fn_scriptlog "failed to start ${servername}" |
|||
else |
|||
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} |
|||
fn_scriptlog "Started ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_details(){ |
|||
fn_autoip |
|||
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') |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo "" |
|||
echo "${gamename} Server Details" |
|||
echo "============================" |
|||
echo "Server name: ${servername}" |
|||
echo "Server IP: ${ip}:${port}" |
|||
echo "RCON password: ${rcon}" |
|||
echo "Config file: ${servercfg}" |
|||
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 "Ports the server is currently using." |
|||
echo "" |
|||
echo "DIRECTION DESCRIPTION PORT" |
|||
echo "INBOUND Game/Rcon Port ${port}" |
|||
echo "INBOUND Game/RCON port ${port}" |
|||
if [ "${engine}" = "source" ]; then |
|||
echo "INBOUND SourceTV Port ${sourcetvport}" |
|||
echo "INBOUND SourceTV port ${sourcetvport}" |
|||
fi |
|||
echo "OUTBOUND Client Port ${clientport}" |
|||
echo "OUTBOUND Client port ${clientport}" |
|||
echo "" |
|||
echo "You can change ports by editing the" |
|||
echo "start parameters in ${selfname}" |
|||
echo "start parameters in ${selfname}." |
|||
echo "" |
|||
echo "${servername} Details" |
|||
echo "=======================" |
|||
echo "Server name: ${servername}" |
|||
echo "Rcon Password: ${rcon}" |
|||
echo "" |
|||
echo "Config file:" |
|||
echo "${servercfg}" |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" |
|||
else |
|||
echo -e "Status:\e[0;32m ONLINE\e[0;39m" |
|||
fi |
|||
echo "" |
|||
} |
|||
|
|||
@ -535,7 +558,7 @@ fn_header(){ |
|||
clear |
|||
echo "=================================" |
|||
echo "${gamename}" |
|||
echo "Server Linux Installer" |
|||
echo "Linux Game Server Manager" |
|||
echo "by Daniel Gibbs" |
|||
echo "http://danielgibbs.co.uk" |
|||
echo "=================================" |
|||
@ -543,19 +566,73 @@ echo "" |
|||
} |
|||
|
|||
fn_steamdl(){ |
|||
echo "Installing Steam" |
|||
echo "Installing SteamCMD" |
|||
echo "=================================" |
|||
cd ${rootdir} |
|||
mkdir steamcmd |
|||
cd steamcmd |
|||
cd "${rootdir}" |
|||
mkdir -pv "steamcmd" |
|||
sleep 1 |
|||
cd "steamcmd" |
|||
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 |
|||
chmod +x steamcmd.sh |
|||
sleep 1 |
|||
else |
|||
echo "" |
|||
echo "Steam already installed!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_steaminstall(){ |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${filesdir}" |
|||
cd "${rootdir}/steamcmd" |
|||
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamfix(){ |
|||
echo "Applying steamclient.so fix" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv ${HOME}/.steam |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_loginstall(){ |
|||
echo "Creating log directorys" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
touch "${scriptlog}" |
|||
mkdir -pv "${consolelogdir}" |
|||
touch "${consolelog}" |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv "${gamelogdir}" "${rootdir}/log/server" |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_retryinstall(){ |
|||
@ -572,20 +649,19 @@ done |
|||
fn_install(){ |
|||
fn_rootcheck |
|||
fn_header |
|||
if [ -d ${filesdir} ]; then |
|||
if [ -d "${filesdir}" ]; then |
|||
echo "${gamename} Server is already installed here:" |
|||
pwd |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Yy]* ) fn_header; break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
fn_header |
|||
echo "Install Directory:" |
|||
pwd |
|||
echo "" |
|||
@ -599,44 +675,21 @@ while true; do |
|||
done |
|||
fn_header |
|||
fn_steamdl |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
cd ${rootdir}/steamcmd |
|||
mkdir -v ${filesdir} |
|||
touch install.txt |
|||
chmod 0600 install.txt |
|||
echo "login anonymous" > install.txt |
|||
echo "force_install_dir ${filesdir}" >> install.txt |
|||
echo "app_update ${appid} validate" >> install.txt |
|||
echo "quit" >> install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
rm install.txt |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fn_header |
|||
fn_steaminstall |
|||
fn_steamfix |
|||
fn_loginstall |
|||
echo "Configuring ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
read -p "Enter server name: " servername |
|||
read -p "Enter rcon password: " rconpass |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating server.cfg" |
|||
touch ${filesdir}/hl2mp/cfg/server.cfg |
|||
echo "exec ${servicename}.cfg" > ${filesdir}/hl2mp/cfg/server.cfg |
|||
echo "Creating server.cfg." |
|||
touch "${defaultcfg}" |
|||
echo "exec ${servicename}.cfg" > "${defaultcfg}" |
|||
sleep 1 |
|||
echo "Creating default config file:" |
|||
sleep 0.5 |
|||
echo "${servercfg}" |
|||
touch ${servercfg} |
|||
echo "Creating ${servicename}.cfg config file." |
|||
touch "${servercfg}" |
|||
{ |
|||
echo -e "// server name" |
|||
echo -e "hostname \"${servername}\"" |
|||
@ -653,28 +706,13 @@ echo "=================================" |
|||
echo -e "sv_logecho 1" |
|||
echo -e "sv_logfile 1" |
|||
echo -e "sv_log_onefile 0" |
|||
}|tee ${servercfg} > /dev/null 2>&1 |
|||
}|tee "${servercfg}" > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating log directorys" |
|||
mkdir -v ${rootdir}/log |
|||
mkdir -v ${scriptlogdir} |
|||
mkdir -v ${consolelogdir} |
|||
touch ${consolelog} |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv ${gamelogdir} ${rootdir}/log/server |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
echo "Applying steamclient.so fix" |
|||
mkdir -v ${HOME}/.steam |
|||
mkdir -v ${HOME}/.steam/sdk32 |
|||
cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so |
|||
sleep 1 |
|||
fn_header |
|||
sleep 1 |
|||
fn_details |
|||
sleep 1 |
|||
echo "=================================" |
|||
echo "Install Complete!" |
|||
echo "" |
|||
|
@ -0,0 +1,754 @@ |
|||
#!/bin/bash |
|||
# Insurgency |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 240114 |
|||
|
|||
#### Variables #### |
|||
|
|||
# Notification Email |
|||
# (on|off) |
|||
emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="username" |
|||
steampass="password" |
|||
|
|||
# Start Variables |
|||
|
|||
defaultmap="ministry" |
|||
port="27015" |
|||
sourcetvport="27020" |
|||
clientport="27005" |
|||
maxplayers="24" |
|||
ip="0.0.0.0" |
|||
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server |
|||
fn_parms(){ |
|||
parms="+map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}" |
|||
} |
|||
|
|||
#### Advanced Variables #### |
|||
|
|||
# Steam |
|||
appid="237410" |
|||
|
|||
# Server Details |
|||
servicename="ins-server" |
|||
gamename="Insurgency" |
|||
engine="source" |
|||
|
|||
# Directorys |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
filesdir="${rootdir}/serverfiles" |
|||
systemdir="${filesdir}/insurgency" |
|||
executabledir="${filesdir}" |
|||
executable="./srcds_linux" |
|||
servercfg="${systemdir}/cfg/${servicename}.cfg" |
|||
defaultcfg="${systemdir}/cfg/server.cfg" |
|||
backupdir="backups" |
|||
steamclient="${filesdir}/bin/steamclient.so" |
|||
|
|||
# Server Details |
|||
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') |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
|
|||
scriptlog="${scriptlogdir}/${servicename}-script.log" |
|||
consolelog="${consolelogdir}/${servicename}-console.log" |
|||
emaillog="${scriptlogdir}/${servicename}-email.log" |
|||
|
|||
scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log" |
|||
consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log" |
|||
|
|||
##### Script ##### |
|||
# Do not edit |
|||
# unless you know |
|||
# what you are doing |
|||
|
|||
fn_scriptlog(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} |
|||
} |
|||
|
|||
fn_rootcheck(){ |
|||
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 "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" |
|||
exit |
|||
fi |
|||
} |
|||
|
|||
fn_autoip(){ |
|||
# Identifies the server interface IP |
|||
# If multiple interfaces this will need to be set manually |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use 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 |
|||
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 "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" |
|||
fn_scriptlog "Starting log cleaner" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
fi |
|||
} |
|||
|
|||
fn_debugserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
echo "" |
|||
echo "${gamename} Debug" |
|||
echo "============================" |
|||
echo "" |
|||
echo -e "Use for identifying server issues only!" |
|||
echo -e "Press CTRL+c to drop out of debug mode" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped" |
|||
echo "" |
|||
echo "Start parameters:" |
|||
echo ${parms} |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fn_stopserver |
|||
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" |
|||
fn_scriptlog "Started debug mode ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd "${executabledir}" |
|||
${executable} ${parms} -debug |
|||
} |
|||
|
|||
fn_console(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
echo "" |
|||
echo "${gamename} Console" |
|||
echo "============================" |
|||
echo "" |
|||
echo "Press \"CTRL+b d\" to exit console" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m Do NOT press CTRL+c to exit" |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
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\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" |
|||
sleep 0.5 |
|||
while true; do |
|||
read -p "Do you want to start the server? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) fn_startserver;break;; |
|||
[Nn]* ) break;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
} |
|||
|
|||
fn_backupserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
backupname="${servicename}-$(date '+%Y-%m-%d-%H%M%S')" |
|||
echo "" |
|||
echo "${gamename} Backup" |
|||
echo "============================" |
|||
echo "" |
|||
echo "The following backup will be created." |
|||
echo "" |
|||
echo "${backupdir}/${backupname}.tar.gz" |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[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 |
|||
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 |
|||
case $yn in |
|||
[Yy]* ) fn_stopserver;break;; |
|||
[Nn]* ) break;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
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}" |
|||
fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd "${rootdir}" |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" * |
|||
echo -en "\r\033[K${servicename} Backup complete" |
|||
fn_scriptlog "Backup complete" |
|||
} |
|||
|
|||
fn_distro(){ |
|||
arch=$(uname -m) |
|||
kernel=$(uname -r) |
|||
if [ -f /etc/lsb-release ]; then |
|||
os=$(lsb_release -s -d) |
|||
elif [ -f /etc/debian_version ]; then |
|||
os="Debian $(cat /etc/debian_version)" |
|||
elif [ -f /etc/redhat-release ]; then |
|||
os=$(cat /etc/redhat-release) |
|||
else |
|||
os="$(uname -s) $(uname -r)" |
|||
fi |
|||
} |
|||
|
|||
fn_uptime(){ |
|||
uptime=$(</proc/uptime) |
|||
uptime=${uptime%%.*} |
|||
minutes=$(( uptime/60%60 )) |
|||
hours=$(( uptime/60/60%24 )) |
|||
days=$(( uptime/60/60/24 )) |
|||
} |
|||
|
|||
fn_load(){ |
|||
load=$(uptime|awk -F 'load average' '{ print $2 }') |
|||
} |
|||
|
|||
fn_emailnotification(){ |
|||
fn_distro |
|||
fn_uptime |
|||
fn_load |
|||
{ |
|||
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 |
|||
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}" |
|||
tail -25 "${consolelog}" >> "${emaillog}" |
|||
fi |
|||
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}" |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_emailtest(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_scriptlog "Emailing test notification" |
|||
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 "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" |
|||
fn_scriptlog "Email notification not enabled" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_serverquery(){ |
|||
# uses gsquery.py to directly query the server |
|||
# detects if the server locks up |
|||
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" |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
sleep 1 |
|||
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
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" |
|||
fn_scriptlog "Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
elif [ "${exitcode}" == "126" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" |
|||
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 -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
fi |
|||
fi |
|||
} |
|||
|
|||
fn_monitorserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" |
|||
fn_scriptlog "Checking session: CHECKING" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_serverquery |
|||
exit |
|||
else |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" |
|||
fn_scriptlog "Checking session: FAIL" |
|||
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 |
|||
fn_scriptlog "Monitor is starting ${servername}" |
|||
fn_startserver |
|||
fi |
|||
else |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" |
|||
fn_scriptlog "Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" |
|||
fn_scriptlog "When updates complete ${servicename} will start" |
|||
fi |
|||
} |
|||
|
|||
fn_updateserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
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}" |
|||
fn_scriptlog "Updating ${servername}" |
|||
cd "${rootdir}" |
|||
cd "steamcmd" |
|||
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" |
|||
} |
|||
|
|||
fn_restartserver(){ |
|||
fn_scriptlog "Restarting ${servername}" |
|||
fn_stopserver |
|||
fn_startserver |
|||
} |
|||
|
|||
fn_stopserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 0.5 |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" |
|||
fn_scriptlog "${servername} is already stopped" |
|||
else |
|||
tmux kill-session -t ${servicename} |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" |
|||
fn_scriptlog "Stopped ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_startserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
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}" |
|||
fn_scriptlog "Starting ${servername}" |
|||
sleep 0.5 |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${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\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" |
|||
fn_scriptlog "failed to start ${servername}" |
|||
else |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" |
|||
fn_scriptlog "Started ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_details(){ |
|||
fn_autoip |
|||
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') |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo "" |
|||
echo "${gamename} Server Details" |
|||
echo "============================" |
|||
echo "Server name: ${servername}" |
|||
echo "Server IP: ${ip}:${port}" |
|||
echo "RCON password: ${rcon}" |
|||
echo "Config file: ${servercfg}" |
|||
echo "" |
|||
echo "${servername} Ports" |
|||
echo "============================" |
|||
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 "" |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" |
|||
else |
|||
echo -e "Status:\e[0;32m ONLINE\e[0;39m" |
|||
fi |
|||
echo "" |
|||
} |
|||
|
|||
# |
|||
## Installer |
|||
# |
|||
|
|||
fn_header(){ |
|||
clear |
|||
echo "=================================" |
|||
echo "${gamename}" |
|||
echo "Linux Game Server Manager" |
|||
echo "by Daniel Gibbs" |
|||
echo "http://danielgibbs.co.uk" |
|||
echo "=================================" |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamdl(){ |
|||
echo "Installing SteamCMD" |
|||
echo "=================================" |
|||
cd "${rootdir}" |
|||
mkdir -pv "steamcmd" |
|||
sleep 1 |
|||
cd "steamcmd" |
|||
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 |
|||
chmod +x steamcmd.sh |
|||
sleep 1 |
|||
else |
|||
echo "" |
|||
echo "Steam already installed!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_steaminstall(){ |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${filesdir}" |
|||
cd "${rootdir}/steamcmd" |
|||
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamfix(){ |
|||
echo "Applying steamclient.so fix" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv ${HOME}/.steam |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_loginstall(){ |
|||
echo "Creating log directorys" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
touch "${scriptlog}" |
|||
mkdir -pv "${consolelogdir}" |
|||
touch "${consolelog}" |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv "${gamelogdir}" "${rootdir}/log/server" |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_retryinstall(){ |
|||
while true; do |
|||
read -p "Retry install? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) fn_install;; |
|||
[Nn]* ) echo Exiting; exit;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
} |
|||
|
|||
fn_install(){ |
|||
fn_rootcheck |
|||
fn_header |
|||
if [ -d "${filesdir}" ]; then |
|||
echo "${gamename} Server is already installed here:" |
|||
pwd |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) fn_header; break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
echo "Install Directory:" |
|||
pwd |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fn_header |
|||
fn_steamdl |
|||
fn_steaminstall |
|||
fn_steamfix |
|||
fn_loginstall |
|||
echo "Configuring ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
read -p "Enter server name: " servername |
|||
read -p "Enter rcon password: " rconpass |
|||
sleep 1 |
|||
echo "Creating server.cfg." |
|||
touch "${defaultcfg}" |
|||
echo "exec ${servicename}.cfg" > "${defaultcfg}" |
|||
sleep 1 |
|||
echo "Creating ${servicename}.cfg config file." |
|||
touch "${servercfg}" |
|||
{ |
|||
echo -e "// server name" |
|||
echo -e "hostname \"${servername}\"" |
|||
echo -e "" |
|||
echo -e "// rcon passsword" |
|||
echo -e "rcon_password \"${rconpass}\"" |
|||
echo -e "" |
|||
echo -e "// Server password" |
|||
echo -e "sv_password \"\"" |
|||
echo -e "" |
|||
echo -e "// server logging" |
|||
echo -e "log on" |
|||
echo -e "sv_logbans 1" |
|||
echo -e "sv_logecho 1" |
|||
echo -e "sv_logfile 1" |
|||
echo -e "sv_log_onefile 0" |
|||
}|tee "${servercfg}" > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
fn_header |
|||
sleep 1 |
|||
fn_details |
|||
sleep 1 |
|||
echo "=================================" |
|||
echo "Install Complete!" |
|||
echo "" |
|||
echo "To start server type:" |
|||
echo "${selfname} start" |
|||
echo "" |
|||
} |
|||
|
|||
case "$1" in |
|||
start) |
|||
fn_startserver;; |
|||
stop) |
|||
fn_stopserver;; |
|||
restart) |
|||
fn_restartserver;; |
|||
update) |
|||
fn_stopserver |
|||
fn_updateserver |
|||
fn_startserver;; |
|||
monitor) |
|||
fn_monitorserver;; |
|||
email-test) |
|||
fn_emailtest;; |
|||
details) |
|||
fn_details;; |
|||
backup) |
|||
fn_backupserver;; |
|||
console) |
|||
fn_console;; |
|||
debug) |
|||
fn_debugserver;; |
|||
install) |
|||
fn_install;; |
|||
*) |
|||
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" |
|||
exit 1;; |
|||
esac |
|||
exit |
@ -3,7 +3,11 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
<<<<<<< HEAD |
|||
# Version: 251214 |
|||
======= |
|||
# Version: 240114 |
|||
>>>>>>> Major update 240114 |
|||
|
|||
#### Variables #### |
|||
|
|||
@ -12,6 +16,10 @@ |
|||
emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="anonymous" |
|||
steampass="" |
|||
|
|||
# Start Variables |
|||
defaultmap="c5m1_waterfront" |
|||
port="27015" |
|||
@ -20,7 +28,9 @@ clientport="27005" |
|||
maxplayers="16" |
|||
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}" |
|||
fn_parms(){ |
|||
parms="-game left4dead2 +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}" |
|||
} |
|||
|
|||
#### Advanced Variables #### |
|||
|
|||
@ -36,16 +46,26 @@ engine="source" |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
filesdir="${rootdir}/serverfiles" |
|||
servercfg="${filesdir}/left4dead2/cfg/${servicename}.cfg" |
|||
systemdir="${filesdir}/left4dead2" |
|||
executabledir="${filesdir}" |
|||
executable="./srcds_run" |
|||
servercfg="${systemdir}/cfg/${servicename}.cfg" |
|||
defaultcfg="${systemdir}/cfg/server.cfg" |
|||
backupdir="backups" |
|||
steamclient="${filesdir}/bin/steamclient.so" |
|||
|
|||
# Server Details |
|||
<<<<<<< HEAD |
|||
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') |
|||
======= |
|||
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') |
|||
>>>>>>> Major update 240114 |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${filesdir}/left4dead2/logs" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
|
|||
@ -73,8 +93,13 @@ fi |
|||
} |
|||
|
|||
fn_syscheck(){ |
|||
<<<<<<< HEAD |
|||
if [ ! -e "${filesdir}" ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: 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" |
|||
>>>>>>> Major update 240114 |
|||
exit |
|||
fi |
|||
} |
|||
@ -82,12 +107,17 @@ fi |
|||
fn_autoip(){ |
|||
# Identifies the server interface IP |
|||
# If multiple interfaces this will need to be set manually |
|||
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) |
|||
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l) |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
<<<<<<< HEAD |
|||
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 "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use in ${selfname}.\n" |
|||
>>>>>>> Major update 240114 |
|||
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" |
|||
echo -en "${getip}\n" |
|||
exit |
|||
@ -102,15 +132,24 @@ if [ ! -e "${consolelog}" ]; then |
|||
touch "${consolelog}" |
|||
fi |
|||
# log manager will active if finds logs older than ${logdays} |
|||
<<<<<<< HEAD |
|||
if [ `find "${scriptlogdir}"/* -mtime +${logdays} |wc -l` -ne "0" ]; then |
|||
======= |
|||
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then |
|||
>>>>>>> Major update 240114 |
|||
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" |
|||
fn_scriptlog "Starting log cleaner" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
<<<<<<< HEAD |
|||
find "${scriptlogdir}"/* -mtime +${logdays} |tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays} |tee >> "${scriptlog}" |
|||
======= |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
>>>>>>> Major update 240114 |
|||
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
@ -125,6 +164,7 @@ fn_debugserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
echo "" |
|||
echo "${gamename} Debug" |
|||
echo "============================" |
|||
@ -133,6 +173,9 @@ echo -e "Use for identifying server issues only!" |
|||
echo -e "Press CTRL+c to drop out of debug mode" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped" |
|||
echo "" |
|||
echo "Start parameters:" |
|||
echo ${parms} |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
@ -145,11 +188,19 @@ fn_stopserver |
|||
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" |
|||
<<<<<<< HEAD |
|||
fn_scriptlog "Started debug mode ${servername} " |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd "${filesdir}" |
|||
./srcds_run "${parms}" -debug |
|||
======= |
|||
fn_scriptlog "Started debug mode ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd "${executabledir}" |
|||
${executable} ${parms} -debug |
|||
>>>>>>> Major update 240114 |
|||
} |
|||
|
|||
fn_console(){ |
|||
@ -231,7 +282,11 @@ fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd "${rootdir}" |
|||
<<<<<<< HEAD |
|||
mkdir -p "${backupdir}" > /dev/null 2>&1 |
|||
======= |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
>>>>>>> Major update 240114 |
|||
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" * |
|||
echo -en "\r\033[K${servicename} Backup complete" |
|||
fn_scriptlog "Backup complete" |
|||
@ -260,7 +315,7 @@ days=$(( uptime/60/60/24 )) |
|||
} |
|||
|
|||
fn_load(){ |
|||
load=$(uptime | awk -F 'load average' '{ print $2 }') |
|||
load=$(uptime|awk -F 'load average' '{ print $2 }') |
|||
} |
|||
|
|||
fn_emailnotification(){ |
|||
@ -292,7 +347,11 @@ if [ ! -z "${consolelog}" ]; then |
|||
fi |
|||
if [ ! -z "${gamelogdir}" ]; then |
|||
echo -e "\n\nServer log\n====================\n" >> "${emaillog}" |
|||
<<<<<<< HEAD |
|||
tail "${gamelogdir}"/* | grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" |
|||
======= |
|||
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" |
|||
>>>>>>> Major update 240114 |
|||
fi |
|||
mail -s "${subject}" ${email} < "${emaillog}" |
|||
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" |
|||
@ -322,20 +381,28 @@ fn_serverquery(){ |
|||
# uses gsquery.py to directly query the server |
|||
# detects if the server locks up |
|||
if [ -f gsquery.py ]; then |
|||
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; 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" |
|||
<<<<<<< HEAD |
|||
fn_scriptlog "Detected gsquery.py " |
|||
======= |
|||
fn_scriptlog "Detected gsquery.py" |
|||
>>>>>>> Major update 240114 |
|||
sleep 1 |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
<<<<<<< HEAD |
|||
sleep 1 |
|||
======= |
|||
sleep 1 |
|||
>>>>>>> Major update 240114 |
|||
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
@ -379,7 +446,7 @@ if [ -f gsquery.py ]; then |
|||
sleep 1 |
|||
echo -en "\n" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
exit |
|||
fi |
|||
fi |
|||
} |
|||
@ -408,7 +475,11 @@ if [ "${updatecheck}" = "0" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" |
|||
fn_scriptlog "Checking session: FAIL" |
|||
sleep 1 |
|||
<<<<<<< HEAD |
|||
echo -en "\n" |
|||
======= |
|||
echo -en "\n" |
|||
>>>>>>> Major update 240114 |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
subject="${servicename} Monitor - Starting ${servername}" |
|||
failurereason="${servicename} process not running" |
|||
@ -416,7 +487,11 @@ if [ "${updatecheck}" = "0" ]; then |
|||
fn_emailnotification |
|||
fi |
|||
fn_scriptlog "Monitor is starting ${servername}" |
|||
<<<<<<< HEAD |
|||
fn_startserver |
|||
======= |
|||
fn_startserver |
|||
>>>>>>> Major update 240114 |
|||
fi |
|||
else |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" |
|||
@ -435,8 +510,13 @@ sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" |
|||
fn_scriptlog "Updating ${servername}" |
|||
cd "${rootdir}" |
|||
<<<<<<< HEAD |
|||
cd steamcmd |
|||
./steamcmd.sh +login anonymous +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |tee -a "${scriptlog}" |
|||
======= |
|||
cd "steamcmd" |
|||
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" |
|||
>>>>>>> Major update 240114 |
|||
} |
|||
|
|||
fn_restartserver(){ |
|||
@ -468,6 +548,7 @@ fn_startserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
fn_logmanager |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 0 ]; then |
|||
@ -484,8 +565,13 @@ if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
<<<<<<< HEAD |
|||
cd "${filesdir}" |
|||
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a '${consolelog}'" |
|||
======= |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'" |
|||
>>>>>>> Major update 240114 |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 0 ]; then |
|||
@ -500,33 +586,44 @@ echo -en "\n" |
|||
} |
|||
|
|||
fn_details(){ |
|||
fn_autoip |
|||
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') |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo "" |
|||
echo "${gamename} Server Details" |
|||
echo "============================" |
|||
echo "Server name: ${servername}" |
|||
echo "Server IP: ${ip}:${port}" |
|||
echo "RCON password: ${rcon}" |
|||
echo "Config file: ${servercfg}" |
|||
echo "" |
|||
echo "${servername} Ports" |
|||
<<<<<<< HEAD |
|||
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 "Ports the server is currently using." |
|||
>>>>>>> Major update 240114 |
|||
echo "" |
|||
echo "DIRECTION DESCRIPTION PORT" |
|||
echo "INBOUND Game/Rcon Port ${port}" |
|||
echo "INBOUND Game/RCON port ${port}" |
|||
if [ "${engine}" = "source" ]; then |
|||
echo "INBOUND SourceTV Port ${sourcetvport}" |
|||
echo "INBOUND SourceTV port ${sourcetvport}" |
|||
fi |
|||
echo "OUTBOUND Client Port ${clientport}" |
|||
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 "start parameters in ${selfname}." |
|||
echo "" |
|||
echo "Config file:" |
|||
echo "${servercfg}" |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" |
|||
else |
|||
echo -e "Status:\e[0;32m ONLINE\e[0;39m" |
|||
fi |
|||
echo "" |
|||
} |
|||
|
|||
@ -538,7 +635,7 @@ fn_header(){ |
|||
clear |
|||
echo "=================================" |
|||
echo "${gamename}" |
|||
echo "Server Linux Installer" |
|||
echo "Linux Game Server Manager" |
|||
echo "by Daniel Gibbs" |
|||
echo "http://danielgibbs.co.uk" |
|||
echo "=================================" |
|||
@ -546,19 +643,78 @@ echo "" |
|||
} |
|||
|
|||
fn_steamdl(){ |
|||
echo "Installing Steam" |
|||
echo "Installing SteamCMD" |
|||
echo "=================================" |
|||
cd "${rootdir}" |
|||
<<<<<<< HEAD |
|||
mkdir -p steamcmd |
|||
cd steamcmd |
|||
======= |
|||
mkdir -pv "steamcmd" |
|||
sleep 1 |
|||
cd "steamcmd" |
|||
>>>>>>> Major update 240114 |
|||
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 |
|||
chmod +x steamcmd.sh |
|||
sleep 1 |
|||
else |
|||
echo "" |
|||
echo "Steam already installed!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_steaminstall(){ |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${filesdir}" |
|||
cd "${rootdir}/steamcmd" |
|||
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamfix(){ |
|||
echo "Applying steamclient.so fix" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv ${HOME}/.steam |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_loginstall(){ |
|||
echo "Creating log directorys" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
touch "${scriptlog}" |
|||
mkdir -pv "${consolelogdir}" |
|||
touch "${consolelog}" |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv "${gamelogdir}" "${rootdir}/log/server" |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_retryinstall(){ |
|||
@ -582,13 +738,12 @@ if [ -d "${filesdir}" ]; then |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Yy]* ) fn_header; break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
fn_header |
|||
echo "Install Directory:" |
|||
pwd |
|||
echo "" |
|||
@ -602,6 +757,7 @@ while true; do |
|||
done |
|||
fn_header |
|||
fn_steamdl |
|||
<<<<<<< HEAD |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
@ -629,11 +785,18 @@ echo "=================================" |
|||
esac |
|||
done |
|||
fn_header |
|||
======= |
|||
fn_steaminstall |
|||
fn_steamfix |
|||
fn_loginstall |
|||
>>>>>>> Major update 240114 |
|||
echo "Configuring ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
read -p "Enter server name: " servername |
|||
read -p "Enter rcon password: " rconpass |
|||
sleep 1 |
|||
<<<<<<< HEAD |
|||
echo "" |
|||
echo "Creating server.cfg" |
|||
touch "${filesdir}/left4dead2/cfg/server.cfg" |
|||
@ -642,6 +805,13 @@ echo "=================================" |
|||
echo "Creating default config file:" |
|||
sleep 0.5 |
|||
echo "${servercfg}" |
|||
======= |
|||
echo "Creating server.cfg." |
|||
touch "${defaultcfg}" |
|||
echo "exec ${servicename}.cfg" > "${defaultcfg}" |
|||
sleep 1 |
|||
echo "Creating ${servicename}.cfg config file." |
|||
>>>>>>> Major update 240114 |
|||
touch "${servercfg}" |
|||
{ |
|||
echo -e "// server name" |
|||
@ -662,6 +832,7 @@ echo "=================================" |
|||
}|tee "${servercfg}" > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
<<<<<<< HEAD |
|||
echo "Creating log directorys" |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
@ -679,8 +850,12 @@ echo "=================================" |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${filesdir}/bin/steamclient.so" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
======= |
|||
>>>>>>> Major update 240114 |
|||
fn_header |
|||
sleep 1 |
|||
fn_details |
|||
sleep 1 |
|||
echo "=================================" |
|||
echo "Install Complete!" |
|||
echo "" |
|||
|
@ -3,7 +3,7 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 251213 |
|||
# Version: 240114 |
|||
|
|||
#### Variables #### |
|||
|
|||
@ -13,21 +13,23 @@ emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="username" |
|||
steampass="password" |
|||
steamuser="dgibbsserver" |
|||
steampass="Roundabout1" |
|||
|
|||
# Start Variables |
|||
servername="NS2 Server" |
|||
|
|||
defaultmap="ns2_summit" |
|||
port="27015" |
|||
webdomain="127.0.0.1" |
|||
maxplayers="24" |
|||
ip="0.0.0.0" |
|||
servername="NS2 Server" |
|||
webadminuser="admin" |
|||
webadminpass="test123" |
|||
webadminpass="admin" |
|||
webadminport="8080" |
|||
maxplayers="24" |
|||
password="" |
|||
parms="-name \"${servername}\" -port ${port} -webadmin -webdomain ${webdomain} -webuser ${webadminuser} -webpassword ${webadminpass} -webport ${webadminport} -map ${defaultmap} -limit ${maxplayers} -password ${password}" |
|||
|
|||
fn_parms(){ |
|||
parms="-name \"${servername}\" -port ${port} -webadmin -webdomain ${ip} -webuser ${webadminuser} -webpassword ${webadminpass} -webport ${webadminport} -map ${defaultmap} -limit ${maxplayers} -password ${password}" |
|||
} |
|||
#### Advanced Variables #### |
|||
|
|||
# Steam |
|||
@ -37,17 +39,20 @@ appid="4940" |
|||
servicename="ns2-server" |
|||
gamename="Natural Selection 2" |
|||
engine="spark" |
|||
ip="0.0.0.0" |
|||
|
|||
# Directorys |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
filesdir="${rootdir}/serverfiles" |
|||
systemdir="${filesdir}" |
|||
executabledir="${filesdir}" |
|||
executable="./server_linux32" |
|||
backupdir="backups" |
|||
steamclient="${filesdir}/steamclient.so" |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${filesdir}/logs" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
|
|||
@ -63,6 +68,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- |
|||
# unless you know |
|||
# what you are doing |
|||
|
|||
fn_scriptlog(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} |
|||
} |
|||
|
|||
fn_rootcheck(){ |
|||
if [ `whoami` = "root" ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" |
|||
@ -71,8 +80,8 @@ fi |
|||
} |
|||
|
|||
fn_syscheck(){ |
|||
if [ ! -e ${filesdir} ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: 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 |
|||
} |
|||
@ -80,42 +89,42 @@ fi |
|||
fn_autoip(){ |
|||
# Identifies the server interface IP |
|||
# If multiple interfaces this will need to be set manually |
|||
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) |
|||
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l) |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active interfaces.\n\n" |
|||
echo -en "Manually specify the IP in ${selfname}\n" |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use in ${selfname}.\n" |
|||
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" |
|||
echo -en "${getip}\n" |
|||
exit |
|||
else |
|||
else |
|||
ip=${getip} |
|||
fi |
|||
fi |
|||
} |
|||
|
|||
fn_logmanager(){ |
|||
if [ ! -e ${consolelog} ]; then |
|||
touch ${consolelog} |
|||
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 |
|||
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} |
|||
fn_scriptlog "Starting log cleaner" |
|||
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} |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) |
|||
consolecount=$(find ${consolelogdir}/* -mtime +${logdays}|wc -l) |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog} |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
fi |
|||
} |
|||
|
|||
@ -123,6 +132,7 @@ fn_debugserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
echo "" |
|||
echo "${gamename} Debug" |
|||
echo "============================" |
|||
@ -131,6 +141,9 @@ echo -e "Use for identifying server issues only!" |
|||
echo -e "Press CTRL+c to drop out of debug mode" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped" |
|||
echo "" |
|||
echo "Start parameters:" |
|||
echo ${parms} |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
@ -143,11 +156,11 @@ fn_stopserver |
|||
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} |
|||
fn_scriptlog "Started debug mode ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd ${filesdir} |
|||
./server_linux32 ${parms} |
|||
cd "${executabledir}" |
|||
${executable} ${parms} |
|||
} |
|||
|
|||
fn_console(){ |
|||
@ -173,7 +186,7 @@ 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\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
@ -225,14 +238,14 @@ fi |
|||
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} |
|||
fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd ${rootdir} |
|||
mkdir ${backupdir} > /dev/null 2>&1 |
|||
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * |
|||
cd "${rootdir}" |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" * |
|||
echo -en "\r\033[K${servicename} Backup complete" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} |
|||
fn_scriptlog "Backup complete" |
|||
} |
|||
|
|||
fn_distro(){ |
|||
@ -258,7 +271,7 @@ days=$(( uptime/60/60/24 )) |
|||
} |
|||
|
|||
fn_load(){ |
|||
load=$(uptime | awk -F 'load average' '{ print $2 }') |
|||
load=$(uptime|awk -F 'load average' '{ print $2 }') |
|||
} |
|||
|
|||
fn_emailnotification(){ |
|||
@ -282,19 +295,19 @@ fn_load |
|||
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 |
|||
echo -e "\n\nConsole log\n====================\n" >> ${emaillog} |
|||
tail -25 ${consolelog} >> ${emaillog} |
|||
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1 |
|||
tail -25 "${scriptlog}" >> "${emaillog}" |
|||
if [ ! -z "${consolelog}" ]; then |
|||
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}" |
|||
tail -25 "${consolelog}" >> "${emaillog}" |
|||
fi |
|||
if [ ! -z ${gamelogdir} ]; then |
|||
echo -e "\n\nServer log\n====================\n" >> ${emaillog} |
|||
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog} |
|||
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} |
|||
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} |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
} |
|||
@ -302,7 +315,7 @@ echo -en "\n" |
|||
fn_emailtest(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} |
|||
fn_scriptlog "Emailing test notification" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
subject="${servicename} Email Test Notification - Testing ${servername}" |
|||
failurereason="Testing ${servicename} email notification" |
|||
@ -310,7 +323,7 @@ if [ "${emailnotification}" = "on" ]; then |
|||
fn_emailnotification |
|||
else |
|||
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} |
|||
fn_scriptlog "Email notification not enabled" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -320,23 +333,23 @@ fn_serverquery(){ |
|||
# uses gsquery.py to directly query the server |
|||
# detects if the server locks up |
|||
if [ -f gsquery.py ]; then |
|||
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; 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} |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
@ -349,13 +362,13 @@ if [ -f gsquery.py ]; then |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
elif [ "${exitcode}" == "126" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "Attempting to resolve automatically" |
|||
@ -373,11 +386,11 @@ if [ -f gsquery.py ]; then |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
exit |
|||
fi |
|||
fi |
|||
} |
|||
@ -387,41 +400,41 @@ fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: CHECKING" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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} |
|||
fn_scriptlog "Checking session: FAIL" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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 |
|||
fn_scriptlog "Monitor is starting ${servername}" |
|||
fn_startserver |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} |
|||
fn_scriptlog "When updates complete ${servicename} will start" |
|||
fi |
|||
} |
|||
|
|||
@ -431,21 +444,14 @@ fn_syscheck |
|||
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 ${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_scriptlog "Updating ${servername}" |
|||
cd "${rootdir}" |
|||
cd "steamcmd" |
|||
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" |
|||
} |
|||
|
|||
fn_restartserver(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Restarting ${servername}" |
|||
fn_stopserver |
|||
fn_startserver |
|||
} |
|||
@ -455,15 +461,15 @@ fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 0.5 |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already stopped" |
|||
else |
|||
tmux kill-session -t ${servicename} |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopped ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -473,32 +479,33 @@ fn_startserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
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} |
|||
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} |
|||
fn_scriptlog "Starting ${servername}" |
|||
sleep 0.5 |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
cd ${filesdir} |
|||
tmux new-session -d -s ${servicename} "./server_linux32 ${parms} |tee -a ${consolelog}" |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${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\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} |
|||
fn_scriptlog "failed to start ${servername}" |
|||
else |
|||
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} |
|||
fn_scriptlog "Started ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -507,73 +514,58 @@ echo -en "\n" |
|||
fn_ns2details(){ |
|||
fn_autoip |
|||
queryport=$((${port} + 1)) |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo "" |
|||
echo "${gamename} Server Details" |
|||
echo "============================" |
|||
echo "Server name: ${servername}" |
|||
echo "Server IP: ${ip}:${port}" |
|||
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 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 URL: http://${ip}:${webadminport}/index.html" |
|||
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" |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" |
|||
else |
|||
echo -e "Status:\e[0;32m ONLINE\e[0;39m" |
|||
fi |
|||
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 |
|||
# |
|||
|
|||
fn_ns2deps(){ |
|||
echo "Downloading libm.so.6 and libstdc++.so.6" |
|||
echo "=================================" |
|||
cd "${filesdir}" |
|||
wget https://github.com/dgibbs64/linuxgameservers/raw/master/NaturalSelection2/dependencies/libm.so.6 |
|||
wget https://github.com/dgibbs64/linuxgameservers/raw/master/NaturalSelection2/dependencies/libstdc++.so.6 |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_header(){ |
|||
clear |
|||
echo "=================================" |
|||
echo "${gamename}" |
|||
echo "Server Linux Installer" |
|||
echo "Linux Game Server Manager" |
|||
echo "by Daniel Gibbs" |
|||
echo "http://danielgibbs.co.uk" |
|||
echo "=================================" |
|||
@ -581,19 +573,73 @@ echo "" |
|||
} |
|||
|
|||
fn_steamdl(){ |
|||
echo "Installing Steam" |
|||
echo "Installing SteamCMD" |
|||
echo "=================================" |
|||
cd ${rootdir} |
|||
mkdir steamcmd |
|||
cd steamcmd |
|||
cd "${rootdir}" |
|||
mkdir -pv "steamcmd" |
|||
sleep 1 |
|||
cd "steamcmd" |
|||
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 |
|||
chmod +x steamcmd.sh |
|||
sleep 1 |
|||
else |
|||
echo "" |
|||
echo "Steam already installed!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_steaminstall(){ |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${filesdir}" |
|||
cd "${rootdir}/steamcmd" |
|||
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamfix(){ |
|||
echo "Applying steamclient.so fix" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv ${HOME}/.steam |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_loginstall(){ |
|||
echo "Creating log directorys" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
touch "${scriptlog}" |
|||
mkdir -pv "${consolelogdir}" |
|||
touch "${consolelog}" |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv "${gamelogdir}" "${rootdir}/log/server" |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_retryinstall(){ |
|||
@ -610,20 +656,19 @@ done |
|||
fn_install(){ |
|||
fn_rootcheck |
|||
fn_header |
|||
if [ -d ${filesdir} ]; then |
|||
if [ -d "${filesdir}" ]; then |
|||
echo "${gamename} Server is already installed here:" |
|||
pwd |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Yy]* ) fn_header; break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
fn_header |
|||
echo "Install Directory:" |
|||
pwd |
|||
echo "" |
|||
@ -637,58 +682,14 @@ while true; do |
|||
done |
|||
fn_header |
|||
fn_steamdl |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
cd ${rootdir}/steamcmd |
|||
mkdir -v ${filesdir} |
|||
touch install.txt |
|||
chmod 0600 install.txt |
|||
echo "login ${steamuser} ${steampass}" > install.txt |
|||
echo "force_install_dir ${filesdir}" >> install.txt |
|||
echo "app_update ${appid} validate" >> install.txt |
|||
echo "quit" >> install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
rm install.txt |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "Downloading libm.so.6 and libstdc++.so.6" |
|||
echo "=================================" |
|||
cd ${filesdir} |
|||
wget https://github.com/dgibbs64/linuxgameservers/raw/master/NaturalSelection2/dependencies/libm.so.6 |
|||
wget https://github.com/dgibbs64/linuxgameservers/raw/master/NaturalSelection2/dependencies/libstdc++.so.6 |
|||
sleep 2 |
|||
fn_header |
|||
fn_header |
|||
echo "Configuring ${gamename} Server" |
|||
echo "=================================" |
|||
echo "Creating log directorys" |
|||
mkdir -v ${rootdir}/log |
|||
mkdir -v ${scriptlogdir} |
|||
mkdir -v ${consolelogdir} |
|||
touch ${consolelog} |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv ${gamelogdir} ${rootdir}/log/server |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
echo "Applying steamclient.so fix" |
|||
mkdir -v ${HOME}/.steam |
|||
mkdir -v ${HOME}/.steam/sdk32 |
|||
cp -v ${filesdir}/steamclient.so ${HOME}/.steam/sdk32/steamclient.so |
|||
sleep 1 |
|||
fn_steaminstall |
|||
fn_steamfix |
|||
fn_loginstall |
|||
fn_ns2deps |
|||
fn_header |
|||
sleep 1 |
|||
fn_ns2details |
|||
sleep 1 |
|||
echo "=================================" |
|||
echo "Install Complete!" |
|||
echo "" |
|||
@ -722,11 +723,8 @@ 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|steam-auth}" |
|||
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" |
|||
exit 1;; |
|||
esac |
|||
exit |
@ -1,35 +0,0 @@ |
|||
#!/usr/bin/python |
|||
# serverquery.py part of |
|||
# Server Management Script |
|||
# |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 010813 |
|||
|
|||
import errno |
|||
import sys |
|||
import socket |
|||
import re |
|||
|
|||
if __name__ == "__main__": |
|||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|||
sock.settimeout(0.5) |
|||
|
|||
ip = sys.argv[1] |
|||
port = sys.argv[2] |
|||
try: |
|||
sock.connect((ip, int(port))) |
|||
except socket.error: |
|||
sys.exit("ERROR 1") |
|||
|
|||
sock.send("\xFF\xFF\xFF\xFFTSource Engine Query\0") |
|||
data = "" |
|||
try: |
|||
data = sock.recv(1024) |
|||
except socket.error: |
|||
sys.exit("ERROR 2") |
|||
|
|||
sock.close() |
|||
|
|||
if(len(data) > 10): |
|||
sys.exit("OK") |
|||
sys.exit("ERROR 3") |
@ -3,7 +3,7 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 251213 |
|||
# Version: 240114 |
|||
|
|||
#### Variables #### |
|||
|
|||
@ -12,6 +12,10 @@ |
|||
emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="anonymous" |
|||
steampass="" |
|||
|
|||
# Start Variables |
|||
defaultmap="ctf_2fort" |
|||
port="27015" |
|||
@ -20,7 +24,9 @@ clientport="27005" |
|||
maxplayers="16" |
|||
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}" |
|||
fn_parms(){ |
|||
parms="-game tf +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}" |
|||
} |
|||
|
|||
#### Advanced Variables #### |
|||
|
|||
@ -36,16 +42,21 @@ engine="source" |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
filesdir="${rootdir}/serverfiles" |
|||
servercfg="${filesdir}/tf/cfg/${servicename}.cfg" |
|||
systemdir="${filesdir}/tf" |
|||
executabledir="${filesdir}" |
|||
executable="./srcds_run" |
|||
servercfg="${systemdir}/cfg/${servicename}.cfg" |
|||
defaultcfg="${systemdir}/cfg/server.cfg" |
|||
backupdir="backups" |
|||
steamclient="${filesdir}/bin/steamclient.so" |
|||
|
|||
# Server Details |
|||
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') |
|||
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') |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${filesdir}/tf/logs" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
|
|||
@ -61,6 +72,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- |
|||
# unless you know |
|||
# what you are doing |
|||
|
|||
fn_scriptlog(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} |
|||
} |
|||
|
|||
fn_rootcheck(){ |
|||
if [ `whoami` = "root" ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" |
|||
@ -69,8 +84,8 @@ fi |
|||
} |
|||
|
|||
fn_syscheck(){ |
|||
if [ ! -e ${filesdir} ]; then |
|||
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: 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 |
|||
} |
|||
@ -78,42 +93,42 @@ fi |
|||
fn_autoip(){ |
|||
# Identifies the server interface IP |
|||
# If multiple interfaces this will need to be set manually |
|||
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1) |
|||
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l) |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active interfaces.\n\n" |
|||
echo -en "Manually specify the IP in ${selfname}\n" |
|||
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use in ${selfname}.\n" |
|||
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" |
|||
echo -en "${getip}\n" |
|||
exit |
|||
else |
|||
else |
|||
ip=${getip} |
|||
fi |
|||
fi |
|||
} |
|||
|
|||
fn_logmanager(){ |
|||
if [ ! -e ${consolelog} ]; then |
|||
touch ${consolelog} |
|||
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 |
|||
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} |
|||
fn_scriptlog "Starting log cleaner" |
|||
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} |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
find ${consolelogdir}/* -mtime +${logdays} |tee >> ${scriptlog} |
|||
scriptcount=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l) |
|||
consolecount=$(find ${consolelogdir}/* -mtime +${logdays}|wc -l) |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \; |
|||
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog} |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
fi |
|||
} |
|||
|
|||
@ -121,6 +136,7 @@ fn_debugserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
echo "" |
|||
echo "${gamename} Debug" |
|||
echo "============================" |
|||
@ -129,6 +145,9 @@ echo -e "Use for identifying server issues only!" |
|||
echo -e "Press CTRL+c to drop out of debug mode" |
|||
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped" |
|||
echo "" |
|||
echo "Start parameters:" |
|||
echo ${parms} |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue? [y/N]" yn |
|||
case $yn in |
|||
@ -141,11 +160,11 @@ fn_stopserver |
|||
echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog} |
|||
fn_scriptlog "Started debug mode ${servername}" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
cd ${filesdir} |
|||
./srcds_run ${parms} -debug |
|||
cd "${executabledir}" |
|||
${executable} ${parms} -debug |
|||
} |
|||
|
|||
fn_console(){ |
|||
@ -171,7 +190,7 @@ 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\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog} |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
@ -204,7 +223,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 |
|||
@ -223,14 +242,14 @@ fi |
|||
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} |
|||
fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd ${rootdir} |
|||
mkdir ${backupdir} > /dev/null 2>&1 |
|||
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} * |
|||
cd "${rootdir}" |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" * |
|||
echo -en "\r\033[K${servicename} Backup complete" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog} |
|||
fn_scriptlog "Backup complete" |
|||
} |
|||
|
|||
fn_distro(){ |
|||
@ -256,7 +275,7 @@ days=$(( uptime/60/60/24 )) |
|||
} |
|||
|
|||
fn_load(){ |
|||
load=$(uptime | awk -F 'load average' '{ print $2 }') |
|||
load=$(uptime|awk -F 'load average' '{ print $2 }') |
|||
} |
|||
|
|||
fn_emailnotification(){ |
|||
@ -280,19 +299,19 @@ fn_load |
|||
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 |
|||
echo -e "\n\nConsole log\n====================\n" >> ${emaillog} |
|||
tail -25 ${consolelog} >> ${emaillog} |
|||
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1 |
|||
tail -25 "${scriptlog}" >> "${emaillog}" |
|||
if [ ! -z "${consolelog}" ]; then |
|||
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}" |
|||
tail -25 "${consolelog}" >> "${emaillog}" |
|||
fi |
|||
if [ ! -z ${gamelogdir} ]; then |
|||
echo -e "\n\nServer log\n====================\n" >> ${emaillog} |
|||
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog} |
|||
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} |
|||
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} |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
} |
|||
@ -300,7 +319,7 @@ echo -en "\n" |
|||
fn_emailtest(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} |
|||
fn_scriptlog "Emailing test notification" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
subject="${servicename} Email Test Notification - Testing ${servername}" |
|||
failurereason="Testing ${servicename} email notification" |
|||
@ -308,7 +327,7 @@ if [ "${emailnotification}" = "on" ]; then |
|||
fn_emailnotification |
|||
else |
|||
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} |
|||
fn_scriptlog "Email notification not enabled" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -318,23 +337,23 @@ fn_serverquery(){ |
|||
# uses gsquery.py to directly query the server |
|||
# detects if the server locks up |
|||
if [ -f gsquery.py ]; then |
|||
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; 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} |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
sleep 1 |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
if [ "${emailnotification}" = "on" ]; then |
|||
@ -347,13 +366,13 @@ if [ -f gsquery.py ]; then |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
elif [ "${exitcode}" == "126" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "Attempting to resolve automatically" |
|||
@ -371,11 +390,11 @@ if [ -f gsquery.py ]; then |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
exit |
|||
fi |
|||
fi |
|||
} |
|||
@ -385,41 +404,41 @@ fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: CHECKING" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog} |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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} |
|||
fn_scriptlog "Checking session: FAIL" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
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 |
|||
fn_scriptlog "Monitor is starting ${servername}" |
|||
fn_startserver |
|||
fi |
|||
else |
|||
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} |
|||
fn_scriptlog "Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog} |
|||
fn_scriptlog "When updates complete ${servicename} will start" |
|||
fi |
|||
} |
|||
|
|||
@ -429,14 +448,14 @@ fn_syscheck |
|||
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 anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog} |
|||
fn_scriptlog "Updating ${servername}" |
|||
cd "${rootdir}" |
|||
cd "steamcmd" |
|||
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" |
|||
} |
|||
|
|||
fn_restartserver(){ |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Restarting ${servername}" |
|||
fn_stopserver |
|||
fn_startserver |
|||
} |
|||
@ -446,15 +465,15 @@ fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 0.5 |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already stopped" |
|||
else |
|||
tmux kill-session -t ${servicename} |
|||
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog} |
|||
fn_scriptlog "Stopped ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
@ -464,65 +483,70 @@ fn_startserver(){ |
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
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} |
|||
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} |
|||
fn_scriptlog "Starting ${servername}" |
|||
sleep 0.5 |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" |
|||
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog} |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
cd ${filesdir} |
|||
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}" |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${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\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} |
|||
fn_scriptlog "failed to start ${servername}" |
|||
else |
|||
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} |
|||
fn_scriptlog "Started ${servername}" |
|||
fi |
|||
sleep 0.5 |
|||
echo -en "\n" |
|||
} |
|||
|
|||
fn_details(){ |
|||
fn_autoip |
|||
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') |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
echo "" |
|||
echo "${gamename} Server Details" |
|||
echo "============================" |
|||
echo "Server name: ${servername}" |
|||
echo "Server IP: ${ip}:${port}" |
|||
echo "RCON password: ${rcon}" |
|||
echo "Config file: ${servercfg}" |
|||
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 "Ports the server is currently using." |
|||
echo "" |
|||
echo "DIRECTION DESCRIPTION PORT" |
|||
echo "INBOUND Game/Rcon Port ${port}" |
|||
echo "INBOUND Game/RCON port ${port}" |
|||
if [ "${engine}" = "source" ]; then |
|||
echo "INBOUND SourceTV Port ${sourcetvport}" |
|||
echo "INBOUND SourceTV port ${sourcetvport}" |
|||
fi |
|||
echo "OUTBOUND Client Port ${clientport}" |
|||
echo "OUTBOUND Client port ${clientport}" |
|||
echo "" |
|||
echo "You can change ports by editing the" |
|||
echo "start parameters in ${selfname}" |
|||
echo "start parameters in ${selfname}." |
|||
echo "" |
|||
echo "${servername} Details" |
|||
echo "=======================" |
|||
echo "Server name: ${servername}" |
|||
echo "Rcon Password: ${rcon}" |
|||
echo "" |
|||
echo "Config file:" |
|||
echo "${servercfg}" |
|||
if [ "${pid}" == "0" ]; then |
|||
echo -e "Status:\e[0;31m OFFLINE\e[0;39m" |
|||
else |
|||
echo -e "Status:\e[0;32m ONLINE\e[0;39m" |
|||
fi |
|||
echo "" |
|||
} |
|||
|
|||
@ -534,7 +558,7 @@ fn_header(){ |
|||
clear |
|||
echo "=================================" |
|||
echo "${gamename}" |
|||
echo "Server Linux Installer" |
|||
echo "Linux Game Server Manager" |
|||
echo "by Daniel Gibbs" |
|||
echo "http://danielgibbs.co.uk" |
|||
echo "=================================" |
|||
@ -542,19 +566,73 @@ echo "" |
|||
} |
|||
|
|||
fn_steamdl(){ |
|||
echo "Installing Steam" |
|||
echo "Installing SteamCMD" |
|||
echo "=================================" |
|||
cd ${rootdir} |
|||
mkdir steamcmd |
|||
cd steamcmd |
|||
cd "${rootdir}" |
|||
mkdir -pv "steamcmd" |
|||
sleep 1 |
|||
cd "steamcmd" |
|||
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 |
|||
chmod +x steamcmd.sh |
|||
sleep 1 |
|||
else |
|||
echo "" |
|||
echo "Steam already installed!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_steaminstall(){ |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${filesdir}" |
|||
cd "${rootdir}/steamcmd" |
|||
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
echo "" |
|||
} |
|||
|
|||
fn_steamfix(){ |
|||
echo "Applying steamclient.so fix" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv ${HOME}/.steam |
|||
mkdir -pv ${HOME}/.steam/sdk32 |
|||
cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_loginstall(){ |
|||
echo "Creating log directorys" |
|||
echo "=================================" |
|||
sleep 1 |
|||
mkdir -pv "${rootdir}/log" |
|||
mkdir -pv "${scriptlogdir}" |
|||
touch "${scriptlog}" |
|||
mkdir -pv "${consolelogdir}" |
|||
touch "${consolelog}" |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv "${gamelogdir}" "${rootdir}/log/server" |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
} |
|||
|
|||
fn_retryinstall(){ |
|||
@ -571,20 +649,19 @@ done |
|||
fn_install(){ |
|||
fn_rootcheck |
|||
fn_header |
|||
if [ -d ${filesdir} ]; then |
|||
if [ -d "${filesdir}" ]; then |
|||
echo "${gamename} Server is already installed here:" |
|||
pwd |
|||
echo "" |
|||
while true; do |
|||
read -p "Continue [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Yy]* ) fn_header; break;; |
|||
[Nn]* ) echo Exiting; return 1;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
|||
fn_header |
|||
echo "Install Directory:" |
|||
pwd |
|||
echo "" |
|||
@ -598,44 +675,21 @@ while true; do |
|||
done |
|||
fn_header |
|||
fn_steamdl |
|||
echo "" |
|||
echo "Installing ${gamename} Server" |
|||
echo "=================================" |
|||
cd ${rootdir}/steamcmd |
|||
mkdir -v ${filesdir} |
|||
touch install.txt |
|||
chmod 0600 install.txt |
|||
echo "login anonymous" > install.txt |
|||
echo "force_install_dir ${filesdir}" >> install.txt |
|||
echo "app_update ${appid} validate" >> install.txt |
|||
echo "quit" >> install.txt |
|||
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt |
|||
rm install.txt |
|||
echo "" |
|||
echo "=================================" |
|||
while true; do |
|||
read -p "Was the install successful? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) break;; |
|||
[Nn]* ) fn_retryinstall;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fn_header |
|||
fn_steaminstall |
|||
fn_steamfix |
|||
fn_loginstall |
|||
echo "Configuring ${gamename} Server" |
|||
echo "=================================" |
|||
sleep 1 |
|||
read -p "Enter server name: " servername |
|||
read -p "Enter rcon password: " rconpass |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating server.cfg" |
|||
touch ${filesdir}/tf/cfg/server.cfg |
|||
echo "exec ${servicename}.cfg" > ${filesdir}/tf/cfg/server.cfg |
|||
echo "Creating server.cfg." |
|||
touch "${defaultcfg}" |
|||
echo "exec ${servicename}.cfg" > "${defaultcfg}" |
|||
sleep 1 |
|||
echo "Creating default config file:" |
|||
sleep 0.5 |
|||
echo "${servercfg}" |
|||
touch ${servercfg} |
|||
echo "Creating ${servicename}.cfg config file." |
|||
touch "${servercfg}" |
|||
{ |
|||
echo -e "// server name" |
|||
echo -e "hostname \"${servername}\"" |
|||
@ -652,28 +706,13 @@ echo "=================================" |
|||
echo -e "sv_logecho 1" |
|||
echo -e "sv_logfile 1" |
|||
echo -e "sv_log_onefile 0" |
|||
}|tee ${servercfg} > /dev/null 2>&1 |
|||
}|tee "${servercfg}" > /dev/null 2>&1 |
|||
sleep 1 |
|||
echo "" |
|||
echo "Creating log directorys" |
|||
mkdir -v ${rootdir}/log |
|||
mkdir -v ${scriptlogdir} |
|||
mkdir -v ${consolelogdir} |
|||
touch ${consolelog} |
|||
if [ ! -h ${rootdir}/log/server ]; then |
|||
ln -sv ${gamelogdir} ${rootdir}/log/server |
|||
else |
|||
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!" |
|||
fi |
|||
sleep 1 |
|||
echo "" |
|||
echo "Applying steamclient.so fix" |
|||
mkdir -v ${HOME}/.steam |
|||
mkdir -v ${HOME}/.steam/sdk32 |
|||
cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so |
|||
sleep 1 |
|||
fn_header |
|||
sleep 1 |
|||
fn_details |
|||
sleep 1 |
|||
echo "=================================" |
|||
echo "Install Complete!" |
|||
echo "" |
|||
|
Loading…
Reference in new issue