#!/bin/bash ### ### TSUser="ts" ## User the TeamSpeak server should run as, please not root. ## RunPath="/var/tss2_rc2" ## Directory where the TeamSpeak server is installed. ## PIDFile="${RunPath}/tsserver2.pid" ## TeamSpeak .pid file, usually in the installation directory. ## INIFile="${RunPath}/server.ini" ## TeamSpeak .ini file, usually the same as install directory. ## LogFile="${RunPath}/server.log" ## Where to store log file, usually the same as install directory. ## # DBPath="${RunPath}" ## Path to TeamSpeak DB, usually the same as install directory. ## # SQLPath="${RunPath}" ## Path to TeamSpeak SQL, usually the same as install directory. ## # HTTPPath="${RunPath}" ## Path to TeamSpeak HTDOCs, usually the same as install directory. ## ### ### ### Status Subroutine ### StatusSub() { if [ -e ${PIDFile} ] then PID=`cat ${PIDFile}` ps -f ${PID} >/dev/null 2>&1 if [ $? -ne 0 ] then echo ">>> The server is not running but the ${PIDFile} exists, and will be removed. <<<" rm ${PIDFile} ExitStat="0" else echo "" echo ">>> TeamSpeak server is up with the following information: <<<" ps -f ${PID} | grep ${PID} | awk '{print "User: "$1" <||> PID: "$2}' echo "" ExitStat="1" fi else echo ">>> TeamSpeak .pid file does not exist, doing thurough check. <<<" ps -ef | grep -v grep | grep server_linux >/dev/null 2>&1 if [ $? -ne 1 ] then echo ">>> TeamSpeak server appears to be running. Setting .pid file <<<" ps -ef | grep -v grep | grep server_linux | head -1 | awk '{print $2}' > ${PIDFile} ExitStat="1" else echo ">>> TeamSpeak server is not running. <<<" ExitStat="0" fi fi } ### ### Start Subroutine ### StartSub() { StatusSub if [ ${ExitStat} = 0 ] then echo ">>> Starting TeamSpeak server. <<<" if [ -e ${RunPath}/server_linux ] && [ -x ${RunPath}/server_linux ] then /bin/su -c "${RunPath}/server_linux -ini=${INIFile} -log=${LogFile} -pid=${PIDFile}" ${TSUser} >/dev/null 2>&1 else echo ">> Could not find server_linux or permissions are incorrect. <<" echo ">> TeamSpeak server not started. <<" fi fi } ### ### Stop Subroutine ### StopSub() { StatusSub if [ ${ExitStat} = 1 ] then echo ">>> Shutting down TeamSpeak server. <<<" kill -15 ${PID} sleep 5 ps -f ${PID} | grep ${PID} >/dev/null 2>&1 if [ $? -ne 1 ] then kill -9 ${PID} rm ${PIDFile} fi fi } ### ### Password Subroutine ### PassSub() { if [ -e ${LogFile} ] then date=`cat ${LogFile} | grep "admin account info: username: admin" | tail -n 1 | sed "s/^\([0-9]\+-[0-9]\+-[0-9]\+ [0-9]\+:[0-9]\+:[0-9]\+\).*$/\1/"` SupPass=`cat ${LogFile} | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: \([a-z0-9]\+\).*$/\1/"` AdmPass=`cat ${LogFile} | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: \([a-z0-9]\+\).*$/\1/"` echo "" echo ">>> Following passwords were generated on $date <<<" echo "superadmin = \"${SupPass}\"" echo "admin = \"${AdmPass}\"" echo "" else echo ">>> server.log not found <<<" fi } ### ### Main Subroutine ### if [[ $1 != "" ]] then case $1 in start) StartSub ;; stop) StopSub ;; restart) StopSub sleep 3 StartSub ;; status) StatusSub ;; passwords) PassSub ;; *) echo "Usage: $0 start|stop|restart|status|passwords" ;; esac else StatusSub echo "Usage: $0 start|stop|restart|status|passwords" fi exit