9 changed files with 388 additions and 5 deletions
@ -0,0 +1,22 @@ |
|||
#!/bin/bash |
|||
# LGSM fn_autoip function |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 011214 |
|||
|
|||
# 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) |
|||
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -vc 127.0.0) |
|||
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then |
|||
if [ "${getipwc}" -ge "2" ]; then |
|||
fn_printwarn "Multiple active network interfaces.\n\n" |
|||
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n" |
|||
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n" |
|||
echo -en "${getip}\n" |
|||
exit |
|||
else |
|||
ip=${getip} |
|||
fi |
|||
fi |
@ -0,0 +1,48 @@ |
|||
#!/bin/bash |
|||
# LGSM fn_backupserver function |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 011214 |
|||
|
|||
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 -Ec "^${servicename}:") |
|||
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 |
|||
fn_printdots "Starting backup ${servicename}: ${servername}" |
|||
sleep 1 |
|||
fn_printok "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" |
@ -0,0 +1,43 @@ |
|||
#!/bin/bash |
|||
# LGSM fn_console function |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 011214 |
|||
|
|||
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 |
|||
fn_printdots "Starting ${servicename} console" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:") |
|||
if [ "${tmuxwc}" -eq 1 ]; then |
|||
fn_printoknl "Starting ${servicename} console" |
|||
fn_scriptlog "Console accessed" |
|||
sleep 1 |
|||
tmux attach-session -t ${servicename} |
|||
else |
|||
fn_printfailnl "Starting ${servicename} console: ${servername} not running" |
|||
sleep 1 |
|||
while true; do |
|||
read -p "Do you want to start the server? [y/N]" yn |
|||
case $yn in |
|||
[Yy]* ) fn_startserver; break;; |
|||
[Nn]* ) break;; |
|||
* ) echo "Please answer yes or no.";; |
|||
esac |
|||
done |
|||
fi |
@ -0,0 +1,47 @@ |
|||
#!/bin/bash |
|||
# LGSM fn_logmanager function |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 011214 |
|||
|
|||
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 |
|||
fn_printdots "Starting log cleaner" |
|||
sleep 1 |
|||
fn_printok "Starting log cleaner" |
|||
fn_scriptlog "Starting log cleaner" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_printinfo "Removing logs older than ${logdays} days" |
|||
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" |
|||
fi |
@ -0,0 +1,55 @@ |
|||
#!/bin/bash |
|||
# LGSM fn_monitorserver function |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 011214 |
|||
|
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_printdots "Monitoring ${servicename}: ${servername}" |
|||
fn_scriptlog "Monitoring ${servername}" |
|||
sleep 1 |
|||
if [ ! -f "${lockselfname}" ]; then |
|||
fn_printinfo "Monitoring ${servicename}: Monitor disabled: No lock file found" |
|||
fn_scriptlog "Monitor disabled: No lock file found" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
echo "To enable monitor run ${selfname} start" |
|||
exit |
|||
fi |
|||
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) |
|||
if [ "${updatecheck}" = "0" ]; then |
|||
fn_printdots "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 |
|||
fn_printok "Monitoring ${servicename}: Checking session: OK" |
|||
fn_scriptlog "Checking session: OK" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_serverquery |
|||
exit |
|||
else |
|||
fn_printfail "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 |
|||
fn_printinfonl "Monitoring ${servicename}: 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_scriptlog "When updates complete ${servicename} will start" |
|||
sleep 1 |
|||
fi |
@ -0,0 +1,78 @@ |
|||
#!/bin/bash |
|||
# LGSM fn_serverquery function |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 011214 |
|||
|
|||
# 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)) |
|||
elif [ "${engine}" == "realvirtuality" ]; then |
|||
port=${queryport} |
|||
fi |
|||
fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" |
|||
fn_scriptlog "Detected gsquery.py" |
|||
sleep 1 |
|||
fn_printdots "Monitoring ${servicename}: 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) |
|||
exitcode=$? |
|||
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then |
|||
fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" |
|||
if [[ -z "${secondquery}" ]]; then |
|||
fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" |
|||
fn_scriptlog "Waiting 30 seconds to re-query" |
|||
sleep 30 |
|||
secondquery=1 |
|||
fn_serverquery |
|||
fi |
|||
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 |
|||
fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" |
|||
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" |
|||
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 |
|||
fn_printfail "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 |
@ -0,0 +1,52 @@ |
|||
#!/bin/bash |
|||
# LGSM fn_startserver function |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 011214 |
|||
|
|||
fn_rootcheck |
|||
fn_syscheck |
|||
fn_autoip |
|||
fn_parms |
|||
fn_logmanager |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:") |
|||
if [ "${tmuxwc}" -eq 0 ]; then |
|||
fn_scriptlog "Rotating log files" |
|||
if [ "${engine}" == "unreal2" ]; then |
|||
mv "${gamelog}" "${gamelogdate}" |
|||
fi |
|||
mv "${scriptlog}" "${scriptlogdate}" |
|||
mv "${consolelog}" "${consolelogdate}" |
|||
fi |
|||
fn_printdots "Starting ${servicename}: ${servername}" |
|||
fn_scriptlog "Starting ${servername}" |
|||
sleep 1 |
|||
if [ "${tmuxwc}" -eq 1 ]; then |
|||
fn_printinfo "Starting ${servicename}: ${servername} is already running" |
|||
fn_scriptlog "${servername} is already running" |
|||
sleep 1 |
|||
echo -en "\n" |
|||
exit |
|||
fi |
|||
# Create lock file |
|||
date > "${rootdir}/${lockselfname}" |
|||
cd "${executabledir}" |
|||
tmux new-session -d -s ${servicename} "${executable} ${parms}" 2> "${scriptlogdir}/.${servicename}-tmux-error.tmp" |
|||
tmux pipe-pane -o -t ${servicename} "exec cat >> '${consolelog}'" |
|||
sleep 1 |
|||
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") |
|||
if [ "${tmuxwc}" -eq 0 ]; then |
|||
fn_printfailnl "Starting ${servicename}: Failed to start ${servername}" |
|||
echo -en " Check log files: ${rootdir}/log" |
|||
fn_scriptlog "failed to start ${servername}" |
|||
if [ -a "${scriptlogdir}/.${servicename}-tmux-error.tmp" ]; then |
|||
fn_scriptlog "tmux returned the following error" |
|||
cat "${scriptlogdir}/.${servicename}-tmux-error.tmp" >> "${scriptlog}" |
|||
fi |
|||
else |
|||
fn_printok "Starting ${servicename}: ${servername}" |
|||
fn_scriptlog "Started ${servername}" |
|||
fi |
|||
rm "${scriptlogdir}/.${servicename}-tmux-error.tmp" |
|||
sleep 1 |
|||
echo -en "\n" |
@ -0,0 +1,24 @@ |
|||
#!/bin/bash |
|||
# LGSM fn_stopserver function |
|||
# Author: Daniel Gibbs |
|||
# Website: http://danielgibbs.co.uk |
|||
# Version: 011214 |
|||
|
|||
fn_rootcheck |
|||
fn_syscheck |
|||
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:") |
|||
fn_printdots "Stopping ${servicename}: ${servername}" |
|||
fn_scriptlog "Stopping ${servername}" |
|||
sleep 1 |
|||
if [ "${pid}" == "0" ]; then |
|||
fn_printfail "Stopping ${servicename}: ${servername} is already stopped" |
|||
fn_scriptlog "${servername} is already stopped" |
|||
else |
|||
tmux kill-session -t ${servicename} |
|||
fn_printok "Stopping ${servicename}: ${servername}" |
|||
fn_scriptlog "Stopped ${servername}" |
|||
fi |
|||
# Remove lock file |
|||
rm -f "${lockselfname}" |
|||
sleep 1 |
|||
echo -en "\n" |
Loading…
Reference in new issue