Jump to content
  • We are looking for staff for the Wiki area!
    If interested please
    click here and select "Documentation Team"

  • automatisation Realmd & Mangosd daemons auto-restarter


    Elmsroth

    Hello everyone !

    After setting-up your server on a Linux-based distro, you may wonder : 

    • how to let the realmd & mangosd deamons run on your server with all consoles closed ?
    • how to automatically restart theses daemons if they crash ?
    • hom to restart theses dameons ?
    • ho to get access to the daemons consoles after having closed all your terminals ?

    Well, you are at the right place !

    PREREQUISITE :

    The "screen" app must be installed and also "gdb" in order to correctly dump chrash data :

    sudo apt install screen gdb

    STEP 1 :

    Go to a folder where you would like to install the script.

    STEP 2 :

    Create a file called wowadmin.sh.

    Make it executable :

    chmod +x wowadmin.sh

    STEP 3 :

    Paste the code below in the file  and change the variables "/path/to/your/realmd" and "/path/to/your/mangosd" as your real paths to realmd and mangosd :

    #!/bin/bash
    
    THIS_FULLPATH=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd -P)/`basename "${BASH_SOURCE[0]}"`
    THIS_FOLDERPATH=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd -P)
    
    APATH=/path/to/your/realmd
    WPATH=/path/to/your/mangosd
    ASRV_BIN=realmd         #This usually doesnt change. TrinityCore: authserver  MaNGOS: realmd  ArcEmu: whocares?
    WSRV_BIN_ORG=mangosd    #This usually doesnt change. TrinityCore: worldserver MaNGOS: mangosd ArcEmu: whocares?
    WSRV_BIN=mangosd
    WSRV_SCR=mangosd
    
    echo "run" > gdbcommands
    echo "shell echo -e \"\nCRASHLOG BEGIN\n\"" >> gdbcommands
    echo "info program" >> gdbcommands
    echo "shell echo -e \"\nBACKTRACE\n\"" >> gdbcommands
    echo "bt" >> gdbcommands
    echo "shell echo -e \"\nBACKTRACE FULL\n\"" >> gdbcommands
    echo "bt full" >> gdbcommands
    echo "shell echo -e \"\nTHREADS\n\"" >> gdbcommands
    echo "info threads" >> gdbcommands
    echo "shell echo -e \"\nTHREADS BACKTRACE\n\"" >> gdbcommands
    echo "thread apply all bt full" >> gdbcommands
    
    DEBUG=false
    
    #WORLD FUNCTIONS
    startWorld()
    {
        if [ "$(screen -ls | grep $WSRV_SCR)" ]
        then
            echo $WSRV_BIN is already running
        else
            cd $WPATH
            screen -AmdS $WSRV_SCR $THIS_FULLPATH $WSRV_BIN $DEBUG
            echo $WSRV_BIN is alive
        fi
    }
    
    restartWorld()
    {
        screen -S $WSRV_SCR -X stuff "saveall$(printf \\r)"
        echo saved all characters, and server restart initialized
        screen -S $WSRV_SCR -X stuff "server restart 5$(printf \\r)"
    }
    
    stopWorld()
    {
        screen -S $WSRV_SCR -X stuff "saveall
        "
        echo saveall sent, waiting 5 seconds to kill $WSRV_BIN
        sleep 5
        screen -S $WSRV_SCR -X kill &>/dev/null
        echo $WSRV_BIN is dead
    }
    
    monitorWorld()
    {
        echo press ctrl+a+d to detach from the server without shutting it down
        sleep 5
        screen -r $WSRV_SCR
    }
    #AUTH FUNCTIONS
    startAuth()
    {
        if [ "$(screen -ls | grep $ASRV_BIN)" ]
        then
            echo $ASRV_BIN is already running
        else
            cd $APATH
            screen -AmdS $ASRV_BIN $THIS_FULLPATH $ASRV_BIN
            echo $ASRV_BIN is alive
        fi
    }
    
    stopAuth()
    {
        screen -S $ASRV_BIN -X kill &>/dev/null
        echo $ASRV_BIN is dead
    }
    
    restartAuth()
    {
        stopAuth
        startAuth
        echo $ASRV_BIN restarted
    }
    
    monitorAuth()
    {
        echo press ctrl+a+d to detach from the server without shutting it down
        sleep 5
        screen -r $ASRV_BIN
    }
    
    #FUNCTION SELECTION
    case "$1" in
        $WSRV_BIN )
        if [ "$2" == "true" ]
        then
            while x=1;
            do
                gdb $WPATH/$WSRV_BIN --batch -x gdbcommands | tee current
                NOW=$(date +"%s-%d-%m-%Y")
                mkdir -p $THIS_FOLDERPATH/crashes
                mv current $THIS_FOLDERPATH/crashes/$NOW.log &>/dev/null
                killall -9 $WSRV_BIN
                echo $NOW $WSRV_BIN stopped, restarting! | tee -a $THIS_FULLPATH.log
                echo crashlog available at: $THIS_FOLDERPATH/crashes/$NOW.log
                sleep 1
            done
        else
            while x=1;
            do
                ./$WSRV_BIN
                NOW=$(date +"%s-%d-%m-%Y")
                echo $NOW $WSRV_BIN stopped, restarting! | tee -a $THIS_FULLPATH.log
                sleep 1
            done
        fi
        ;;
        $ASRV_BIN )
            while x=1;
            do
                ./$ASRV_BIN
                NOW=$(date +"%s-%d-%m-%Y")
                echo $NOW $ASRV_BIN stopped, restarting! | tee -a $THIS_FULLPATH.log
                sleep 1
            done
        ;;
        "wstart" )
        startWorld
        ;;
        "wdstart" )
        DEBUG=true
        startWorld
        ;;
        "wrestart" )
        restartWorld
        ;;
        "wstop" )
        stopWorld
        ;;
        "wmonitor" )
        monitorWorld
        ;;
    
        "astart" )
        startAuth
        ;;
        "arestart" )
        restartAuth
        ;;
        "astop" )
        stopAuth
        ;;
        "amonitor" )
        monitorAuth
        ;;
        
        "start" )
        startWorld
        startAuth
        ;;
        "stop" )
        stopWorld
        stopAuth
        ;;
        "restart" )
        restartWorld
        restartAuth
        ;;
        * )
        echo Your argument is invalid
        echo "usage: start | stop | restart | wstart | wdstart | wrestart | wstop | wmonitor | astart | arestart | astop | amonitor"
        exit 1
        ;;
    esac

    USAGE :

    You can use the script with its options like :

    ./wowadmin.sh start

    Available options are :

    • start : Starts realmd and mangosd - in a screened process.
    • stop : Stops realmd and mangosd - in a screened process.
    • restart : Retarts realmd and mangosd - in a screened process.
    • wstart : Starts only mangosd - in a screened process.
    • wdstart : Starts only mangosd in DEBUG mode - in a screened process.
    • wrestart : Restarts only mangosd - in a screened process
    • wstop : Stops mangosd - screened process.
    • wmonitor : Brings back the mangosd console from the screened process (press "Ctrl+A+D" to re-detach it).
    • astart : Starts only realmd - in a screened process.
    • arestart : Restarts only realmd - in a screened process.
    • astop : Stops only realmd - in a screened process.
    • amonitor : Brings back the realmd console (press "Ctrl+A+D" to re-detach it).

    Moreover, when there is a crash, the daemons will auto-restart dans there will be a crashlog dumped in "crashes" directory next to your deamons executable binaries.

    For your information, you can see the screened processes by typing :

    screen -ls

    You can use multiple wowadmin.sh files if you manage multiple realms but the more simple would be to add specific options in the same script for your differents mangosd dameons as there could be only 1 realmd daemon running and many mangosd daemons running.

    Source : adapted from  Lillecarl Gist



    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

Contact Us

To contact us click here
You can also email us at [email protected]

Privacy Policy | Terms & Conditions

Repositories

The Link to the master list
of MaNGOS repositories:
Copyright © getMaNGOS. All rights Reserved.

This website is in no way associated with or endorsed by Blizzard Entertainment®
×
×
  • Create New...