linux下编译mangos,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

下面是完整代码下载

游客,如果您要查看本帖隐藏内容请回复

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

6276bcf60295a986e64f40d009119ebe.gif

x

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值