Added all Existing project files

This commit is contained in:
Daniel Gibbs 2013-08-11 12:03:31 +01:00
parent 2cbbb321b9
commit 10028d7e0f
10 changed files with 4166 additions and 0 deletions

499
CounterStrike/csserver Normal file
View File

@ -0,0 +1,499 @@
#!/bin/bash
# Counter Strike
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 010813
#### Variables ####
# Notification Email
# (on|off)
emailnotification="off"
email="email@example.com"
# Start vars
defaultmap="de_aztec"
port="27015"
parms="-game cstrike +map ${defaultmap} -strictportbind +port ${port}"
#### Advanced Variables ####
# Steam
appid="90"
# Directorys
rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/cs"
servercfg="${filesdir}/cstrike/server.cfg"
# Server names
servicename="cs-server"
gamename="Counter Strike 1.6"
servername=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
# Logging
logdir="${rootdir}/log/script"
gamelogdir="${filesdir}/cstrike/logs"
logfile="${logdir}/${servicename}.log"
logfiledate="${logdir}/${servicename}-$( date '+%d-%m-%Y-%H-%M-%S').log"
logdays="7"
##### Script #####
# 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_serverquery(){
# uses serverquery.py to directly query the server
# detects if the server locks up
if [ -f serverquery.py ];then
echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${logfile}
serverquery=`./serverquery.py 127.0.0.1 ${port} 2>&1`
sleep 1
if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${logfile}
sleep 1
fn_restartserver
else
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
fi
fi
}
fn_runcheck(){
# already running check
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 1 ];then
fn_serverquery
echo -e "[\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" >> ${logfile}
exit
# multiple of same instance check
elif [ ${pidwc} -ge 2 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: ${servername} is running ${pidwc} times"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is running ${pidwc} times" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] ${servicename}: Stopping ${pidwc} instances of ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${pidwc} instances of ${servername}" >> ${logfile}
fn_stopserver
exit
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_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "=========================================\nServer information\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 "=========================================\n${servicename} statistics\n=========================================\n"
echo -e "Service: ${servicename}"
echo -e "Server: ${servername}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "=========================================\n${servicename} log summary\n=========================================\n"
}|tee ${logdir}/${servicename}-email.log > /dev/null 2>&1
tail -50 ${logfile} >> /${logdir}/${servicename}-email.log
mail -s "${subject}" ${email} < /${logdir}/${servicename}-email.log
echo -e "[\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}" >> ${logfile}
}
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Emailing test notification"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification
else
echo -e "[\e[0;31m FAIL \e[0;39m] Email notificaion not enabled"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Email notificaion not enabled" >> ${logfile}
fi
}
fn_logmanager(){
# log manager will active if finds logs older than $logdays
if [ `find ${logdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then
echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${logfile}
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" >> ${logfile}
find ${logdir}/* -mtime +${logdays} |tee >> ${logfile}
count=`find ${logdir}/* -mtime +${logdays}|wc -l`
find ${logdir}/* -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" >> ${logfile}
fi
}
fn_restartserver(){
echo -e "[\e[0;32m OK \e[0;39m] Restarting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${logfile}
fn_stopserver
sleep 1
fn_startserver
}
fn_startserver(){
fn_rootcheck
fn_syscheck
fn_runcheck
fn_logmanager
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${logfile}
cp ${logfile} ${logfiledate}
screen -d -m -S ${servicename} ./hlds_run ${parms}
sleep 1
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 0 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: Failed to start ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${logfile}
fi
}
fn_stopserver(){
fn_rootcheck
fn_syscheck
pid=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
if [ -z ${pid} ];then
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already stopped"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${logfile}
else
echo -e "[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${logfile}
kill `screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
screen -wipe > /dev/null 2>&1
fi
}
fn_debugserver(){
fn_rootcheck
fn_syscheck
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} in debug mode!"
sleep 0.5
echo -e ""
echo -e "Use for identifying server issues only!"
while true; do
echo "If server is already running it will be stopped"
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_stopserver
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Press CTRL+C to drop out of debug mode"
sleep 3
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
./hlds_run ${parms} -debug
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_logmanager
echo -e "[\e[0;32m OK \e[0;39m] Checking ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Checking ${servername}" >> ${logfile}
updatecheck=`ps -ef|grep "${selfname} update"|grep -v grep|wc -l`
if [ "${updatecheck}" = "0" ];then
fn_runcheck
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servername} had stopped"
actiontaken="restarted ${servername}"
fn_emailnotification
fi
fn_startserver
else
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${logfile}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${logfile}
fi
}
fn_updateserver(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${logfile}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
}
#
##Installer
#
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
if [ ! -f steam.sh ];then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steam.sh
else
echo "Steam already installed!"
fi
}
fn_retryinstall(){
while true; do
read -p "Retry install? [y/N]" yn
case $yn in
[Yy]* ) fn_install;;
[Nn]* ) echo Exiting; exit ;;
* ) echo "Please answer yes or no.";;
esac
done
}
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ];then
echo "${gamename} Server is already installed here:"
pwd
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
fi
fn_header
echo "Install Directory:"
pwd
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_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
rm -f ${servercfg}
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
mkdir -v ${rootdir}/log
mkdir -v ${logdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steam.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall ;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Configuring ${gamename} Server"
echo "================================="
read -p "Enter rcon password: " rconpass
read -p "Enter server name: " servername
sleep 1
echo ""
echo "Creating server.cfg"
touch ${servercfg}
touch ${filesdir}/cstrike/listip.cfg
touch ${filesdir}/cstrike/banned.cfg
{
echo -e "// Use this file to configure your DEDICATED server."
echo -e "// This config file is executed on server start."
echo -e ""
echo -e "// disable autoaim"
echo -e "sv_aim 0"
echo -e ""
echo -e "// disable clients' ability to pause the server"
echo -e "pausable 0"
echo -e ""
echo -e "// default server name. Change to \"Bob's Server\", etc."
echo -e "hostname \"${servername}\""
echo -e ""
echo -e "// maximum client movement speed "
echo -e "sv_maxspeed 320"
echo -e ""
echo -e "// 20 minute timelimit"
echo -e "mp_timelimit 20"
echo -e ""
echo -e "// cheats off"
echo -e "sv_cheats 0"
echo -e ""
echo -e "// load ban files"
echo -e "exec listip.cfg"
echo -e "exec banned.cfg"
echo -e ""
echo -e "// rcon passsword"
echo -e "rcon_password \"${rconpass}\""
echo -e ""
echo -e "// Server password"
echo -e "sv_password \"\""
echo -e ""
echo -e "// server logging"
echo -e "log on"
echo -e "sv_logbans 1"
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
sleep 1
echo ""
echo "Setting up logging"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${rootdir}/.steam
mkdir -v ${rootdir}/.steam/sdk32
cp -v ${filesdir}/steamclient.so ${rootdir}/.steam/sdk32/steamclient.so
sleep 1
echo ""
echo "${gamename} Server Details"
echo "================================="
hostname=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
rcon=`grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g'`
echo "Server hostname: ${hostname}"
echo "Rcon password: ${rcon}"
echo "You can edit these in server.cfg:"
echo "${servercfg}"
echo ""
echo "Server IP: localhost:27015"
echo "You can change port by editing the"
echo "start parms in ${selfname}"
echo "================================="
echo "Install Complete!"
echo ""
echo "To start server type:"
echo "${selfname} start"
echo ""
}
case "$1" in
start)
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
update)
fn_stopserver
fn_updateserver
fn_startserver;;
monitor)
fn_monitorserver;;
install)
fn_install;;
debug)
fn_debugserver;;
email-test)
fn_emailtest;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|install|debug|email-test}"
exit 1;;
esac
exit

View File

@ -0,0 +1,476 @@
#!/bin/bash
# Counter Strike: Source
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 010813
#### Variables ####
# Notification Email
# (on|off)
emailnotification="off"
email="email@example.com"
# Start vars
defaultmap="de_dust"
port="27015"
sourcetvport="27020"
clientport="27005"
parms="-game cstrike +map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport}"
#### Advanced Variables ####
# Steam
appid="232330"
# Directorys
rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/css"
servercfg="${filesdir}/cstrike/cfg/server.cfg"
# Server names
servicename="css-server"
gamename="Counter Strike: Source"
servername=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
# Logging
logdir="${rootdir}/log/script"
gamelogdir="${filesdir}/cstrike/logs"
logfile="${logdir}/${servicename}.log"
logfiledate="${logdir}/${servicename}-$( date '+%d-%m-%Y-%H-%M-%S').log"
logdays="7"
##### Script #####
# 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_serverquery(){
# uses serverquery.py to directly query the server
# detects if the server locks up
if [ -f serverquery.py ];then
echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${logfile}
serverquery=`./serverquery.py 127.0.0.1 ${port} 2>&1`
sleep 1
if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${logfile}
sleep 1
fn_restartserver
else
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
fi
fi
}
fn_runcheck(){
# already running check
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 1 ];then
fn_serverquery
echo -e "[\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" >> ${logfile}
exit
# multiple of same instance check
elif [ ${pidwc} -ge 2 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: ${servername} is running ${pidwc} times"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is running ${pidwc} times" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] ${servicename}: Stopping ${pidwc} instances of ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${pidwc} instances of ${servername}" >> ${logfile}
fn_stopserver
exit
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_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "=========================================\nServer information\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 "=========================================\n${servicename} statistics\n=========================================\n"
echo -e "Service: ${servicename}"
echo -e "Server: ${servername}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "=========================================\n${servicename} log summary\n=========================================\n"
}|tee ${logdir}/${servicename}-email.log > /dev/null 2>&1
tail -50 ${logfile} >> /${logdir}/${servicename}-email.log
mail -s "${subject}" ${email} < /${logdir}/${servicename}-email.log
echo -e "[\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}" >> ${logfile}
}
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Emailing test notification"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification
else
echo -e "[\e[0;31m FAIL \e[0;39m] Email notificaion not enabled"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Email notificaion not enabled" >> ${logfile}
fi
}
fn_logmanager(){
# log manager will active if finds logs older than $logdays
if [ `find ${logdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then
echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${logfile}
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" >> ${logfile}
find ${logdir}/* -mtime +${logdays} |tee >> ${logfile}
count=`find ${logdir}/* -mtime +${logdays}|wc -l`
find ${logdir}/* -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" >> ${logfile}
fi
}
fn_restartserver(){
echo -e "[\e[0;32m OK \e[0;39m] Restarting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${logfile}
fn_stopserver
sleep 1
fn_startserver
}
fn_startserver(){
fn_rootcheck
fn_syscheck
fn_runcheck
fn_logmanager
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${logfile}
cp ${logfile} ${logfiledate}
screen -d -m -S ${servicename} ${filesdir}/srcds_run ${parms}
sleep 1
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 0 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: Failed to start ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${logfile}
fi
}
fn_stopserver(){
fn_rootcheck
fn_syscheck
pid=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
if [ -z ${pid} ];then
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already stopped"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${logfile}
else
echo -e "[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${logfile}
kill `screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
screen -wipe > /dev/null 2>&1
fi
}
fn_debugserver(){
fn_rootcheck
fn_syscheck
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} in debug mode!"
sleep 0.5
echo -e ""
echo -e "Use for identifying server issues only!"
while true; do
echo "If server is already running it will be stopped"
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_stopserver
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Press CTRL+C to drop out of debug mode"
sleep 3
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
${filesdir}/srcds_run ${parms} -debug
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_logmanager
echo -e "[\e[0;32m OK \e[0;39m] Checking ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Checking ${servername}" >> ${logfile}
updatecheck=`ps -ef|grep "${selfname} update"|grep -v grep|wc -l`
if [ "${updatecheck}" = "0" ];then
fn_runcheck
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servername} had stopped"
actiontaken="restarted ${servername}"
fn_emailnotification
fi
fn_startserver
else
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${logfile}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${logfile}
fi
}
fn_updateserver(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${logfile}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
}
#
##Installer
#
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
if [ ! -f steam.sh ];then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steam.sh
else
echo "Steam already installed!"
fi
}
fn_retryinstall(){
while true; do
read -p "Retry install? [y/N]" yn
case $yn in
[Yy]* ) fn_install;;
[Nn]* ) echo Exiting; exit ;;
* ) echo "Please answer yes or no.";;
esac
done
}
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ];then
echo "${gamename} Server is already installed here:"
pwd
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
fi
fn_header
echo "Install Directory:"
pwd
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_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
mkdir -v ${rootdir}/log
mkdir -v ${logdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steam.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall ;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Configuring ${gamename} Server"
echo "================================="
read -p "Enter rcon password: " rconpass
read -p "Enter server name: " servername
sleep 1
echo ""
echo "Creating server.cfg"
touch ${servercfg}
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
echo -e ""
echo -e "// rcon passsword"
echo -e "rcon_password \"${rconpass}\""
echo -e ""
echo -e "// Server password"
echo -e "sv_password \"\""
echo -e ""
echo -e "// server logging"
echo -e "log on"
echo -e "sv_logbans 1"
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
sleep 1
echo ""
echo "Setting up logging"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${rootdir}/.steam
mkdir -v ${rootdir}/.steam/sdk32
cp -v ${filesdir}/bin/steamclient.so ${rootdir}/.steam/sdk32/steamclient.so
sleep 1
echo ""
echo "${gamename} Server Details"
echo "================================="
hostname=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
rcon=`grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g'`
echo "Server hostname: ${hostname}"
echo "Rcon password: ${rcon}"
echo "You can edit these in server.cfg:"
echo "${servercfg}"
echo ""
echo "Server IP: localhost:27015"
echo "You can change port by editing the"
echo "start parms in ${selfname}"
echo "================================="
echo "Install Complete!"
echo ""
echo "To start server type:"
echo "${selfname} start"
echo ""
}
case "$1" in
start)
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
update)
fn_stopserver
fn_updateserver
fn_startserver;;
monitor)
fn_monitorserver;;
install)
fn_install;;
debug)
fn_debugserver;;
email-test)
fn_emailtest;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|install|debug|email-test}"
exit 1;;
esac
exit

View File

@ -0,0 +1,476 @@
#!/bin/bash
# Day of Defeat: Source
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 010813
#### Variables ####
# Notification Email
# (on|off)
emailnotification="off"
email="email@example.com"
# Start vars
defaultmap="dod_Anzio"
port="27015"
sourcetvport="27020"
clientport="27005"
parms="-game dod +map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport}"
#### Advanced Variables ####
# Steam
appid="232290"
# Directorys
rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/dods"
servercfg="${filesdir}/dod/cfg/server.cfg"
# Server names
servicename="dods-server"
gamename="Day of Defeat: Source"
servername=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
# Logging
logdir="${rootdir}/log/script"
gamelogdir="${filesdir}/dod/logs"
logfile="${logdir}/${servicename}.log"
logfiledate="${logdir}/${servicename}-$( date '+%d-%m-%Y-%H-%M-%S').log"
logdays="7"
##### Script #####
# 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_serverquery(){
# uses serverquery.py to directly query the server
# detects if the server locks up
if [ -f serverquery.py ];then
echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${logfile}
serverquery=`./serverquery.py 127.0.0.1 ${port} 2>&1`
sleep 1
if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${logfile}
sleep 1
fn_restartserver
else
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
fi
fi
}
fn_runcheck(){
# already running check
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 1 ];then
fn_serverquery
echo -e "[\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" >> ${logfile}
exit
# multiple of same instance check
elif [ ${pidwc} -ge 2 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: ${servername} is running ${pidwc} times"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is running ${pidwc} times" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] ${servicename}: Stopping ${pidwc} instances of ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${pidwc} instances of ${servername}" >> ${logfile}
fn_stopserver
exit
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_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "=========================================\nServer information\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 "=========================================\n${servicename} statistics\n=========================================\n"
echo -e "Service: ${servicename}"
echo -e "Server: ${servername}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "=========================================\n${servicename} log summary\n=========================================\n"
}|tee ${logdir}/${servicename}-email.log > /dev/null 2>&1
tail -50 ${logfile} >> /${logdir}/${servicename}-email.log
mail -s "${subject}" ${email} < /${logdir}/${servicename}-email.log
echo -e "[\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}" >> ${logfile}
}
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Emailing test notification"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification
else
echo -e "[\e[0;31m FAIL \e[0;39m] Email notificaion not enabled"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Email notificaion not enabled" >> ${logfile}
fi
}
fn_logmanager(){
# log manager will active if finds logs older than $logdays
if [ `find ${logdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then
echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${logfile}
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" >> ${logfile}
find ${logdir}/* -mtime +${logdays} |tee >> ${logfile}
count=`find ${logdir}/* -mtime +${logdays}|wc -l`
find ${logdir}/* -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" >> ${logfile}
fi
}
fn_restartserver(){
echo -e "[\e[0;32m OK \e[0;39m] Restarting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${logfile}
fn_stopserver
sleep 1
fn_startserver
}
fn_startserver(){
fn_rootcheck
fn_syscheck
fn_runcheck
fn_logmanager
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${logfile}
cp ${logfile} ${logfiledate}
screen -d -m -S ${servicename} ${filesdir}/srcds_run ${parms}
sleep 1
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 0 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: Failed to start ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${logfile}
fi
}
fn_stopserver(){
fn_rootcheck
fn_syscheck
pid=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
if [ -z ${pid} ];then
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already stopped"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${logfile}
else
echo -e "[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${logfile}
kill `screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
screen -wipe > /dev/null 2>&1
fi
}
fn_debugserver(){
fn_rootcheck
fn_syscheck
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} in debug mode!"
sleep 0.5
echo -e ""
echo -e "Use for identifying server issues only!"
while true; do
echo "If server is already running it will be stopped"
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_stopserver
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Press CTRL+C to drop out of debug mode"
sleep 3
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
${filesdir}/srcds_run ${parms} -debug
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_logmanager
echo -e "[\e[0;32m OK \e[0;39m] Checking ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Checking ${servername}" >> ${logfile}
updatecheck=`ps -ef|grep "${selfname} update"|grep -v grep|wc -l`
if [ "${updatecheck}" = "0" ];then
fn_runcheck
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servername} had stopped"
actiontaken="restarted ${servername}"
fn_emailnotification
fi
fn_startserver
else
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${logfile}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${logfile}
fi
}
fn_updateserver(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${logfile}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
}
#
##Installer
#
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
if [ ! -f steam.sh ];then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steam.sh
else
echo "Steam already installed!"
fi
}
fn_retryinstall(){
while true; do
read -p "Retry install? [y/N]" yn
case $yn in
[Yy]* ) fn_install;;
[Nn]* ) echo Exiting; exit ;;
* ) echo "Please answer yes or no.";;
esac
done
}
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ];then
echo "${gamename} Server is already installed here:"
pwd
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
fi
fn_header
echo "Install Directory:"
pwd
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_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
mkdir -v ${rootdir}/log
mkdir -v ${logdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steam.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall ;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Configuring ${gamename} Server"
echo "================================="
read -p "Enter rcon password: " rconpass
read -p "Enter server name: " servername
sleep 1
echo ""
echo "Creating server.cfg"
touch ${servercfg}
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
echo -e ""
echo -e "// rcon passsword"
echo -e "rcon_password \"${rconpass}\""
echo -e ""
echo -e "// Server password"
echo -e "sv_password \"\""
echo -e ""
echo -e "// server logging"
echo -e "log on"
echo -e "sv_logbans 1"
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
sleep 1
echo ""
echo "Setting up logging"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${rootdir}/.steam
mkdir -v ${rootdir}/.steam/sdk32
cp -v ${filesdir}/bin/steamclient.so ${rootdir}/.steam/sdk32/steamclient.so
sleep 1
echo ""
echo "${gamename} Server Details"
echo "================================="
hostname=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
rcon=`grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g'`
echo "Server hostname: ${hostname}"
echo "Rcon password: ${rcon}"
echo "You can edit these in server.cfg:"
echo "${servercfg}"
echo ""
echo "Server IP: localhost:27015"
echo "You can change port by editing the"
echo "start parms in ${selfname}"
echo "================================="
echo "Install Complete!"
echo ""
echo "To start server type:"
echo "${selfname} start"
echo ""
}
case "$1" in
start)
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
update)
fn_stopserver
fn_updateserver
fn_startserver;;
monitor)
fn_monitorserver;;
install)
fn_install;;
debug)
fn_debugserver;;
email-test)
fn_emailtest;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|install|debug|email-test}"
exit 1;;
esac
exit

View File

@ -0,0 +1,476 @@
#!/bin/bash
# Half Life 2: Deathmatch
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 010813
#### Variables ####
# Notification Email
# (on|off)
emailnotification="off"
email="email@example.com"
# Start vars
defaultmap="dm_lockdown"
port="27015"
sourcetvport="27020"
clientport="27005"
parms="-game hl2mp +map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport}"
#### Advanced Variables ####
# Steam
appid="232370"
# Directorys
rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/hl2dm"
servercfg="${filesdir}/hl2mp/cfg/server.cfg"
# Server names
servicename="hl2dm-server"
gamename="Half Life 2: Deathmatch"
servername=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
# Logging
logdir="${rootdir}/log/script"
gamelogdir="${filesdir}/hl2mp/logs"
logfile="${logdir}/${servicename}.log"
logfiledate="${logdir}/${servicename}-$( date '+%d-%m-%Y-%H-%M-%S').log"
logdays="7"
##### Script #####
# 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_serverquery(){
# uses serverquery.py to directly query the server
# detects if the server locks up
if [ -f serverquery.py ];then
echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${logfile}
serverquery=`./serverquery.py 127.0.0.1 ${port} 2>&1`
sleep 1
if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${logfile}
sleep 1
fn_restartserver
else
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
fi
fi
}
fn_runcheck(){
# already running check
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 1 ];then
fn_serverquery
echo -e "[\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" >> ${logfile}
exit
# multiple of same instance check
elif [ ${pidwc} -ge 2 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: ${servername} is running ${pidwc} times"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is running ${pidwc} times" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] ${servicename}: Stopping ${pidwc} instances of ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${pidwc} instances of ${servername}" >> ${logfile}
fn_stopserver
exit
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_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "=========================================\nServer information\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 "=========================================\n${servicename} statistics\n=========================================\n"
echo -e "Service: ${servicename}"
echo -e "Server: ${servername}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "=========================================\n${servicename} log summary\n=========================================\n"
}|tee ${logdir}/${servicename}-email.log > /dev/null 2>&1
tail -50 ${logfile} >> /${logdir}/${servicename}-email.log
mail -s "${subject}" ${email} < /${logdir}/${servicename}-email.log
echo -e "[\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}" >> ${logfile}
}
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Emailing test notification"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification
else
echo -e "[\e[0;31m FAIL \e[0;39m] Email notificaion not enabled"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Email notificaion not enabled" >> ${logfile}
fi
}
fn_logmanager(){
# log manager will active if finds logs older than $logdays
if [ `find ${logdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then
echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${logfile}
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" >> ${logfile}
find ${logdir}/* -mtime +${logdays} |tee >> ${logfile}
count=`find ${logdir}/* -mtime +${logdays}|wc -l`
find ${logdir}/* -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" >> ${logfile}
fi
}
fn_restartserver(){
echo -e "[\e[0;32m OK \e[0;39m] Restarting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${logfile}
fn_stopserver
sleep 1
fn_startserver
}
fn_startserver(){
fn_rootcheck
fn_syscheck
fn_runcheck
fn_logmanager
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${logfile}
cp ${logfile} ${logfiledate}
screen -d -m -S ${servicename} ${filesdir}/srcds_run ${parms}
sleep 1
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 0 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: Failed to start ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${logfile}
fi
}
fn_stopserver(){
fn_rootcheck
fn_syscheck
pid=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
if [ -z ${pid} ];then
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already stopped"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${logfile}
else
echo -e "[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${logfile}
kill `screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
screen -wipe > /dev/null 2>&1
fi
}
fn_debugserver(){
fn_rootcheck
fn_syscheck
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} in debug mode!"
sleep 0.5
echo -e ""
echo -e "Use for identifying server issues only!"
while true; do
echo "If server is already running it will be stopped"
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_stopserver
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Press CTRL+C to drop out of debug mode"
sleep 3
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
${filesdir}/srcds_run ${parms} -debug
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_logmanager
echo -e "[\e[0;32m OK \e[0;39m] Checking ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Checking ${servername}" >> ${logfile}
updatecheck=`ps -ef|grep "${selfname} update"|grep -v grep|wc -l`
if [ "${updatecheck}" = "0" ];then
fn_runcheck
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servername} had stopped"
actiontaken="restarted ${servername}"
fn_emailnotification
fi
fn_startserver
else
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${logfile}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${logfile}
fi
}
fn_updateserver(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${logfile}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
}
#
##Installer
#
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
if [ ! -f steam.sh ];then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steam.sh
else
echo "Steam already installed!"
fi
}
fn_retryinstall(){
while true; do
read -p "Retry install? [y/N]" yn
case $yn in
[Yy]* ) fn_install;;
[Nn]* ) echo Exiting; exit ;;
* ) echo "Please answer yes or no.";;
esac
done
}
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ];then
echo "${gamename} Server is already installed here:"
pwd
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
fi
fn_header
echo "Install Directory:"
pwd
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_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
mkdir -v ${rootdir}/log
mkdir -v ${logdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steam.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall ;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Configuring ${gamename} Server"
echo "================================="
read -p "Enter rcon password: " rconpass
read -p "Enter server name: " servername
sleep 1
echo ""
echo "Creating server.cfg"
touch ${servercfg}
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
echo -e ""
echo -e "// rcon passsword"
echo -e "rcon_password \"${rconpass}\""
echo -e ""
echo -e "// Server password"
echo -e "sv_password \"\""
echo -e ""
echo -e "// server logging"
echo -e "log on"
echo -e "sv_logbans 1"
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
sleep 1
echo ""
echo "Setting up logging"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${rootdir}/.steam
mkdir -v ${rootdir}/.steam/sdk32
cp -v ${filesdir}/bin/steamclient.so ${rootdir}/.steam/sdk32/steamclient.so
sleep 1
echo ""
echo "${gamename} Server Details"
echo "================================="
hostname=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
rcon=`grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g'`
echo "Server hostname: ${hostname}"
echo "Rcon password: ${rcon}"
echo "You can edit these in server.cfg:"
echo "${servercfg}"
echo ""
echo "Server IP: localhost:27015"
echo "You can change port by editing the"
echo "start parms in ${selfname}"
echo "================================="
echo "Install Complete!"
echo ""
echo "To start server type:"
echo "${selfname} start"
echo ""
}
case "$1" in
start)
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
update)
fn_stopserver
fn_updateserver
fn_startserver;;
monitor)
fn_monitorserver;;
install)
fn_install;;
debug)
fn_debugserver;;
email-test)
fn_emailtest;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|install|debug|email-test}"
exit 1;;
esac
exit

539
KillingFloor/kfserver Normal file
View File

@ -0,0 +1,539 @@
#!/bin/bash
# Killing Floor
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 010813
#### Variables ####
# Steam login
steamuser="username"
steampass="password"
# Steam
appid="215360"
# Notification Email
# (on|off)
emailnotification="off"
email="email@example.com"
# Directorys
rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/killingfloor"
systemdir="${filesdir}/System"
compressedmapsdir="${rootdir}/Maps-Compressed"
# Server names
servicename="kf-server"
gamename="Killing Floor"
ini="${servicename}.ini"
servername=`grep -s ServerName= ${systemdir}/${ini} | sed 's/ServerName=//g'`
# Logging
logdir="${rootdir}/log"
logfile="${logdir}/${servicename}.log"
logfiledate="${logdir}/${servicename}-$( date '+%d-%m-%Y-%H-%M-%S').log"
logdays="7"
# Start vars
defaultmap="KF-BioticsLab.rom"
parms="server ${defaultmap}?game=KFmod.KFGameType -nohomedir ini=${ini} log=${logfile}"
##### Script #####
# 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 ${systemdir} ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
fn_serverquery(){
# uses serverquery.py to directly query the server
# detects if the server locks up
if [ -f serverquery.py ];then
echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${logfile}
serverquery=`./serverquery.py 127.0.0.1 ${port} 2>&1`
sleep 1
if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${logfile}
sleep 1
fn_restartserver
else
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
fi
fi
}
fn_runcheck(){
# already running check
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 1 ];then
fn_serverquery
echo -e "[\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" >> ${logfile}
exit
# multiple of same instance check
elif [ ${pidwc} -ge 2 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: ${servername} is running ${pidwc} times"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is running ${pidwc} times" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] ${servicename}: Stopping ${pidwc} instances of ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${pidwc} instances of ${servername}" >> ${logfile}
fn_stopserver
exit
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_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "=========================================\nServer information\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 "=========================================\n${servicename} statistics\n=========================================\n"
echo -e "Service: ${servicename}"
echo -e "Server: ${servername}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "=========================================\n${servicename} log summary\n=========================================\n"
}|tee ${logdir}/${servicename}-email.log > /dev/null 2>&1
tail -50 ${logfile} >> /${logdir}/${servicename}-email.log
mail -s "${subject}" ${email} < /${logdir}/${servicename}-email.log
echo -e "[\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}" >> ${logfile}
}
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Emailing test notification"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification
else
echo -e "[\e[0;31m FAIL \e[0;39m] Email notificaion not enabled"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Email notificaion not enabled" >> ${logfile}
fi
}
fn_logmanager(){
# log manager will active if finds logs older than $logdays
if [ `find ${logdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then
echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${logfile}
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" >> ${logfile}
find ${logdir}/* -mtime +${logdays} |tee >> ${logfile}
count=`find ${logdir}/* -mtime +${logdays}|wc -l`
find ${logdir}/* -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" >> ${logfile}
fi
}
fn_restartserver(){
echo -e "[\e[0;32m OK \e[0;39m] Restarting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${logfile}
fn_stopserver
sleep 1
fn_startserver
}
fn_startserver(){
fn_rootcheck
fn_syscheck
fn_runcheck
fn_logmanager
cd ${systemdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${logfile}
cp ${logfile} ${logfiledate}
screen -d -m -S ${servicename} ./ucc-bin ${parms}
sleep 1
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 0 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: Failed to start ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${logfile}
fi
}
fn_stopserver(){
fn_rootcheck
fn_syscheck
pid=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
if [ -z ${pid} ];then
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already stopped"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${logfile}
else
echo -e "[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${logfile}
kill `screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
screen -wipe > /dev/null 2>&1
fi
}
fn_debugserver(){
fn_rootcheck
fn_syscheck
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} in debug mode!"
sleep 0.5
echo -e ""
echo -e "Use for identifying server issues only!"
while true; do
echo "If server is already running it will be stopped"
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_stopserver
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Press CTRL+C to drop out of debug mode"
sleep 3
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
cd ${systemdir}
./ucc-bin ${parms}
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_logmanager
echo -e "[\e[0;32m OK \e[0;39m] Checking ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Checking ${servername}" >> ${logfile}
updatecheck=`ps -ef|grep "${selfname} update"|grep -v grep|wc -l`
if [ "${updatecheck}" = "0" ];then
fn_runcheck
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servername} had stopped"
actiontaken="restarted ${servername}"
fn_emailnotification
fi
fn_startserver
else
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${logfile}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${logfile}
fi
}
fn_updateserver(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${logfile}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
if [ $(grep Denied ${logfile}|wc -l) -ge 1 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: STEAMAUTH error detected!: Server update failed"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: STEAMAUTH error detected!: Server update failed" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
mail -s "${servername}: Steam Auth Failure" ${email}< ${logfile}
fi
fi
}
fn_compressmaps(){
fn_rootcheck
clear
echo "${gamename} Map Compressor"
echo "============================"
echo "Will compress all maps in:"
echo ""
pwd
echo ""
echo "Compressed maps saved to:"
echo ""
echo "$compressedmapsdir"
echo ""
while true; do
read -p "Start compression [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1 ;;
* ) echo "Please answer yes or no.";;
esac
done
mkdir $compressedmapsdir
rm -rfv ${filesdir}/Maps/*.uz2
cd ${systemdir}
./ucc-bin compress ../Maps/* --nohomedir
mv -fv ${filesdir}/Maps/*.uz2 $compressedmapsdir
}
fn_steamguard(){
fn_rootcheck
fn_syscheck
clear
fn_header
fn_steamdl
clear
fn_header
echo "If you are gettng an error:"
echo ""
echo "Login Failure: Account Logon Denied Failed."
echo ""
echo "You should now get an email from Steam with a Steam Guard code"
echo ""
read -p "Press [Enter] key to when you have the code..."
clear
fn_header
echo "Please enter Steam Guard Code"
echo "=============================="
echo -n "Code: "
read CODE
touch guard.txt
chmod 0600 guard.txt
echo "set_steam_guard_code $CODE" > guard.txt
echo "login ${steamuser} ${steampass}" >> guard.txt
echo "quit" >> guard.txt
STEAMEXE=steamcmd ./steam.sh +runscript guard.txt
rm guard.txt
cd ../
echo "=============================="
echo "Complete!"
cd ${rootdir}
}
#
##Installer
#
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
if [ ! -f steam.sh ];then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steam.sh
else
echo "Steam already installed!"
fi
}
fn_retryinstall(){
while true; do
read -p "Retry install? [y/N]" yn
case $yn in
[Yy]* ) fn_install;;
[Nn]* ) echo Exiting; exit ;;
* ) echo "Please answer yes or no.";;
esac
done
}
fn_install(){
fn_rootcheck
fn_header
if [ -d ${systemdir} ];then
echo "${gamename} Server is already installed here:"
pwd
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
fi
fn_header
echo "Install Directory:"
pwd
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_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
mkdir -v ${logdir}
touch install.txt
chmod 0600 install.txt
echo "login ${steamuser} ${steampass}" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steam.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall ;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Configuring ${gamename} Server"
echo "================================="
echo "Copying ${systemdir}/default.ini to ${systemdir}/${ini}"
cp ${systemdir}/Default.ini ${systemdir}/${ini}
sleep 1
echo ""
echo "Applying WebAdmin CharSet fix!"
echo "http://forums.tripwireinteractive.com/showpost.php?p=442340&postcount=1"
sleep 1
echo ""
echo "Applying WebAdmin ROOst.css fix!"
echo "http://forums.tripwireinteractive.com/showpost.php?p=585435&postcount=13"
sleep 1
echo ""
echo "Setting WebAdmin username and password"
sleep 1
echo ""
echo "Enabling Web Interface"
sleep 2
sed -i 's/CharSet="iso-8859-1"/CharSet="utf-8"/g' ${systemdir}/UWeb.int
sed -i 's/none}/none;/g' ${filesdir}/Web/ServerAdmin/ROOst.css
sed -i 's/underline}/underline;/g' ${filesdir}/Web/ServerAdmin/ROOst.css
sed -i 's/AdminName=/AdminName=admin/g' ${systemdir}/${ini}
sed -i 's/AdminPassword=/AdminPassword=kfpass/g' ${systemdir}/${ini}
sed -i 's/bEnabled=False/bEnabled=True/g' ${systemdir}/${ini}
mkdir ${logdir}
cd ${rootdir}
echo ""
echo "Default Settings"
echo "=============================="
echo "WebAdmin Details:"
echo "Url: http://localhost:8075"
echo "Username: admin"
echo "Password: kfpass"
echo ""
echo "Port Details:"
echo "8075 TCP (WebAdmin Port)"
echo "7707 UDP (Game Port)"
echo "7708 UDP (Query Port)"
echo "7717 UDP (GameSpy Query Port)"
echo "28852 TCP & UDP (Allows your Server to Connect to the Master Server Browser)"
echo "20560 UDP (Steam Port)"
echo "================================="
echo "Install Complete!"
echo ""
echo "To start server type:"
echo "${selfname} start"
echo ""
}
case "$1" in
start)
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
update)
fn_stopserver
fn_updateserver
fn_startserver;;
monitor)
fn_monitorserver;;
install)
fn_install;;
debug)
fn_debugserver;;
map-compressor)
fn_compressmaps;;
steam-auth)
fn_updateserver
fn_steamguard;;
email-test)
fn_emailtest;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|install|debug|map-compressor|steam-auth|email-test}"
exit 1;;
esac
exit

475
Left4Dead2/l4d2server Normal file
View File

@ -0,0 +1,475 @@
#!/bin/bash
# Left 4 Dead 2
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 010813
#### Variables ####
# Notification Email
# (on|off)
emailnotification="off"
email="email@example.com"
# Start vars
defaultmap="c5m1_waterfront"
port="27015"
parms="-strictportbind -game left4dead2 +port ${port} +map ${defaultmap}"
#### Advanced Variables ####
# Steam
appid="222860"
# Directorys
rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/l4d2"
servercfg="${filesdir}/left4dead2/cfg/server.cfg"
# Server names
servicename="l4d2-server"
gamename="Left 4 Dead 2"
servername=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
# Logging
logdir="${rootdir}/log/script"
gamelogdir="${filesdir}/left4dead2/logs"
logfile="${logdir}/${servicename}.log"
logfiledate="${logdir}/${servicename}-$( date '+%d-%m-%Y-%H-%M-%S').log"
logdays="7"
##### Script #####
# 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_serverquery(){
# uses serverquery.py to directly query the server
# detects if the server locks up
if [ -f serverquery.py ];then
echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${logfile}
serverquery=`./serverquery.py 127.0.0.1 ${port} 2>&1`
sleep 1
if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${logfile}
sleep 1
fn_restartserver
else
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
fi
fi
}
fn_runcheck(){
# already running check
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 1 ];then
fn_serverquery
echo -e "[\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" >> ${logfile}
exit
# multiple of same instance check
elif [ ${pidwc} -ge 2 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: ${servername} is running ${pidwc} times"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is running ${pidwc} times" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] ${servicename}: Stopping ${pidwc} instances of ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${pidwc} instances of ${servername}" >> ${logfile}
fn_stopserver
exit
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_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "=========================================\nServer information\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 "=========================================\n${servicename} statistics\n=========================================\n"
echo -e "Service: ${servicename}"
echo -e "Server: ${servername}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "=========================================\n${servicename} log summary\n=========================================\n"
}|tee ${logdir}/${servicename}-email.log > /dev/null 2>&1
tail -50 ${logfile} >> /${logdir}/${servicename}-email.log
mail -s "${subject}" ${email} < /${logdir}/${servicename}-email.log
echo -e "[\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}" >> ${logfile}
}
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Emailing test notification"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification
else
echo -e "[\e[0;31m FAIL \e[0;39m] Email notificaion not enabled"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Email notificaion not enabled" >> ${logfile}
fi
}
fn_logmanager(){
# log manager will active if finds logs older than $logdays
if [ `find ${logdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then
echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${logfile}
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" >> ${logfile}
find ${logdir}/* -mtime +${logdays} |tee >> ${logfile}
count=`find ${logdir}/* -mtime +${logdays}|wc -l`
find ${logdir}/* -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" >> ${logfile}
fi
}
fn_restartserver(){
echo -e "[\e[0;32m OK \e[0;39m] Restarting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${logfile}
fn_stopserver
sleep 1
fn_startserver
}
fn_startserver(){
fn_rootcheck
fn_syscheck
fn_runcheck
fn_logmanager
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${logfile}
cp ${logfile} ${logfiledate}
screen -d -m -S ${servicename} ${filesdir}/srcds_run ${parms}
sleep 1
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 0 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: Failed to start ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${logfile}
fi
}
fn_stopserver(){
fn_rootcheck
fn_syscheck
pid=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
if [ -z ${pid} ];then
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already stopped"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${logfile}
else
echo -e "[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${logfile}
kill `screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
screen -wipe > /dev/null 2>&1
fi
}
fn_debugserver(){
fn_rootcheck
fn_syscheck
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} in debug mode!"
sleep 0.5
echo -e ""
echo -e "Use for identifying server issues only!"
while true; do
echo "If server is already running it will be stopped"
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_stopserver
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Press CTRL+C to drop out of debug mode"
sleep 3
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
${filesdir}/srcds_run ${parms} -debug
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_logmanager
echo -e "[\e[0;32m OK \e[0;39m] Checking ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Checking ${servername}" >> ${logfile}
updatecheck=`ps -ef|grep "${selfname} update"|grep -v grep|wc -l`
if [ "${updatecheck}" = "0" ];then
fn_runcheck
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servername} had stopped"
actiontaken="restarted ${servername}"
fn_emailnotification
fi
fn_startserver
else
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${logfile}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${logfile}
fi
}
fn_updateserver(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${logfile}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
}
#
##Installer
#
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
if [ ! -f steam.sh ];then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steam.sh
else
echo "Steam already installed!"
fi
}
fn_retryinstall(){
while true; do
read -p "Retry install? [y/N]" yn
case $yn in
[Yy]* ) fn_install;;
[Nn]* ) echo Exiting; exit ;;
* ) echo "Please answer yes or no.";;
esac
done
}
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ];then
echo "${gamename} Server is already installed here:"
pwd
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
fi
fn_header
echo "Install Directory:"
pwd
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_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
mkdir -v ${rootdir}/log
mkdir -v ${logdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steam.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall ;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Configuring ${gamename} Server"
echo "================================="
read -p "Enter rcon password: " rconpass
read -p "Enter server name: " servername
sleep 1
echo ""
echo "Creating server.cfg"
touch ${servercfg}
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
echo -e ""
echo -e "// rcon passsword"
echo -e "rcon_password \"${rconpass}\""
echo -e ""
echo -e "// Server password"
echo -e "sv_password \"\""
echo -e ""
echo -e "// server logging"
echo -e "log on"
echo -e "sv_logbans 1"
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
sleep 1
echo ""
echo "Setting up logging"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${rootdir}/.steam
mkdir -v ${rootdir}/.steam/sdk32
cp -v ${filesdir}/bin/steamclient.so ${rootdir}/.steam/sdk32/steamclient.so
sleep 1
echo ""
echo "${gamename} Server Details"
echo "================================="
hostname=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
rcon=`grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g'`
echo "Server hostname: ${hostname}"
echo "Rcon password: ${rcon}"
echo "You can edit these in server.cfg:"
echo "${servercfg}"
echo ""
echo "Server IP: localhost:27015"
echo "You can change port by editing the"
echo "start parms in ${selfname}"
echo "================================="
echo "Install Complete!"
echo ""
echo "To start server type:"
echo "${selfname} start"
echo ""
}
case "$1" in
start)
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
update)
fn_stopserver
fn_updateserver
fn_startserver;;
monitor)
fn_monitorserver;;
install)
fn_install;;
debug)
fn_debugserver;;
email-test)
fn_emailtest;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|install|debug|email-test}"
exit 1;;
esac
exit

View File

@ -0,0 +1,35 @@
#!/usr/bin/python
# serverquery.py part of
# Server Management Script
#
# Website: http://danielgibbs.co.uk
# Version: 010813
import errno
import sys
import socket
import re
if __name__ == "__main__":
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(0.5)
ip = sys.argv[1]
port = sys.argv[2]
try:
sock.connect((ip, int(port)))
except socket.error:
sys.exit("ERROR 1")
sock.send("\xFF\xFF\xFF\xFFTSource Engine Query\0")
data = ""
try:
data = sock.recv(1024)
except socket.error:
sys.exit("ERROR 2")
sock.close()
if(len(data) > 10):
sys.exit("OK")
sys.exit("ERROR 3")

476
TeamFortress2/tf2server Normal file
View File

@ -0,0 +1,476 @@
#!/bin/bash
# Team Fortress 2
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 010813
#### Variables ####
# Notification Email
# (on|off)
emailnotification="off"
email="email@example.com"
# Start vars
defaultmap="ctf_2fort"
port="27015"
sourcetvport="27020"
clientport="27005"
parms="-game tf +map ${defaultmap} -strictportbind -port ${port} +tv_port ${sourcetvport} +clientport ${clientport}"
#### Advanced Variables ####
# Steam
appid="232250"
# Directorys
rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/tf2"
servercfg="${filesdir}/tf/cfg/server.cfg"
# Server names
servicename="tf2-server"
gamename="Team Fortress 2"
servername=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
# Logging
logdir="${rootdir}/log/script"
gamelogdir="${filesdir}/tf/logs"
logfile="${logdir}/${servicename}.log"
logfiledate="${logdir}/${servicename}-$( date '+%d-%m-%Y-%H-%M-%S').log"
logdays="7"
##### Script #####
# 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_serverquery(){
# uses serverquery.py to directly query the server
# detects if the server locks up
if [ -f serverquery.py ];then
echo -e "[\e[0;36m INFO \e[0;39m] serverquery.py detected"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: serverquery.py detected" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: QUERYING"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: QUERYING" >> ${logfile}
serverquery=`./serverquery.py 127.0.0.1 ${port} 2>&1`
sleep 1
if [ "${serverquery}" = "ERROR 1" ]||[ "${serverquery}" = "ERROR 2" ]||[ "${serverquery}" = "ERROR 3" ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} has locked up!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} has locked up!" >> ${logfile}
sleep 1
fn_restartserver
else
echo -e "[\e[0;32m OK \e[0;39m] Querying ${servicename}: ${servername}: ${serverquery}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Querying ${servername}: ${serverquery}" >> ${logfile}
sleep 1
fi
fi
}
fn_runcheck(){
# already running check
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 1 ];then
fn_serverquery
echo -e "[\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" >> ${logfile}
exit
# multiple of same instance check
elif [ ${pidwc} -ge 2 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: ${servername} is running ${pidwc} times"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is running ${pidwc} times" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] ${servicename}: Stopping ${pidwc} instances of ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${pidwc} instances of ${servername}" >> ${logfile}
fn_stopserver
exit
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_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "=========================================\nServer information\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 "=========================================\n${servicename} statistics\n=========================================\n"
echo -e "Service: ${servicename}"
echo -e "Server: ${servername}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "=========================================\n${servicename} log summary\n=========================================\n"
}|tee ${logdir}/${servicename}-email.log > /dev/null 2>&1
tail -50 ${logfile} >> /${logdir}/${servicename}-email.log
mail -s "${subject}" ${email} < /${logdir}/${servicename}-email.log
echo -e "[\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}" >> ${logfile}
}
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Emailing test notification"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification
else
echo -e "[\e[0;31m FAIL \e[0;39m] Email notificaion not enabled"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Email notificaion not enabled" >> ${logfile}
fi
}
fn_logmanager(){
# log manager will active if finds logs older than $logdays
if [ `find ${logdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then
echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${logfile}
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" >> ${logfile}
find ${logdir}/* -mtime +${logdays} |tee >> ${logfile}
count=`find ${logdir}/* -mtime +${logdays}|wc -l`
find ${logdir}/* -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" >> ${logfile}
fi
}
fn_restartserver(){
echo -e "[\e[0;32m OK \e[0;39m] Restarting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${logfile}
fn_stopserver
sleep 1
fn_startserver
}
fn_startserver(){
fn_rootcheck
fn_syscheck
fn_runcheck
fn_logmanager
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${logfile}
cp ${logfile} ${logfiledate}
screen -d -m -S ${servicename} ${filesdir}/srcds_run ${parms}
sleep 1
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 0 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: Failed to start ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${logfile}
fi
}
fn_stopserver(){
fn_rootcheck
fn_syscheck
pid=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
if [ -z ${pid} ];then
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already stopped"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${logfile}
else
echo -e "[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${logfile}
kill `screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
screen -wipe > /dev/null 2>&1
fi
}
fn_debugserver(){
fn_rootcheck
fn_syscheck
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} in debug mode!"
sleep 0.5
echo -e ""
echo -e "Use for identifying server issues only!"
while true; do
echo "If server is already running it will be stopped"
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_stopserver
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Press CTRL+C to drop out of debug mode"
sleep 3
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
${filesdir}/srcds_run ${parms} -debug
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_logmanager
echo -e "[\e[0;32m OK \e[0;39m] Checking ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Checking ${servername}" >> ${logfile}
updatecheck=`ps -ef|grep "${selfname} update"|grep -v grep|wc -l`
if [ "${updatecheck}" = "0" ];then
fn_runcheck
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servername} had stopped"
actiontaken="restarted ${servername}"
fn_emailnotification
fi
fn_startserver
else
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${logfile}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${logfile}
fi
}
fn_updateserver(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${logfile}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
}
#
##Installer
#
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
if [ ! -f steam.sh ];then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steam.sh
else
echo "Steam already installed!"
fi
}
fn_retryinstall(){
while true; do
read -p "Retry install? [y/N]" yn
case $yn in
[Yy]* ) fn_install;;
[Nn]* ) echo Exiting; exit ;;
* ) echo "Please answer yes or no.";;
esac
done
}
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ];then
echo "${gamename} Server is already installed here:"
pwd
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
fi
fn_header
echo "Install Directory:"
pwd
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_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
mkdir -v ${rootdir}/log
mkdir -v ${logdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steam.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall ;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Configuring ${gamename} Server"
echo "================================="
read -p "Enter rcon password: " rconpass
read -p "Enter server name: " servername
sleep 1
echo ""
echo "Creating server.cfg"
touch ${servercfg}
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
echo -e ""
echo -e "// rcon passsword"
echo -e "rcon_password \"${rconpass}\""
echo -e ""
echo -e "// Server password"
echo -e "sv_password \"\""
echo -e ""
echo -e "// server logging"
echo -e "log on"
echo -e "sv_logbans 1"
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
sleep 1
echo ""
echo "Setting up logging"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${rootdir}/.steam
mkdir -v ${rootdir}/.steam/sdk32
cp -v ${filesdir}/bin/steamclient.so ${rootdir}/.steam/sdk32/steamclient.so
sleep 1
echo ""
echo "${gamename} Server Details"
echo "================================="
hostname=`grep -s hostname ${servercfg} | sed 's/hostname //g'|sed 's/"//g'`
rcon=`grep -s rcon_password ${servercfg} | sed 's/rcon_password //g'|sed 's/"//g'`
echo "Server hostname: ${hostname}"
echo "Rcon password: ${rcon}"
echo "You can edit these in server.cfg:"
echo "${servercfg}"
echo ""
echo "Server IP: localhost:27015"
echo "You can change port by editing the"
echo "start parms in ${selfname}"
echo "================================="
echo "Install Complete!"
echo ""
echo "To start server type:"
echo "${selfname} start"
echo ""
}
case "$1" in
start)
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
update)
fn_stopserver
fn_updateserver
fn_startserver;;
monitor)
fn_monitorserver;;
install)
fn_install;;
debug)
fn_debugserver;;
email-test)
fn_emailtest;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|install|debug|email-test}"
exit 1;;
esac
exit

250
TeamSpeak3/ts3server Normal file
View File

@ -0,0 +1,250 @@
#!/bin/bash
# Teamspeak 3
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 010813
#### Variables ####
# Notification Email
# (on|off)
emailnotification="off"
email="email@example.com"
# Server names
servername="Teamspeak 3 Server"
servicename="ts3-server"
# Directorys
rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
filesdir="${rootdir}/ts3"
ini="${servicename}.ini"
# Logging
logdir="${rootdir}/${servicename}-log"
logfile="${logdir}/${servicename}.log"
logfiledate="${logdir}/${servicename}-$( date '+%d-%m-%Y-%H-%M-%S').log"
logdays="7"
##### Script #####
# 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 -e "[\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" >> ${logfile}
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" >> ${logfile}
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}" >> ${logfile}
echo -e "* ${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_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "=========================================\nServer information\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 "=========================================\n${servicename} statistics\n=========================================\n"
echo -e "Service: ${servicename}"
echo -e "Server: ${servername}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "=========================================\n${servicename} log summary\n=========================================\n"
}|tee ${logdir}/${servicename}-email.log > /dev/null 2>&1
tail -50 ${logfile} >> /${logdir}/${servicename}-email.log
mail -s "${subject}" ${email} < /${logdir}/${servicename}-email.log
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Sent email notification to ${email}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} sent email notification to ${email}" >> ${logfile}
}
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] ${servicename}: Email test notification: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} email test notification" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} email test notification - testing ${servername}"
failurereason="Testing ${servicename} email notification"
actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification
else
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: email notificaion not enabled"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} email notificaion not enabled" >> ${logfile}
fi
}
fn_logmanager(){
#Log manager will active if finds logs older than $logdays
if [ `find ${logdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then
echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${logfile}
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" >> ${logfile}
find ${logdir}/* -mtime +${logdays} |tee >> ${logfile}
count=`find ${logdir}/* -mtime +${logdays}|wc -l`
find ${logdir}/* -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" >> ${logfile}
fi
}
fn_restartserver(){
echo -e "[\e[0;32m OK \e[0;39m] Restarting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${logfile}
fn_stopserver
sleep 1
fn_startserver
}
fn_startserver(){
if [ ! -d ${logdir} ];then
mkdir ${logdir}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} Creating log directory ${logdir}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} Creating log directory ${logdir}" >> ${logfile}
fi
fn_rootcheck
fn_syscheck
fn_runcheck
fn_inicheck
fn_logmanager
if [ -f ${logdir} ];then
cp ${logfile} ${logfiledate}
fi
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${logfile}
${filesdir}/ts3server_startscript.sh start inifile=${ini}
sleep 3
fn_status
if [ "$ts3status" = "Server seems to have died" ] || [ "$ts3status" = "No server running (ts3server.pid is missing)" ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: ${servername} Server is unable to start"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} Server is unable to start" >> ${logfile}
echo -e "Check ${filesdir}/logs for failure reason" |tee ${logfile}
fi
}
fn_stopserver(){
fn_rootcheck
fn_syscheck
fn_status
if [ "$ts3status" = "No server running (ts3server.pid is missing)" ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: ${servername} has already stopped"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} has already stopped" >> ${logfile}
else
echo -e "[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${logfile}
${filesdir}/ts3server_startscript.sh stop inifile=${ini}
fi
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_logmanager
echo -e "[\e[0;32m OK \e[0;39m] Checking ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Checking ${servername}" >> ${logfile}
fn_runcheck
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${logfile}
ts3status=`${filesdir}/ts3server_startscript.sh status inifile=${ini}`
if [ "$ts3status" = "Server seems to have died" ];then
echo -e "[\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" >> ${logfile}
failurereason="Server seems to have died"
elif [ "$ts3status" = "No server running (ts3server.pid is missing)" ];then
echo -e "[\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)" >> ${logfile}
failurereason="No server running (ts3server.pid is missing)"
else
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} Unknown error"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} Unknown error" >> ${logfile}
failurereason="Unknown error"
fi
fn_restartserver
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Monitor - Restarting ${servername}"
actiontaken="restarted ${servername}"
fn_emailnotification
fi
}
fn_status(){
ts3status=`${filesdir}/ts3server_startscript.sh status inifile=${ini}`
}
case "$1" in
start)
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
monitor)
fn_monitorserver;;
email-test)
fn_emailtest;;
*)
echo "Usage: $0 {start|stop|restart|monitor|email-test}"
exit 1;;
esac
exit

View File

@ -0,0 +1,464 @@
#!/bin/bash
# Unreal Tournament 2004
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 110813
#### Variables ####
# Notification Email
# (on|off)
emailnotification="off"
email="email@example.com"
# Directorys
rootdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/ut2k4"
systemdir="${filesdir}/System"
compressedmapsdir="${rootdir}/Maps-Compressed"
# Server names
servicename="ut2k4-server"
gamename="Unreal Tournament 2004"
ini="${servicename}.ini"
servername=`grep -s ServerName= ${systemdir}/${ini} | sed 's/ServerName=//g'`
# Logging
logdir="${rootdir}/log"
logfile="${logdir}/${servicename}.log"
logfiledate="${logdir}/${servicename}-$( date '+%d-%m-%Y-%H-%M-%S').log"
logdays="7"
# Start vars
defaultmap="DM-Rankin"
parms="server ${defaultmap}?game=XGame.xDMGame -nohomedir ini=${ini} log=${logfile}"
##### Script #####
# 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(){
# already running check
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 1 ];then
echo -e "[\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" >> ${logfile}
exit
# multiple of same instance check
elif [ ${pidwc} -ge 2 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: ${servername} is running ${pidwc} times"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is running ${pidwc} times" >> ${logfile}
echo -e "[\e[0;32m OK \e[0;39m] ${servicename}: Stopping ${pidwc} instances of ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${pidwc} instances of ${servername}" >> ${logfile}
fn_stopserver
exit
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_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "=========================================\nServer information\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 "=========================================\n${servicename} statistics\n=========================================\n"
echo -e "Service: ${servicename}"
echo -e "Server: ${servername}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "=========================================\n${servicename} log summary\n=========================================\n"
}|tee ${logdir}/${servicename}-email.log > /dev/null 2>&1
tail -50 ${logfile} >> /${logdir}/${servicename}-email.log
mail -s "${subject}" ${email} < /${logdir}/${servicename}-email.log
echo -e "[\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}" >> ${logfile}
}
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "[\e[0;32m OK \e[0;39m] Emailing test notification"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
actiontaken="Sent test email...hello is this thing on?"
fn_emailnotification
else
echo -e "[\e[0;31m FAIL \e[0;39m] Email notificaion not enabled"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Email notificaion not enabled" >> ${logfile}
fi
}
fn_logmanager(){
# log manager will active if finds logs older than $logdays
if [ `find ${logdir}/* -mtime +${logdays} |wc -l` -ne "0" ];then
echo -e "[\e[0;32m OK \e[0;39m] Starting log cleaner"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${logfile}
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" >> ${logfile}
find ${logdir}/* -mtime +${logdays} |tee >> ${logfile}
count=`find ${logdir}/* -mtime +${logdays}|wc -l`
find ${logdir}/* -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" >> ${logfile}
fi
}
fn_restartserver(){
echo -e "[\e[0;32m OK \e[0;39m] Restarting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${logfile}
fn_stopserver
sleep 1
fn_startserver
}
fn_startserver(){
fn_rootcheck
fn_syscheck
fn_runcheck
fn_logmanager
cd ${systemdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${logfile}
cp ${logfile} ${logfiledate}
screen -d -m -S ${servicename} ./ucc-bin ${parms}
sleep 1
pidwc=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'|wc -l`
if [ ${pidwc} -eq 0 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: Failed to start ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${logfile}
fi
}
fn_stopserver(){
fn_rootcheck
fn_syscheck
pid=`screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
if [ -z ${pid} ];then
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} is already stopped"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${logfile}
else
echo -e "[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${logfile}
kill `screen -ls |grep ${servicename} |awk -F . '{print $1}'|awk '{print $1}'`
screen -wipe > /dev/null 2>&1
fi
}
fn_debugserver(){
fn_rootcheck
fn_syscheck
cd ${filesdir}
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername} in debug mode!"
sleep 0.5
echo -e ""
echo -e "Use for identifying server issues only!"
while true; do
echo "If server is already running it will be stopped"
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_stopserver
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Press CTRL+C to drop out of debug mode"
sleep 3
echo -e "[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
cd ${systemdir}
./ucc-bin ${parms}
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_logmanager
echo -e "[\e[0;32m OK \e[0;39m] Checking ${servicename}: ${servername}"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Checking ${servername}" >> ${logfile}
updatecheck=`ps -ef|grep "${selfname} update"|grep -v grep|wc -l`
if [ "${updatecheck}" = "0" ];then
fn_runcheck
echo -e "[\e[1;33m WARN \e[0;39m] ${servicename}: Monitor detected ${servername} had stopped!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} had stopped!" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servername} had stopped"
actiontaken="restarted ${servername}"
fn_emailnotification
fi
fn_startserver
else
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: Monitor detected ${servername} is currently checking for updates!"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: Monitor detected ${servername} is currently checking for updates!" >> ${logfile}
echo -e "[\e[0;36m INFO \e[0;39m] ${servicename}: ${servername} will start when updating is complete"
echo -e "$( date '+%b %d %H:%M:%S') ${servicename}: ${servername} will start when updating is complete" >> ${logfile}
fi
}
fn_compressmaps(){
fn_rootcheck
clear
echo "${gamename} Map Compressor"
echo "============================"
echo "Will compress all maps in:"
echo ""
pwd
echo ""
echo "Compressed maps saved to:"
echo ""
echo "$compressedmapsdir"
echo ""
while true; do
read -p "Start compression [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1 ;;
* ) echo "Please answer yes or no.";;
esac
done
mkdir $compressedmapsdir
rm -rfv ${filesdir}/Maps/*.uz2
cd ${systemdir}
./ucc-bin compress ../Maps/* --nohomedir
mv -fv ${filesdir}/Maps/*.uz2 $compressedmapsdir
}
#
##Installer
#
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_filesdl(){
echo ""
echo "Downloading Server Files"
echo "============================"
cd ${rootdir}
mkdir ${filesdir}
cd ${filesdir}
if [ ! -f dedicatedserver3339-bonuspack.zip ];then
wget http://downloads.unrealadmin.org/UT2004/Server/dedicatedserver3339-bonuspack.zip
else
echo "dedicatedserver3339-bonuspack.zip already downloaded!"
fi
echo "Running MD5 checksum to verify the file"
sleep 1
echo "MD5 checksum: d3f28c5245c4c02802d48e4f0ffd3e34"
md5check=`md5sum dedicatedserver3339-bonuspack.zip| awk '{print $1;}'`
echo "File returned: ${md5check}"
if [ "${md5check}" != "d3f28c5245c4c02802d48e4f0ffd3e34" ];then
echo "MD5 checksum: FAILED!"
read -p "Retry download? [y/N]" yn
case $yn in
[Yy]* ) rm -f dedicatedserver3339-bonuspack.zip; fn_filesdl;;
[Nn]* ) echo Exiting; exit ;;
* ) echo "Please answer yes or no.";;
esac
else
echo "MD5 checksum: PASSED"
fi
}
fn_retryinstall(){
while true; do
read -p "Retry install? [y/N]" yn
case $yn in
[Yy]* ) fn_install;;
[Nn]* ) echo Exiting; exit ;;
* ) echo "Please answer yes or no.";;
esac
done
}
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ];then
echo "${gamename} Server is already installed here:"
pwd
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
fi
fn_header
echo "Install Directory:"
pwd
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_header
fn_filesdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${filesdir}
unzip dedicatedserver3339-bonuspack.zip
cd ${systemdir}
chmod +x ucc-bin
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall ;;
* ) echo "Please answer yes or no.";;
esac
done
cd ${filesdir}
while true; do
read -p "Remove dedicatedserver3339-bonuspack.zip? [y/N]" yn
case $yn in
[Yy]* ) rm -iv dedicatedserver3339-bonuspack.zip ; break ;;
[Nn]* ) break ;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Configuring ${gamename} Server"
echo "================================="
echo "Copying ${systemdir}/ut2004.ini to ${systemdir}/${ini}"
cp ${systemdir}/UT2004.ini ${systemdir}/${ini}
sleep 1
echo ""
echo "Applying WebAdmin CharSet fix!"
echo "http://forums.tripwireinteractive.com/showpost.php?p=442340&postcount=1"
sleep 1
echo ""
echo "Applying WebAdmin ut2003.css fix!"
echo "http://forums.tripwireinteractive.com/showpost.php?p=585435&postcount=13"
sleep 1
echo ""
echo "Setting WebAdmin port to 8077"
sleep 1
echo ""
echo "Setting WebAdmin username and password"
sleep 1
echo ""
echo "Enabling Web Interface"
sleep 2
sed -i 's/CharSet="iso-8859-1"/CharSet="utf-8"/g' ${systemdir}/UWeb.int
sed -i 's/none}/none;/g' ${filesdir}/Web/ServerAdmin/ut2003.css
sed -i 's/underline}/underline;/g' ${filesdir}/Web/ServerAdmin/ut2003.css
sed -i 's/AdminName=/AdminName=admin/g' ${systemdir}/${ini}
sed -i 's/AdminPassword=/AdminPassword=utpass/g' ${systemdir}/${ini}
sed -i 's/bEnabled=False/bEnabled=True/g' ${systemdir}/${ini}
sed -i 's/ListenPort=80/ListenPort=8077/g' ${systemdir}/${ini}
mkdir ${logdir}
cd ${rootdir}
echo ""
echo "Default Settings"
echo "=============================="
echo "WebAdmin Details:"
echo "Url: http://localhost:8077"
echo "Username: admin"
echo "Password: utpass"
echo ""
echo "Port Details:"
echo "8077 TCP (WebAdmin Port)"
echo "7777 UDP (Game Port)"
echo "7778 UDP (Query Port)"
echo "7787 UDP (GameSpy Query Port)"
echo "28902 TCP & UDP (Allows your Server to Connect to the Master Server Browser)"
echo "20560 UDP (Steam Port)"
echo "================================="
echo "Install Complete!"
echo ""
echo "To start server type:"
echo "${selfname} start"
}
case "$1" in
start)
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
monitor)
fn_monitorserver;;
install)
fn_install;;
debug)
fn_debugserver;;
map-compressor)
fn_compressmaps;;
email-test)
fn_emailtest;;
*)
echo "Usage: $0 {start|stop|restart|monitor|install|debug|map-compressor|email-test}"
exit 1;;
esac
exit