TrinityCore restarter

Some of you keep asking for a restarter when the core or realm crash with GDB trace.

For this to work, you’ll have to install screen

aptitude install screen

and GDB: http://www.trinityco…to:Advanced:GDB

Well… i’ll post here my couple of files

restarter:


#!/bin/bash

screen -A -m -d -S restarter ./restarter-bin

restarter-bin:


#!/bin/bash


######################

GDB_ENABLED=1

GDB="trinity.gdb"

WORLDSERVER="world.pid" ### Put here the pid you configured on your worldserver.conf file ###

AUTHSERVER="auth.pid"   ### Put here the pid you configured on your authserver.conf file ###


### If you want to have more realms runing, just uncoment or copy this line ###

# EXTRAWORLDSERVER="world.pid" ### Put here the pid you configured on your worldserver.conf file ###



WORLD_CONFIG="../etc/worldserver.conf"

REALM_CONFIG="../etc/authserver.conf"


### If you want to have more realms runing, just uncoment or copy this line ###

# EXTRAWORLD_CONFIG="../etc/extraworldserver.conf"


WORLD_SCREEN_NAME="world"

REALM_SCREEN_NAME="realm"


### If you want to have more realms runing, just uncoment or copy this line ###

# EXTRAWORLD_SCREEN_NAME="world"



TRACE_BEGIN_STRING="SIGSEGV"

TRACE_FILE="trace.log"

ERR_FILE="error.log"

SYSLOG="system.log"

SYSERR="system.err"

LINKS_FILE="crash_links.link"

######################


function checkStatus() {

	if [ -d "/proc/"$1 ]; then

		eval "TEST=1"

	else

		eval "TEST=0"

	fi

}


while :

do

	PID=$(cat $WORLDSERVER)

	checkStatus $PID

	if [ $TEST -eq 0 ]; then

		DATE=$(date)

		echo "Restarting Trinity Core blizz($DATE)"

		if [ $GDB_ENABLED -eq 1 ]; then

			grep -B 10 -A 1800 "$TRACE_BEGIN_STRING" "$SYSLOG" >> "$TRACE_FILE"

            echo "------------------`date+%Y-%m-%d-%H-%M-%S`------------------" >> "$TRACE_FILE"

			cat "$TRACE_FILE" | ./paster | grep "http" >> "$LINKS_FILE"

			cat "$SYSERR" > "$ERR_FILE"

			screen -A -m -d -S $WORLD_SCREEN_NAME ./start worldserver $GDB "$WORLD_CONFIG" "$SYSLOG" "$SYSERR" 1

		fi


		if [ $GDB_ENABLED -eq 0 ]; then

			screen -A -m -d -S $WORLD_SCREEN_NAME ./start worldserver null "$WORLD_CONFIG" null null 0

		fi

	fi


### If you want to have more realms runing, just uncoment or copy those lines ###

#	PID=$(cat $EXTRAWORLDSERVER)

#	checkStatus $PID

#	if [ $TEST -eq 0 ]; then

#		DATE=$(date)

#		echo "Restarting Trinity Core blizz($DATE)"

#		if [ $GDB_ENABLED -eq 1 ]; then

#			grep -B 10 -A 1800 "$TRACE_BEGIN_STRING" "$SYSLOG" > "$TRACE_FILE"

#			cat "$TRACE_FILE" | ./paster | grep "http" >> "$LINKS_FILE"

#			cat "$SYSERR" > "$ERR_FILE"

#			screen -A -m -d -S $EXTRAWORLD_SCREEN_NAME ./start worldserver $GDB "$EXTRAWORLD_CONFIG" "$SYSLOG" "$SYSERR" 1

#		fi

#		

#		if [ $GDB_ENABLED -eq 0 ]; then

#			screen -A -m -d -S $EXTRAWORLD_SCREEN_NAME ./start worldserver null "$EXTRAWORLD_CONFIG" null null 0

#		fi

#	fi


	PID=$(cat "$AUTHSERVER")

	checkStatus $PID

	if [ $TEST -eq 0 ]; then

		DATE=$(date)

		echo "Restarting Trinity Realm ($DATE)"

		screen -A -m -d -S $REALM_SCREEN_NAME ./start authserver null "$REALM_CONFIG"

	fi

	sleep 45

done

start


#!/bin/bash


#GDB_FILE=$2

#CONFIG=$3

#SYSLOG=$4

#SYSERR=$5

#GBD_ENABLED=$6


case $1 in

	worldserver)

		if [ $6 -eq 1 ]; then

			echo "run -c $3" > $2

			echo "bt" >> $2

			echo "bt full" >> $2

			echo "info thread" >> $2

			echo "thread apply all backtrace full" >> $2


			gdb ./worldserver -x $2 --batch >$4 2>$5

		fi


		if [ $6 -eq 0 ]; then

			./worldserver -c $3

		fi

	;;


	authserver)

		./authserver -c $3

	;;

esac

After that, configure the restarter-bin file.

Note: If you want to have more realms runing, just uncoment or copy the EXTRAWORLD parts and rename EXTRAWORLD to what variable you want.

chmod +x all those files, put them on the same folder as your worldserver and authserver and run ./restarter

Note before you run the restarter, you have to run one time the worldserver and authserver to create the pid file for each.

The restarter will search for those pid files to detect any crashes.

Hope it helps.

Cheers

This is just what i needed! just for M$shit box ^^

I dont have a M$hit box to correctly write one script for it and test… but if you use search, you will find some similar scripts to M$hit.

^.^

Cheers,

I am having a problem with the restarter, it does not seem to launch the authserver. Just keeps spaming “cat: : No such file or directory”.

Haven’t tested nor used this restarter, but it uses

[CODE]PID=$(cat “$REALMPID”)

[/CODE]without $REALMPID defined.

It should probably be $AUTHSERVER →

PID=$(cat "$AUTHSERVER")

If it still fails: Check that all paths are correct and that both worldserver and authserver are configured to use .pid files

Corrected. /emoticons/default_wink.png

Thx for the report.

Note: For every core that you want to add, you have to run it with is own config to create the associated pid. Only this way the restarter will work. /emoticons/default_wink.png

Thx !

how to report always at any crash?

Enable GDB Tracing and you’ll see the GDB File on same folder.

@Athena,

would it be possible instead of having 1 file being overwritten everytime the core crash ( in this case the trace.log file ) to have it add a timestamp to the file?

maybe the core crashes multiple times on various reasons, then you can leave it running for some time without worrying that you miss a crash.

Replace

TRACE_FILE="trace.log"

With

TRACE_FILE="`date +%Y-%m-%d-%H-%M-%S`-trace.log"

thanks shocker.

@shocker somehow it doesnt work.

got today a new crash since last one was on date 24, but he overwritten that crashdump.

i want to collect crashdumps, and thats why i need those dates.

so now my crashdump of today ( december 26th ) was dumped in that trace.log of december 24th.

With the actual script you can’t have separate crash logs. Tomorrow i will look into it and change it to include the date and time on file name.

The actual script is dumping the whole screen, not the process only.

its too bad that the parsing of dump files to that website is not working anymore what was it elegeos.trinitycore.org or something.

i would love to have it working, or if possible even the possibility that people can host it themselfs, but i think that it needs extra scripting on the webserver front.

Ok, i made a little change on the script.

It will not rewrite the trace file, it will continue it… and separate the trace with a divisor with the date and time.

To create different files i have to look into it and do some testing.

Has for the trace site… i don’t know what it have behind it… If i know what to look, maybe i can create a parser myself. I need more free time to do it. /emoticons/default_wink.png

well the whole parser was on the subdomain of trinity itself as far as i know ( elegeos.trinitycore.org) so the files COULD be in hands of the admin that controls the domain…

or it must be deleted then its a shame…

Missing The Contents of paster and start

What? Im lost!

the paster is the subpart of the whole restarter wich parse the crashlog to the website

http://trinity.elegosproject.org.

anyway its not online anymore, but in case it gives you errors here it is.

Maybe its now possible to make a fully working parser??

anyway here it is:

[CODE]

#!/usr/bin/php

<?php /* CONFIGURATION $url: where to send the paste $author: the author of the report $description: revision, custom patches (if any) */ $url = "http://trinity.elegosproject.org/crash/index.php"; $author = "elegos"; $description = "Rev. 150"; ?> <?php function post_it($datastream, $url) { $url = preg_replace("@^http://@i", "", $url); $host = substr($url, 0, strpos($url, "/")); $uri = strstr($url, "/"); $reqbody = ""; foreach($datastream as $key=>$val) { if (!empty($reqbody)) $reqbody.= "&"; $reqbody.= $key."=".urlencode($val); } $contentlength = strlen($reqbody); $reqheader = "POST $uri HTTP/1.1\r\n". "Host: $host\n". "User-Agent: elegopaster/0.0.1\r\n". "Content-Type: application/x-www-form-urlencoded\r\n". "Content-Length: $contentlength\r\n\r\n". "$reqbody\r\n"; $socket = fsockopen($host, 80, $errno, $errstr); if (!$socket) { $result["errno"] = $errno; $result["errstr"] = $errstr; return $result; } fputs($socket, $reqheader); while (!feof($socket)) $result[] = fgets($socket, 4096); fclose($socket); return $result; } ?> <?php $prg = $argv[0]; $usage = "EleGoPaster by EleGoS v.1.0\n"; $usage .= "Usage: php $prg text to be sent\n"; $code = ""; $stdin = fopen('php://stdin', 'r'); while(!feof($stdin)) $code .= fgets($stdin, 4096); if($code == "") die($usage); $data["name"] = $author; $data["code_lang"] = "C++"; $data["tab_length"] = 9; $data["description"] = $description; $data["code"] = $code; $data["submit"] = "submit"; $return = post_it($data,$url); foreach($return as $line) { if(strpos($line,"<a href=") && strpos($line,"index.php?id=")) { $substring = strstr($line,"http:"); $last_char = strpos($substring,""); echo "(".date("F j, Y - g:i a") . ") " . substr($substring,0,$last_char)."\n"; } } ?>[/CODE]

gr.