[BATCH] Restart with GDB

Hello, im searching for a restart that also provides crashlog, im currently use this one but it doesnt provide anything(something miss with the core files, i have gdb installed)

[CODE]# path to mangos-worldd binary

daemon=/root/hardcorepvp/bin/hardcorepvp

system

export LD_LIBRARY_PATH=.:lib:$LD_LIBRARY_PATH

ulimit -c unlimited

while true

do 

TRINITY=`ps -el | grep hardcorepvp`

$daemon $*

if [ -z "$TRINITY" ]; then

    dte=`date +%F_%H-%M-%S`

    gdb $daemon core.* --batch --eval-command="bt ful" > crash_log_$dte.log

    rm core.*

fi

sleep 2

done[/CODE]

OS: ubuntu

Someone?

I used this one with mangos core:

[CODE]#!/bin/sh

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

About: Auto restart mangos-worldd on crash & generate crash report into crash_log_(DATE_TIME).log

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

1. Compile MaNGOS with parameter: --with-debug-info

2. Put auto_restarter.sh into compiled mangos directory (where folders: bin/, lib/, etc/)

3. (Only once): chmod +x auto_restarter.sh

4. Usage: ./auto_restarter.sh -c etc/mangosd.conf

p.s. Make sure you have “gdb” installed.

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

config:

path to mangos-worldd binary

daemon=./bin/mangos-worldd

system

export LD_LIBRARY_PATH=.:lib:$LD_LIBRARY_PATH

if [ “ulimit -c” -eq 0 ]; then

ulimit -c unlimited

fi

while true

do

$daemon $*

if [ $? -eq 0 ]; then

break;

fi

sleep 10

dte=`date +%F_%H-%M-%S`

gdb $daemon core.* --batch --eval-command="bt ful" > /var/log/mangos/crash/crash_log_$dte.log

rm core.*

sleep 5

done[/CODE]
Did u compile with debug flag? Btw check permissions for directory.

[CODE]BCKTRC=$(date +“backtrace_%Y-%m-%d_%H-%M-%S.txt”)

mv ~/backtrace.log ~/server/crashes/$BCKTRC

screen -A -m -d -S world gdb -x crashreport.gdb $daemon[/CODE]
https://github.com/TrinityCore/TrinityCore/tree/master/contrib/debugger → crashreport.gdb

try to integrate that into your script and it should work just fine

Something like this, I suppose.

[CODE]# path to mangos-worldd binary

daemon=/root/hardcorepvp/bin/hardcorepvp

system

export LD_LIBRARY_PATH=.:lib:$LD_LIBRARY_PATH

ulimit -c unlimited

while true

do 

TRINITY=`ps -el | grep hardcorepvp`

if [ -z "$TRINITY" ]; then

	BCKTRC=$(date +"backtrace_%Y-%m-%d_%H-%M-%S.txt")

	mv ~/backtrace.log ~/server/crashes/$BCKTRC

	gdb -x crashreport.gdb $daemon

fi

sleep 2

done[/CODE]

What premision of the dir? And what dir exactly?

Since u create crash log without any path, u should go to the folder where is this scripts located and type in console “ls -l”. Then checkout ur permissions. To learn more use this->link. Btw did u try solution by Ishigure?

Nope his solution dont work , just get that backtrace.log error , not exist

Try to check if file exists then move it:

[CODE]if [ -f ~/backtrace.log ]; then

mv ~/backtrace.log ~/server/crashes/$BCKTRC

fi

[/CODE]

killradio_1337 , how should the whole script look like , im not good with batch files

[CODE]# path to mangos-worldd binary

daemon=/root/hardcorepvp/bin/hardcorepvp

system

export LD_LIBRARY_PATH=.:lib:$LD_LIBRARY_PATH

ulimit -c unlimited

while true

do 

TRINITY=`ps -el | grep hardcorepvp`

if [ -z "$TRINITY" ]; then

    BCKTRC=$(date +"backtrace_%Y-%m-%d_%H-%M-%S.txt")

        if [ -f ~/backtrace.log ]; then

            mv ~/backtrace.log ~/server/crashes/$BCKTRC

        fi

    gdb -x crashreport.gdb $daemon

fi

sleep 2

done[/CODE]
But u should change directories used in this script.

Nothing happens if i run it : I get this information:

[CODE]root@ks308466:~/hardcorepvp# GNU gdb (GDB) 7.1-ubuntu

Copyright (C) 2010 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law. Type “show copying”

and “show warranty” for details.

This GDB was configured as “x86_64-linux-gnu”.

For bug reporting instructions, please see:

http://www.gnu.org/software/gdb/bugs/

Reading symbols from /root/hardcorepvp/bin/hardcorepvp…done.

crashreport.gdb: No such file or directory.

(gdb)

[/CODE]

crashreport.gdb: No such file or directory.

U have to put chashreport.gdb in the same directory or try to set path like:

        gdb -x /root/hardcorepvp/debugger/crashreport.gdb $daemon

Before start ur bash script u can just execute this command - gdb -x /root/hardcorepvp/debugger/crashreport.gdb /root/hardcorepvp/bin/hardcorepvp. If u will get no errors - execute script.

The question is: How the hell can i get crashreport.gdb? , just create emtpy file or what?

https://github.com/TrinityCore/TrinityCore/tree/master/contrib/debugger

THIS FILE COMES WITH SOURCES!

U need correct directories in script, single command and try again.

Thank you very much: Btw your restarter wasnt complete, it didnt restart /emoticons/default_sad.png

This is working for me:


# path to mangos-worldd binary

daemon=/root/hardcorepvp/bin/hardcorepvp

# system

export LD_LIBRARY_PATH=.:lib:$LD_LIBRARY_PATH

if [ "`ulimit -c`" -eq 0 ]; then

    ulimit -c unlimited

    fi


while true

    do 

    TRINITY=`ps -el | grep hardcorepvp`

	$daemon $*

    if [ -z "$TRINITY" ]; then

        BCKTRC=$(date +"crashlog_%Y-%m-%d_%H-%M-%S.txt")

            if [ -f backtrace.log ]; then

                mv backtrace.log /root/hardcorepvp/$BCKTRC

            fi

        gdb -x crashreport.gdb $daemon

    fi

    sleep 2

done

You’re welcome =)

Another one:

[CODE]#!/bin/sh

path to worldserver binary

daemon=./bin/worldserver

system

export LD_LIBRARY_PATH=.:lib:$LD_LIBRARY_PATH

if [ “ulimit -c” -eq 0 ]; then

ulimit -c unlimited

fi

while true

do

$daemon $*

if [ $? -eq 0 ]; then

    break;

fi

sleep 10

BCKTRC=$(date +"crashlog_%Y-%m-%d_%H-%M-%S.log")

    if [ -f backtrace.log ]; then

        mv backtrace.log /var/log/trinity/$BCKTRC

    fi

gdb -x crashreport.gdb $daemon

sleep 5

done[/CODE]

nice work, it will be good for crashhunting

File core → full image of process $daemon running in ur system.

Erm… why are you running the server as root?!