After getting frustrated on how much work it took to recompile my Linux server, I decided to automate it. Now that I’ve tested it, I’ll contribute to the community.
BIG UPDATE 02-07-11: I’ve updated this script to be a ton more flexible. No more are their 2 scripts to choose from, you only have one. And the directory layout is much more flexible, you don’t have to rewrite all the directory listings because you don’t want all of trinity inside your home directory. Check out the updated script below!
Notes:
[ul][li]This script only works on Linux (sorry Windows users)[/li][li]These scripts were only tested in Ubuntu Server 10.10. your results may be different on other distributions[/li][li]I’m not responsible if this server breaks your server or trinity server. This disclaimer isn’t meant to scare you, its just so that you don’t blame me. I use this script all the time on my server. [/li][/ul]
This script assumes the following directory structure in the directory the script resides in:[ul][li]repo - The git repository of trinity. Needs to already exist![/li][li]build - CMake generated directory that contains all the make files[/li][li]server - Where the actual server lives[/li][li]server-backup - A backup directory of server. If something goes horribly wrong and you loose everything you can just restore the backup. [/li][/ul]
Configuration:
[ul][li]USE_BYOBU - I manage TrinityCore inside of a persistent byobu session. If all you know is screen and want to use that instead just replace byobu with screen at the bottom, the switches should be identical. If you have absoluetly no idea what I’m talking about and don’t want to learn how screen or byobu is the best thing you can possibly have with a remote Linux server, just set it to false.[/li][li]KILL_BY_NAME - By default this script will try to kill any process with the names “authserver” and “worldserver”. So if you happen to be running anything else with that process name (eg CactusEMU), it will get killed as well. If your sure you aren’t in this situation, continue on. If not, you need to set the value to false, then MAKE SURE you have enabled PID in your conf files.[/li][li]KILL_PROCS - This is a space separated list of other programs that need to be killed before building. So for example if you have my awesome auto-restarter and don’t put its name in this list, you’ll break this script. [/li][/ul]
First, a simple version that doesn’t rely on byobu/screen.
#!/bin/bash
#By TheLQ, version 1.1
############CHANGE SETTINGS AS NESSESARY#################
#Should server be autostarted inside of a byobu/screen session?
USE_BYOBU=true
#Kill processes by name (true) or by PID file (false). NOTE: Kill by PID file requires enabling in conf!
KILL_BY_NAME=true
#Other processes to kill (eg script wrappers, autorestarters, etc)
KILL_PROCS=()
###########DO NOT MODIFY BELOW THIS LINE#################
ROOT=`pwd`
echo "Update Trin-Repo to newest version"
cd repo
git pull origin
echo "Kill the servers"
for i in "${KILL_PROCS[@]}"; do kill $i; done;
if [[ KILL_BY_NAME -eq true ]]; then
killall authserver
killall worldserver
else
cd $ROOT/server
if [ -f worldd.pid ]; then kill `cat worldd.pid`; done;
if [ -f authserver.pid ]; then kill `cat authserver.pid`; done;
if [ -f bin/worldd.pid ]; then kill `cat bin/worldd.pid`; done;
if [ -f bin/authserver.pid ]; then kill `cat bin/authserver.pid`; done;
fi;
echo "Delete the build dir"
cd $ROOT
rm -rf build
echo "Backup server (just in case)"
rm -rf server-backup
cp -R server server-backup
echo "Build!"
mkdir build
cd build
cmake $ROOT/repo -DSERVER=1 -DSCRIPTS=1 -DWITH_SQL=1 -DPREFIX=$ROOT/server
make
make install
echo "Done"
echo "Build completed on `date`"
if [[ USE_BYOBU -eq true ]]; then
echo "Re-initializing server"
byobu -p trinauth -X stuff "cd $ROOT $(echo -ne '\r')"
byobu -p trinauth -X stuff "bin/authserver $(echo -ne '\r')"
echo "Sleeping 5 seconds..."
sleep 5
byobu -p trinworld -X stuff "cd $ROOT $(echo -ne '\r')"
byobu -p trinworld -X stuff "bin/worldserver $(echo -ne '\r')"
fi;
echo "Build Complete!"
Hope you enjoy it! Please report any bugs and press the Thanks button while your at it.