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