Browse Source
* Synced the scripts so all functions correctly match * updated fn_autoip so 127.0.0.0 range should be ignored * glibcfix function added where required * Fixed update-restart bug causing the lockfile to be created in the wrong directory #172 * gmodserver libsteamfix added * General code tidy uppull/175/head
23 changed files with 1003 additions and 707 deletions
@ -3,7 +3,7 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 170914 |
|||
# Version: 200914 |
|||
|
|||
#### Variables #### |
|||
|
|||
@ -15,6 +15,7 @@ email="[email protected]" |
|||
# Directories |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )" |
|||
selfname="$0" |
|||
lockselfname=$(echo ".${servicename}.lock") |
|||
filesdir="${rootdir}/serverfiles" |
|||
systemdir="${filesdir}/System" |
|||
executabledir="${systemdir}" |
|||
@ -96,7 +97,7 @@ fn_printwarn(){ |
|||
fn_printwarnnl(){ |
|||
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" |
|||
} |
|||
|
|||
|
|||
# [ .... ] |
|||
fn_printdots(){ |
|||
echo -en "\r\033[K[ .... ] $@" |
|||
@ -119,8 +120,8 @@ 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) |
|||
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0|wc -l) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
fn_printwarn "Multiple active network interfaces.\n\n" |
|||
@ -141,28 +142,40 @@ fi |
|||
# log manager will active if finds logs older than ${logdays} |
|||
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then |
|||
fn_printdots "Starting log cleaner" |
|||
sleep 1 |
|||
sleep 1 |
|||
fn_printok "Starting log cleaner" |
|||
sleep 1 |
|||
fn_scriptlog "Starting log cleaner" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_printinfo "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_scriptlog "Removing logs older than ${logdays} days" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
if [ "${engine}" == "unreal2" ]; then |
|||
find "${gamelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
fi |
|||
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" |
|||
if [ "${engine}" == "unreal2" ]; then |
|||
gamecount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) |
|||
fi |
|||
scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) |
|||
consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
if [ "${engine}" == "unreal2" ]; then |
|||
count=$((${scriptcount} + ${consolecount} + ${gamecount})) |
|||
else |
|||
count=$((${scriptcount} + ${consolecount})) |
|||
fi |
|||
if [ "${engine}" == "unreal2" ]; then |
|||
find "${gamelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
fi |
|||
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; |
|||
fn_printok "Log cleaner removed ${count} log files" |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_scriptlog "Log cleaner removed ${count} log files" |
|||
fi |
|||
} |
|||
|
|||
@ -232,8 +245,8 @@ sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
fn_printoknl "Starting ${servicename} console" |
|||
sleep 1 |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
fn_printfailnl "Starting ${servicename} console: ${servername} not running" |
|||
@ -284,8 +297,8 @@ fi |
|||
fn_printdots "Starting backup ${servicename}: ${servername}" |
|||
sleep 1 |
|||
fn_printok "Starting backup ${servicename}: ${servername}" |
|||
sleep 1 |
|||
fn_scriptlog "Backup started" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
cd "${rootdir}" |
|||
mkdir -pv "${backupdir}" > /dev/null 2>&1 |
|||
@ -353,9 +366,9 @@ if [ ! -z "${gamelogdir}" ]; then |
|||
fi |
|||
mail -s "${subject}" ${email} < "${emaillog}" |
|||
fn_printinfo "Sent email notification to ${email}" |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_scriptlog "Sent email notification to ${email}" |
|||
} |
|||
|
|||
fn_emailtest(){ |
|||
@ -386,11 +399,11 @@ if [ -f gsquery.py ]; then |
|||
port=$((${port} + 1)) |
|||
fi |
|||
fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" |
|||
sleep 1 |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" |
|||
sleep 1 |
|||
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" |
|||
sleep 1 |
|||
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) |
|||
exitcode=$? |
|||
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then |
|||
@ -400,9 +413,8 @@ if [ -f gsquery.py ]; then |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
if [[ -z "${secondquery}" ]]; then |
|||
fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" |
|||
sleep 1 |
|||
fn_scriptlog "Waiting 30 seconds to re-query" |
|||
sleep 29 |
|||
sleep 30 |
|||
secondquery=1 |
|||
fn_serverquery |
|||
fi |
|||
@ -416,14 +428,14 @@ if [ -f gsquery.py ]; then |
|||
exit |
|||
elif [ "${exitcode}" == "0" ]; then |
|||
fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
fn_scriptlog "Querying port: ${ip}:${port}: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
elif [ "${exitcode}" == "126" ]; then |
|||
fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" |
|||
sleep 1 |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "Attempting to resolve automatically" |
|||
chmod +x -v gsquery.py |
|||
@ -440,9 +452,9 @@ if [ -f gsquery.py ]; then |
|||
fi |
|||
else |
|||
fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" |
|||
./gsquery.py -a ${ip} -p ${port} -e ${engine} |
|||
exit |
|||
fi |
|||
@ -454,26 +466,26 @@ fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_printdots "Monitoring ${servicename}: ${servername}" |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
if [ ! -f ${lockselfname} ]; then |
|||
if [ ! -f ${lockselfname} ]; then |
|||
fn_printinfo "Monitoring ${servicename}: No lock file found: Monitor disabled" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "To enable monitor run ${selfname} start" |
|||
exit |
|||
fi |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" |
|||
sleep 1 |
|||
fn_scriptlog "Checking session: CHECKING" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
fn_printok "Monitoring ${servicename}: Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_serverquery |
|||
exit |
|||
else |
|||
@ -492,11 +504,11 @@ if [ "${updatecheck}" = "0" ]; then |
|||
fi |
|||
else |
|||
fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
fn_scriptlog "Detected SteamCMD is checking for updates" |
|||
sleep 1 |
|||
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" |
|||
sleep 1 |
|||
fn_scriptlog "When updates complete ${servicename} will start" |
|||
sleep 1 |
|||
fi |
|||
} |
|||
|
|||
@ -511,8 +523,8 @@ fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) |
|||
fn_printdots "Stopping ${servicename}: ${servername}" |
|||
sleep 1 |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 1 |
|||
if [ "${pid}" == "0" ]; then |
|||
fn_printfail "Stopping ${servicename}: ${servername} is already stopped" |
|||
fn_scriptlog "${servername} is already stopped" |
|||
@ -535,6 +547,9 @@ 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 |
|||
if [ "${engine}" == "unreal2" ]; then |
|||
mv "${gamelog}" "${gamelogdate}" |
|||
fi |
|||
mv "${scriptlog}" "${scriptlogdate}" |
|||
mv "${consolelog}" "${consolelogdate}" |
|||
fi |
|||
@ -543,13 +558,13 @@ sleep 1 |
|||
fn_scriptlog "Starting ${servername}" |
|||
if [ ${tmuxwc} -eq 1 ]; then |
|||
fn_printinfo "Starting ${servicename}: ${servername} is already running" |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_scriptlog "${servername} is already running" |
|||
exit |
|||
fi |
|||
# Create lock file |
|||
date > ${lockselfname} |
|||
date > ${rootdir}/${lockselfname} |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${parms}" |
|||
tmux pipe-pane -o -t ${servicename} "exec cat >> '${consolelog}'" |
|||
@ -783,7 +798,7 @@ fn_getquery(){ |
|||
while true; do |
|||
read -p "Do you want to install GameServerQuery? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) wget -nv "http://danielgibbs.co.uk/dl/gsquery.py"; chmod +x gsquery.py;break;; |
|||
[Yy]* ) wget -nv -N "http://danielgibbs.co.uk/dl/gsquery.py"; chmod +x gsquery.py;break;; |
|||
[Nn]* ) echo -e "Not installing GameServerQuery.";break;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
|
Loading…
Reference in new issue