Browse Source

Merged and updated ts3server

Ts3server now updated and merged in to the new functions method.
This merge has not added any new features but just updated the code.
New features will be added over time.
pull/292/head
Daniel Gibbs 10 years ago
parent
commit
25c0e0e210
  1. 331
      TeamSpeak3/ts3server
  2. 10
      functions/fn_check_ts3status
  3. 62
      functions/fn_details
  4. 19
      functions/fn_details_config
  5. 27
      functions/fn_getopt
  6. 22
      functions/fn_logs
  7. 71
      functions/fn_start
  8. 36
      functions/fn_stop

331
TeamSpeak3/ts3server

@ -3,8 +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: 221113 # Version: 080214
#### Variables #### #### Variables ####
# Notification Email # Notification Email
@ -17,11 +16,23 @@ gamename="Teamspeak 3"
servername="Teamspeak 3 Server" servername="Teamspeak 3 Server"
servicename="ts3-server" servicename="ts3-server"
# Directorys fn_parms(){
rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" parms="-game fof -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
}
# Directories
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
selfname="$(basename $0)"
lockselfname=".${servicename}.lock"
filesdir="${rootdir}/serverfiles" filesdir="${rootdir}/serverfiles"
ini="${servicename}.ini" systemdir="${filesdir}"
backupdir="backups" executabledir="${filesdir}"
executable="./ts3server_startscript.sh"
servercfgdir="${filesdir}"
servercfg="${servicename}.ini"
servercfgfullpath="${servercfgdir}/${servercfg}"
defaultcfg="${servercfgfullpath}" #
backupdir="${rootdir}/backups"
# Logging # Logging
logdays="7" logdays="7"
@ -35,297 +46,31 @@ scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S'
##### Script ##### ##### Script #####
# Do not edit # Do not edit
# unless you know
# what you are doing
fn_rootcheck(){
if [ `whoami` = "root" ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
exit
fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
exit
fi
}
fn_runcheck(){
fn_status
if [ "$ts3status" = "Server is running" ]; then
echo -en "\r[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already running"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
sleep 0.5
echo -en "\n"
exit
fi
}
fn_inicheck(){
if [ ! -e ${filesdir}/${ini} ]; then
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: ${filesdir}/${ini} is missing"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} ${filesdir}/${ini} is missing" >> ${scriptlog}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Creating blank ${ini}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Creating blank ${ini}" >> ${scriptlog}
echo -e "[\e[0;36m INFO \e[0;39m] ${ini} can remain blank by default."
touch ${filesdir}/${ini}
fi
}
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_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
fn_status
if [ "$ts3status" = "Server is running" ]; 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 "[ .... ] Starting ${servicename}: ${servername} backup"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername} backup" >> ${scriptlog}
sleep 0.5
echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} backup"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername} backup" >> ${scriptlog}
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
echo -en "\r${servicename} backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: backup complete" >> ${scriptlog}
}
fn_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "========================================\n${servicename} details\n========================================\n"
echo -e "Service: ${servicename}"
echo -e "Game: ${gamename}"
echo -e "Server: ${servername}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "========================================\nServer details\n========================================\n"
echo -e "Date: $(date)"
echo -e "Distro: ${os}"
echo -e "Arch: ${arch}"
echo -e "Kernel: ${kernel}"
echo -e "Hostname: $HOSTNAME"
echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m"
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
}
fn_emailtest(){ fn_runfunction(){
fn_rootcheck # Functions are downloaded and run with this function
fn_syscheck if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog} cd "${rootdir}"
if [ "${emailnotification}" = "on" ];then if [ ! -d "functions" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}" mkdir functions
failurereason="Testing ${servicename} email notification" fi
actiontaken="Sent test email...hello is this thing on?" cd functions
fn_emailnotification echo -e "loading ${functionfile}...\c"
else wget -N --no-check-certificate /dev/null https://raw.githubusercontent.com/dgibbs64/linuxgameservers/master/functions/${functionfile} 2>&1 | grep -F HTTP | cut -c45-
echo -e "[\e[0;31m FAIL \e[0;39m] Email notification not enabled" chmod +x "${functionfile}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog} cd "${rootdir}"
sleep 1
fi fi
sleep 0.5 source "${rootdir}/functions/${functionfile}"
echo -en "\n"
} }
fn_logmanager(){ fn_functions(){
#Log manager will active if finds logs older than $logdays # Functions are defined in fn_functions.
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then functionfile="${FUNCNAME}"
echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner" fn_runfunction
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
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}
find ${scriptlogdir}/* -mtime +${logdays} |tee >> ${scriptlog}
count=$(find ${scriptlogdir}/* -mtime +${logdays}|wc -l)
find ${scriptlogdir}/* -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}
fi
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_stopserver
fn_startserver
} }
fn_startserver(){ fn_functions
if [ ! -d ${scriptlogdir} ];then
mkdir ${rootdir}/log
mkdir ${scriptlogdir}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} Creating log directorys ${scriptlogdir}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} Creating log directorys ${scriptlogdir}" >> ${scriptlog}
fi
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
fi
fn_rootcheck
fn_syscheck
fn_runcheck
fn_inicheck
fn_logmanager
mv ${scriptlog} ${scriptlogdate}
echo -en "[ .... ] Starting ${servicename}: ${servername}"
${filesdir}/ts3server_startscript.sh start inifile=${ini} > /dev/null 2>&1
sleep 1
fn_status
if [ "$ts3status" = "Server seems to have died" ] || [ "$ts3status" = "No server running (ts3server.pid is missing)" ];then
echo -en "\r[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} Server is unable to start" >> ${scriptlog}
echo -e "Check ${filesdir}/logs for failure reason" |tee ${scriptlog}
else
echo -en "\r[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fi
sleep 0.5
echo -en "\n"
}
fn_stopserver(){
fn_rootcheck
fn_syscheck
fn_status
echo -en "[ .... ] Stopping ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
sleep 0.5
if [ "$ts3status" = "No server running (ts3server.pid is missing)" ];then
echo -en "\r[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
else
echo -en "\r[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
${filesdir}/ts3server_startscript.sh stop inifile=${ini} > /dev/null 2>&1
fi
echo -en "\n"
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_logmanager
echo -en "[ .... ] Monitor is checking ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor is checking ${servername}" >> ${scriptlog}
sleep 0.5
fn_runcheck
echo -en "\r[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!\n"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${scriptlog}
sleep 1
fn_status
if [ "$ts3status" = "Server seems to have died" ];then
echo -en "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} Server seems to have died"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} Server seems to have died" >> ${scriptlog}
failurereason="Server seems to have died"
echo -en "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} No server running (ts3server.pid is missing)"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} No server running (ts3server.pid is missing)" >> ${scriptlog}
failurereason="No server running (ts3server.pid is missing)"
else
echo -en "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} Unknown error"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} Unknown error" >> ${scriptlog}
failurereason="Unknown error"
fi
sleep 0.5
echo -en "\n"
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Monitor - Restarting ${servername}"
actiontaken="restarted ${servername}"
fn_emailnotification
fi
sleep 0.5
echo -en "\n"
fn_restartserver
}
fn_status(){
ts3status=$(${filesdir}/ts3server_startscript.sh status inifile=${ini})
}
case "$1" in getopt=$1
start) fn_getopt
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
backup)
fn_backupserver;;
monitor)
fn_monitorserver;;
email-test)
fn_emailtest;;
*)
echo "Usage: $0 {start|stop|restart|backup|monitor|email-test}"
exit 1;;
esac
exit

10
functions/fn_check_ts3status

@ -0,0 +1,10 @@
#!/bin/bash
# LGSM fn_check_ts3status function
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 070215
# Checks the status of Teamspeak 3.
cd "${executabledir}"
ts3status=$(./ts3server_startscript.sh status servercfgfullpathfile=${servercfgfullpath})

62
functions/fn_details

@ -2,7 +2,7 @@
# LGSM fn_details function # LGSM fn_details function
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 220115 # Version: 080214
# Description: Displays server infomation. # Description: Displays server infomation.
@ -81,6 +81,9 @@ echo -e "\e[34mLocation:£\e[0m${rootdir}" >> .fn_details_gameserver
if [ ! -z "${servercfgfullpath}" ]; then if [ ! -z "${servercfgfullpath}" ]; then
echo -e "\e[34mConfig file:£\e[0m${servercfgfullpath}" >> .fn_details_gameserver echo -e "\e[34mConfig file:£\e[0m${servercfgfullpath}" >> .fn_details_gameserver
fi fi
if [ "${gamename}" == "Teamspeak 3" ]; then
echo -e "\e[34mdbplugin:£\e[0m${dbplugin}" >> .fn_details_gameserver
fi
column -s '£' -t .fn_details_gameserver column -s '£' -t .fn_details_gameserver
rm -f .fn_details_gameserver rm -f .fn_details_gameserver
} }
@ -121,7 +124,7 @@ echo -e ""
# Engine Specific details # Engine Specific details
fn_avalanchedetails(){ fn_details_avalanche(){
fn_check_ip fn_check_ip
fn_details_config fn_details_config
fn_details_distro fn_details_distro
@ -147,7 +150,7 @@ rm -f .fn_details_ports
fn_details_statusbottom fn_details_statusbottom
} }
fn_realvirtualitydetails(){ fn_details_realvirtuality(){
fn_check_ip fn_check_ip
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_parms fn_parms
@ -181,7 +184,7 @@ rm -f .fn_details_ports
fn_details_statusbottom fn_details_statusbottom
} }
fn_seriousengine35details(){ fn_details_seriousengine35(){
fn_check_ip fn_check_ip
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_parms fn_parms
@ -210,7 +213,7 @@ rm -f .fn_details_ports
fn_details_statusbottom fn_details_statusbottom
} }
fn_sourcedetails(){ fn_details_source(){
fn_check_ip fn_check_ip
fn_parms fn_parms
fn_details_config fn_details_config
@ -241,7 +244,7 @@ rm -f .fn_details_ports
fn_details_statusbottom fn_details_statusbottom
} }
fn_sparkdetails(){ fn_details_spark(){
fn_check_ip fn_check_ip
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_parms fn_parms
@ -279,7 +282,34 @@ rm -f .fn_details_ports
fn_details_statusbottom fn_details_statusbottom
} }
fn_unity3ddetails(){ fn_details_teamspeak3(){
fn_details_config
fn_details_distro
fn_details_os
fn_details_performance
fn_details_disk
fn_details_gameserver
fn_details_backup
fn_details_commandlineparms
echo -e ""
echo -e "\e[92mPorts\e[0m"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
echo -e "Change ports by editing the command-line"
echo -e "parameters in ${selfname}."
echo -e ""
echo -e "Useful port diagnostic command:"
echo -e "netstat -atunp | grep ts3server"
echo -e ""
echo -e "DESCRIPTION£DIRECTION£PORT£PROTOCOL" >> .fn_details_ports
echo -e "> Voice£INBOUND£${port}£udp" >> .fn_details_ports
echo -e "> ServerQuery£INBOUND£${queryport}£tcp" >> .fn_details_ports
echo -e "> File transfer£INBOUND£${fileport}£tcp" >> .fn_details_ports
column -s '£' -t .fn_details_ports
rm -f .fn_details_ports
fn_details_statusbottom
}
fn_details_unity3d(){
fn_check_ip fn_check_ip
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_parms fn_parms
@ -326,7 +356,7 @@ rm -f .fn_details_ports
fn_details_statusbottom fn_details_statusbottom
} }
fn_unrealdetails(){ fn_details_unreal(){
fn_check_ip fn_check_ip
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_parms fn_parms
@ -384,19 +414,21 @@ fn_details_statusbottom
} }
if [ "${engine}" == "avalanche" ]; then if [ "${engine}" == "avalanche" ]; then
fn_avalanchedetails fn_details_avalanche
elif [ "${engine}" == "realvirtuality" ]; then elif [ "${engine}" == "realvirtuality" ]; then
fn_realvirtualitydetails fn_details_realvirtuality
elif [ "${engine}" == "seriousengine35" ]; then elif [ "${engine}" == "seriousengine35" ]; then
fn_seriousengine35details fn_details_seriousengine35
elif [ "${engine}" == "source" ]||[ "${engine}" == "goldsource" ]; then elif [ "${engine}" == "source" ]||[ "${engine}" == "goldsource" ]; then
fn_sourcedetails fn_details_source
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
fn_sparkdetails fn_details_spark
elif [ "${engine}" == "unity3d" ]; then elif [ "${engine}" == "unity3d" ]; then
fn_unity3ddetails fn_details_unity3d
elif [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then elif [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
fn_unrealdetails fn_details_unreal
elif [ "${gamename}" == "Teamspeak 3" ]; then
fn_details_teamspeak3
else else
fn_printerrornl "Unable to detect server engine." fn_printerrornl "Unable to detect server engine."
fi fi

19
functions/fn_details_config

@ -2,7 +2,7 @@
# LGSM fn_details_config function # LGSM fn_details_config function
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 210115 # Version: 080215
# Description: Gets specific details from config files. # Description: Gets specific details from config files.
@ -27,7 +27,18 @@ elif [ "${engine}" == "source" ]||[ "${engine}" == "goldsource" ]; then
elif [ "${engine}" == "spark" ]; then elif [ "${engine}" == "spark" ]; then
queryport=$((${port} + 1)) queryport=$((${port} + 1))
elif [ "${gamename}" == "Teamspeak 3" ]; then
if [ -s "${servercfgfullpath}" ]; then
port=$(grep default_voice_port= "${servercfgfullpath}"|tr -cd [:digit:])
queryport=$(grep query_port= "${servercfgfullpath}"|tr -cd [:digit:])
fileport=$(grep filetransfer_port= "${servercfgfullpath}"|tr -cd [:digit:])
ip=$(grep voice_ip= "${servercfgfullpath}"|sed 's/\voice_ip=//g')
dbplugin=$(grep dbplugin= "${servercfgfullpath}"|sed 's/\dbplugin=//g')
else
port="9987"
queryport="10011"
fileport="30033"
fi
elif [ "${engine}" == "unity3d" ]; then elif [ "${engine}" == "unity3d" ]; then
servername=$(grep ServerName "${servercfgfullpath}"|sed 's/^.*value="//'|cut -f1 -d"\"") servername=$(grep ServerName "${servercfgfullpath}"|sed 's/^.*value="//'|cut -f1 -d"\"")
port=$(grep ServerPort "${servercfgfullpath}"|tr -cd [:digit:]) port=$(grep ServerPort "${servercfgfullpath}"|tr -cd [:digit:])
@ -49,11 +60,9 @@ elif [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
webadminport=$(grep ListenPort= "${servercfgfullpath}"|tr -d '\r'|tr -cd [:digit:]) webadminport=$(grep ListenPort= "${servercfgfullpath}"|tr -d '\r'|tr -cd [:digit:])
if [ "${engine}" == "unreal" ]; then if [ "${engine}" == "unreal" ]; then
webadminuser=$(grep AdminUsername= "${servercfgfullpath}"|sed 's/\AdminUsername=//g') webadminuser=$(grep AdminUsername= "${servercfgfullpath}"|sed 's/\AdminUsername=//g')
webadminpass=$(grep UTServerAdmin.UTServerAdmin "${servercfgfullpath}" -A 2| grep AdminPassword= |sed 's/\AdminPassword=//g') webadminpass=$(grep UTServerAdmin.UTServerAdmin "${servercfgfullpath}" -A 2| grep AdminPassword=|sed 's/\AdminPassword=//g')
else else
webadminuser=$(grep AdminName= "${servercfgfullpath}"|sed 's/\AdminName=//g') webadminuser=$(grep AdminName= "${servercfgfullpath}"|sed 's/\AdminName=//g')
webadminpass=$(grep AdminPassword= "${servercfgfullpath}"|sed 's/\AdminPassword=//g') webadminpass=$(grep AdminPassword= "${servercfgfullpath}"|sed 's/\AdminPassword=//g')
fi fi
fi fi

27
functions/fn_getopt

@ -2,7 +2,7 @@
# LGSM fn_getopt function # LGSM fn_getopt function
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 210115 # Version: 080214
# Description: getopt arguments. # Description: getopt arguments.
@ -48,6 +48,31 @@ esac
exit exit
} }
fn_getopt_teamspeak3(){
case "$1" in
start)
fn_start;;
stop)
fn_stop;;
restart)
fn_restart;;
backup)
fn_backup;;
monitor)
fn_monitor;;
email-test)
fn_email_test;;
details)
fn_details;;
backup)
fn_backup;;
*)
echo "Usage: $0 {start|stop|restart|backup|monitor|email-test|details|backup}"
exit 1;;
esac
exit
}
fn_getopt_unreal(){ fn_getopt_unreal(){
case "$getopt" in case "$getopt" in
start) start)

22
functions/fn_logs

@ -2,13 +2,16 @@
# LGSM fn_logs function # LGSM fn_logs function
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 210115 # Version: 080214
# Description: Acts as a log rotater, removing old logs. # Description: Acts as a log rotater, removing old logs.
local modulename="Log Manager" local modulename="Log Manager"
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}" if [ -n "${consolelog}" ]; then
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
fi 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
@ -26,12 +29,17 @@ if [ $(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) -ne "0" ]; then
find "${gamelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${gamelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
fi fi
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" if
if [ -n "${consolelog}" ]; then
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
fi
if [ "${engine}" == "unreal2" ]; then if [ "${engine}" == "unreal2" ]; then
gamecount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) gamecount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
fi fi
scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) if [ -n "${consolelog}" ]; then
consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
fi
count=$((${scriptcount} + ${consolecount})) count=$((${scriptcount} + ${consolecount}))
if [ "${engine}" == "unreal2" ]; then if [ "${engine}" == "unreal2" ]; then
count=$((${scriptcount} + ${consolecount} + ${gamecount})) count=$((${scriptcount} + ${consolecount} + ${gamecount}))
@ -42,7 +50,9 @@ if [ $(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) -ne "0" ]; then
find "${gamelogdir}"/* -mtime +${logdays} -exec rm {} \; find "${gamelogdir}"/* -mtime +${logdays} -exec rm {} \;
fi fi
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; if [ -n "${consolelog}" ]; then
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
fi
fn_printok "Removed ${count} log files" fn_printok "Removed ${count} log files"
fn_scriptlog "Removed ${count} log files" fn_scriptlog "Removed ${count} log files"
sleep 1 sleep 1

71
functions/fn_start

@ -2,11 +2,71 @@
# LGSM fn_start function # LGSM fn_start function
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 210115 # Version: 080214
# Description: Starts the server. # Description: Starts the server.
local modulename="Starting" local modulename="Starting"
fn_start_teamspeak3(){
# Create any missing log dirs
if [ ! -d ${scriptlogdir} ];then
mkdir ${rootdir}/log
mkdir ${scriptlogdir}
fn_printinfo "Creating log directorys ${scriptlogdir}"
fn_scriptlog "Creating log directorys ${scriptlogdir}"
fi
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
fi
fn_check_root
fn_check_systemdir
fn_check_ts3status
if [ "${ts3status}" = "Server is running" ]; then
fn_printinfo "${servername} is already running"
fn_scriptlog "${servername} is already running"
sleep 1
echo -en "\n"
exit
fi
if [ ! -e ${servercfgfullpath} ]; then
fn_printwarn "${servercfgfullpath} is missing"
fn_scriptlog "${servercfgfullpath} is missing"
sleep 1
fn_printinfo "Creating blank ${servercfgfullpath}"
fn_scriptlog "Creating blank ${servercfgfullpath}"
sleep 1
fn_printinfo "${servercfgfullpath} can remain blank by default."
fn_scriptlog "${servercfgfullpath} can remain blank by default."
sleep 1
touch "${servercfgfullpath}"
fi
fn_logs
fn_printdots "${servername}"
fn_scriptlog "${servername}"
sleep 1
mv "${scriptlog}" "${scriptlogdate}"
# Create lock file
date > "${rootdir}/${lockselfname}"
cd "${executabledir}"
./ts3server_startscript.sh start inifile=${servercfgfullpath} > /dev/null 2>&1
sleep 1
fn_check_ts3status
#
if [ "${ts3status}" = "Server seems to have died" ] || [ "${ts3status}" = "No server running (ts3server.pid is missing)" ];then
fn_printfailnl "Unable to start ${servername}"
fn_scriptlog "Unable to start ${servername}"
echo -en " Check log files: ${rootdir}/log"
else
fn_printok "${servername}"
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_start_tmux(){
fn_check_root fn_check_root
fn_check_systemdir fn_check_systemdir
fn_check_ip fn_check_ip
@ -66,4 +126,11 @@ else
fi fi
rm "${scriptlogdir}/.${servicename}-tmux-error.tmp" rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
}
if [ "${gamename}" == "Teamspeak 3" ]; then
fn_start_teamspeak3
else
fn_start_tmux
fi

36
functions/fn_stop

@ -2,11 +2,34 @@
# LGSM fn_stop function # LGSM fn_stop function
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk # Website: http://danielgibbs.co.uk
# Version: 210115 # Version: 080214
# Description: Stops the server. # Description: Stops the server.
local modulename="Stopping" local modulename="Stopping"
fn_stop_teamspeak3(){
fn_check_root
fn_check_systemdir
fn_printdots "${servername}"
fn_scriptlog "${servername}"
sleep 1
fn_check_ts3status
if [ "${ts3status}" = "No server running (ts3server.pid is missing)" ];then
fn_printfail "${servername} is already stopped"
fn_scriptlog "${servername} is already stopped"
else
${filesdir}/ts3server_startscript.sh stop inifile=${ini} > /dev/null 2>&1
fn_printok "${servername}"
fn_scriptlog "Stopped ${servername}"
fi
# Remove lock file
rm -f "${rootdir}/${lockselfname}"
sleep 1
echo -en "\n"
}
fn_stop_tmux(){
fn_check_root fn_check_root
fn_check_systemdir fn_check_systemdir
fn_details_config fn_details_config
@ -24,6 +47,13 @@ else
fn_scriptlog "Stopped ${servername}" fn_scriptlog "Stopped ${servername}"
fi fi
# Remove lock file # Remove lock file
rm -f "${lockselfname}" rm -f "${rootdir}/${lockselfname}"
sleep 1 sleep 1
echo -en "\n" echo -en "\n"
}
if [ "${gamename}" == "Teamspeak 3" ]; then
fn_stop_teamspeak3
else
fn_stop_tmux
fi
Loading…
Cancel
Save