当前位置:首页>>魔兽单机>>正文
Linux下MANGOS服务端自动重启Shell启动脚本
2013-04-23 11:49:36 作者:网络 来源: 浏览次数:0
摘要:Linux下MANGOS服务端自动重启Shell启动脚本
 下面是一个Linux下支持的一个启动服务端的Shell代码。可以实现服务端当机后自动重新启动。

同时可以支持LINUX下用GDB对mangos进行当机调试,输出结果到crashes/Server.log  ??

你需要根据你的单机版在Linux中的路径调整下面的文件

#! /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=/home/mangos/mangos-server/bin
WPATH=/home/mangos/mangos-server/bin
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 \" CRASHLOG BEGIN \"" >> gdbcommands
echo "info program" >> gdbcommands
echo "shell echo -e \" BACKTRACE \"" >> gdbcommands
echo "bt" >> gdbcommands
echo "shell echo -e \" BACKTRACE FULL \"" >> gdbcommands
echo "bt full" >> gdbcommands
echo "shell echo -e \" THREADS \"" >> gdbcommands
echo "info threads" >> gdbcommands
echo "shell echo -e \" THREADS BACKTRACE \"" >> 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 \ )"
    echo saved all characters, and server restart initialized
    screen -S $WSRV_SCR -X stuff "server restart 5$(printf \ )"
}
 
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



下面是完整代码下载



点击下载完整代码


 


相关报道:

[关闭] [返回顶部]


  返回首页 | 最新资讯 | 资源下载 | 魔兽图片 | 单机文档 | 技术攻略 | 玩家视频
备案号:蜀ICP备2024062380号-1
免责声明:本网站为热爱怀旧WOW的玩家们建立的魔兽世界资料网站,仅供交流和学习使用,非盈利和商用.如有侵权之处,请联系我们,我们会在24小时内确认删除侵权内容,谢谢合作。
Copyright © 2024 - 2024 WOWAII.COM Corporation, All Rights Reserved

机器人国度