1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

Linux KAG How to run a server and help the devs fix crashes

Discussion in 'Server Help' started by FliesLikeABrick, Apr 5, 2012.

  1. FliesLikeABrick

    FliesLikeABrick THD Team THD Team Administrator Global Moderator

    Messages:
    952
    Hey all,

    I am going to give a brief description of how to run servers on linux in such a way that you can get information which tells the devs almost exactly what caused the crash.

    This can be done by running the server on an active console or in screen. An active console is easier unless you are very familiar with screen (such as how to scroll back so you can fetch more information).

    What we are going to do here is run a server with the GNU Debugger, gdb. In the event of a server crash due to a bug in the code, a corrupted variable, etc.

    I will assume you have your server downloaded and configured.

    First install gdb. If you're running debian-alike (like Ubuntu, Debian, etc), you can do this with
    sudo apt-get install gdb

    Instead of running the server with ./dedicatedserver.sh or another command directly, the server will be run inside a debug environment. This probably requires slightly more CPU power, but not enough that it impacts performance for a server.

    You can see from `cat dedicatedserver.sh` that the command that actually runs the server with is:
    Code:
    ./KAGdedi autostart Scripts//dedicated_autostart.gm autoconfig Scripts/dedicated_autoconfig.gm
    Instead, we are going to run it with gdb, such as:
    gdb ./KAGdedi

    You will see 10-20 lines as gdb loads the server binary into memory, followed by the prompt:
    (gdb)

    Now we will actually start the server by typing 'run' followed by the arguments to KAGdedi
    (gdb) run


    At this point your server is running.

    Now, if it eventually crashes you will see something like this (but probably with different text) in the end of the output to the console:
    Code:
    [15:41:49] <Sir Retrofit> wait
    
    [15:41:57] <callofduty13426> help!
    
    [15:42:04] <callofduty13426> dam you bird
    
    [15:42:07] <CL leogro> :O!
    
    [15:42:12] <Shanix> greaifers
    
    [15:42:16] <Confs> fuck
    
    [15:42:19] <Confs> was just abotu to lay a brick
    
    [15:42:30] <<WRTW GloriousToast> I GOT 27- GP;D
    
    Program received signal SIGSEGV, Segmentation fault.
    
    CBlob::DoTick (this=0xb5906748) at ../Juxta/juxta_blob.cpp:188
    
    188 ../Juxta/juxta_blob.cpp: No such file or directory.
    
    in ../Juxta/juxta_blob.cpp
    
    
    followed by:
    (gdb)

    Note that it says SIGSEGV/Segmentation fault. This type of crash is most common and the steps below will help gather precious information for the devs to troubleshoot and resolve the problem.

    Note that the gdb prompt (bolded above) is waiting for a command (bold above). Type "bt full" which will produce a full backtrace of the function call that caused the crash. This will look like:
    (gdb) bt full

    Code:
    #0 CBlob::DoTick (this=0xb5906748) at ../Juxta/juxta_blob.cpp:188
    
    No locals.
    
    #1 0x0063241e in CZombie::DoTick (this=0xb5906748) at ../Entities/zombie.cpp:72
    
    No locals.
    
    #2 0x00778b1c in CActor::Think (this=0xb5906748) at ../World/actor.cpp:162
    
    No locals.
    
    #3 0x007acc02 in CWorldTask::Update (this=0x8161048) at ../World/world.cpp:208
    
    i = 14
    
    #4 0x0060a401 in CKernel::Execute (this=0x80e95e0) at ../Engine/kernel.cpp:86
    
    t = 0x0
    
    thisIt = <optimized out>
    
    nocompensate = <optimized out>
    
    mainControl = 0
    
    #5 0x006506a6 in CGame::Run (this=0x80e5c00, argc=1, argv=0xbffff7d4) at ../Game/GameDLL.cpp:396
    
    No locals.
    
    #6 0x0065092c in GameDLLInit (ie=..., argc=1, argv=0xbffff7d4) at ../Game/GameDLL.cpp:84
    
    profilehandler = {<IProfilerOutputHandler> = {_vptr.IProfilerOutputHandler = 0xad40d0}, <No data fields>}
    
    script = 0x80cb638
    
    console = 0x80d5388
    
    filename = {array = 0x80e2a88 "Logs/console-12-04-01-10-39-51.txt", allocated = 35, used = 35, allocator = {_vptr.irrAllocator = 0xad3cb8}}
    
    now = 1333291191
    
    #7 0x0804e994 in CApplication::LoadGameDLL (this=0x80b6088, filename=0x80b93c4 "Base/libJuxta_dedi.so", argc=1, argv=0xbffff7d4) at ../App/main.cpp:334
    
    initializer = 0x650718
    
    module = 0x80ba3c0
    
    #8 0x0804ed5a in CApplication::Run (this=0x80b6088, argc=1, argv=0xbffff7d4) at ../App/main.cpp:221
    
    dllFile = {static npos = 4294967295,
    
    _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
    
    _M_p = 0x80b93c4 "Base/libJuxta_dedi.so"}}
    
    path = <optimized out>
    
    buildnum = <optimized out>
    
    #9 0x0804ee41 in main (argc=1, argv=0xbffff7d4) at ../App/main.cpp:592
    
    restart = {array = 0xbffff708 "8\367\377\277\371X\t\bЫ\004\b", allocated = 134521053, used = 1243416, allocator = {_vptr.irrAllocator = 0x8049789}}
    
    dir = {array = 0xbffff6f8 "\b\367\377\277ݠ\004\b\030\371\022", allocated = 134830443, used = 2239104, allocator = {_vptr.irrAllocator = 0x80a61bc}}
    
    
    (gdb)


    Copy all of this, and at least the last 50 lines of the game console output to a text file and attach it to a forum post, or e-mail it to me at ryan [at] u13 dawt net. I will review it and share it with MM/Geti to have it looked into (or I'll look into it myself it it's in my code or something I can look at)


    Running your server this way can very greatly help the devs improve the stability of the server, as this gives 100% useful information about exactly where in the code the server crashed.'

    Once you have saved the information, you can type quit at the remaining gdb prompt. It will ask you if you're sure, to which you type
    (gdb) quit
    A debugging session is active.

    Inferior 1 [process 26852] will be killed.

    Quit anyway? (y or n) y




    And now you're ready to restart your server again:
    ryan@graybar:~/kag_linux$ gdb ./KAGdedi
    [...]
    (gdb) run autostart Scripts/dedicated_autostart.gm autoconfig Scripts/dedicated_autoconfig.gm


    Thanks for reading, and I hope as many of you server owners as possible can participate in this to help remove remaining stability issues from the server!
     
    Last edited by a moderator: Mar 15, 2016
  2. trelawney

    trelawney KAG Guard Tester

    Messages:
    771
    You can run gdb in a GNU Screen window and log your output to a file (saves you a few copy and paste clicks and keystrokes). To enable session logging in screen, edit your .screenrc file (located in your home directory), and add the following near the end:
    Code:
    logfile $HOME/screen-%Y%m%d-%n.log
    deflog on
    
     
    acridstone likes this.
  3. Skurcey

    Skurcey Catapult Fodder

    Messages:
    86
  4. Thanks this really helped!!!:)
     
  5. FliesLikeABrick

    FliesLikeABrick THD Team THD Team Administrator Global Moderator

    Messages:
    952
    Note that an alternative to running the server in gdb is to execute 'ulimit -c unlimited' in the same shell before running the dedicated server. This will cause the kernel to write a memory dump to the file Base/core upon a segfault or similar crash.

    In this case you can just send me the core file and I will be able to extract the backtrace from it
     
  6. GloriousToast

    GloriousToast Haxor Donator

    Messages:
    1,463
    Can you change the title to say that you've done this on linux?
     
  7. FliesLikeABrick

    FliesLikeABrick THD Team THD Team Administrator Global Moderator

    Messages:
    952
    done, thanks for the suggestion
     
  8. Eden

    Eden Galen Slayer Donator

    Messages:
    65
    Does this work for Windows too?

    If it doesn't is there any way?!
     
  9. Doc22

    Doc22 Builder Stabber

    Messages:
    51
    Find a debugging tool for windows that uses C++ (according to the .cpp error) and change the dedicated server.bat to run kag.exe with the debugging tool.
     
  10. Eden

    Eden Galen Slayer Donator

    Messages:
    65
    I didnt under stand any of that, aha :p allG
     
  11. Doc22

    Doc22 Builder Stabber

    Messages:
    51
    Ok, so download this:
    http://sourceforge.net/projects/mingw/files/latest/download?source=files
    Install it, and change dedicated server.bat to this:
    c:\mingw\bin\gdb.exe KAG.exe nolauncher noautoupdate autostart Scripts/dedicated_autostart.gm autoconfig Scripts/dedicated_autoconfig.gm]

    Hopefully it should work. If it runs as regular king arthurs gold, (not the server) then its a problem with the params, and I don't know how to fix it.
     
  12. D0ubl3Tr0ubl3

    D0ubl3Tr0ubl3 Shopkeep Stealer

    Messages:
    282
    Can you speak in english please?
     
  13. Twisty

    Twisty Catapult Fodder

    Messages:
    4
    Thanks! you helped me out!
     
    IxKINGzZ and IxLUCKYzZ like this.
  14. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    For current version, when you see (dbg), type
    Code:
    run ../autoconfig.cfg
    instead of
    Code:
    run autostart Scripts/dedicated_autostart.gm autoconfig Scripts/dedicated_autoconfig.gm
     
  15. Tsilliev

    Tsilliev Haxor

    Messages:
    414
    I did login as root, install dgb, then with filezilla I edit the dedicatedserver.sh and last line instead of the "./KAGdedi autostart Scripts/s......" now its only run../autostart but when I do ./startkag it stays red and server doesn't start, is it outdated?
     
  16. Furai

    Furai THD Team THD Team Administrator

    Messages:
    3,124
    It's called gdb.

    Literally all you need to do is 2 commands. No need to edit anything. First you go into your main KAG server folder. Then you do:
    Code:
    gdb ./KAGdedi
    And then inside gdb just:
    Code:
    run
    You don't need to do anything else. The guide says it all.
     
  17. Tsilliev

    Tsilliev Haxor

    Messages:
    414
    Thank you for the clarification! Server is up using screen dgb ./KAGdedi because it went offline when i exit putty, thanks.