forked from TrinityCore/TrinityCore
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mmowatcher.sh
204 lines (180 loc) · 6.78 KB
/
mmowatcher.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
#########################################################################################################
#
# Copyright (C) 2012 LORDofDOOM <https://github.com/LORDofDOOM>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################################################
#-------------------------------------------------------------------------------------------------------#
# INI Parser #
#-------------------------------------------------------------------------------------------------------#
# prefix for all global variables
INI_PREFIX=bash_inifile_
function ini_load {
# param1 inifile
local tmpfile=`(mktemp "${TMPDIR-/tmp}/bash_inifileXXXXXXXX") 2>/dev/null || echo ${TMPDIR-/tmp}/bash_inifile$$`
awk -v INI_PREFIX=${INI_PREFIX} -f - "$1" >$tmpfile <<EOF
# default global section
BEGIN {
FS="[[:space:]]*=[[:space:]]*"
section="globals";
}
{
# kill comments
sub(/;.*/, "");
}
/^\[[^\]]+\]$/ {
section=substr(\$0, 2, length(\$0) -2);
# map section to valid shell variables
gsub(/[^[[:alnum:]]/, "_", section)
printf "%s%s_keys=()\n", INI_PREFIX, section, INI_PREFIX, section
printf "%s%s_values=()\n", INI_PREFIX, section, INI_PREFIX, section
}
\$1 ~ /^[[:alnum:]\._]+\$/ {
# remove trail/head single/double quotes
gsub(/(^[\"\']|[\'\"]\$)/, "", \$2);
# escape inside single quotes
gsub(/\47/, "'\"'\"'", \$2);
printf "%s%s_keys=(\"\${%s%s_keys[@]}\" '%s')\n", INI_PREFIX, section, INI_PREFIX, section, \$1
printf "%s%s_values=(\"\${%s%s_values[@]}\" '%s')\n", INI_PREFIX, section, INI_PREFIX, section, \$2
}
EOF
while read line ; do
eval $line
done <${tmpfile}
rm ${tmpfile}
}
function ini_get_value {
# param1 section
# param2 key
# map section to valid bash variable like in awk parsing
local section=${1//[![:alnum:]]/_}
local keyarray=${INI_PREFIX}${section}_keys[@]
local valuearray=${INI_PREFIX}${section}_values[@]
local keys=("${!keyarray}")
local values=("${!valuearray}")
for (( i=0; i<${#keys[@]}; i++ )); do
if [[ "${keys[$i]}" = "$2" ]]; then
echo "${values[$i]}"
return 0
fi
done
return 1
}
function ini_get_sections {
eval local prefix_arrays=\${!$INI_PREFIX\*}
for varname in $prefix_arrays; do
# grep for key arrays
local arrayname=${varname#${INI_PREFIX}}
# strip trailing keys suffix
if [[ ${arrayname%*_keys} != ${arrayname} ]]; then
echo ${arrayname%*_keys}
fi
done
}
function ini_get_keys {
#param1 section
# map section to valid bash variable like in awk parsing
local section=${1//[![:alnum:]]/_}
local keyarray=${INI_PREFIX}${section}_keys[@]
local keys=("${!keyarray}")
echo ${keys[@]}
}
#-------------------------------------------------------------------------------------------------------#
# Color Codes #
#-------------------------------------------------------------------------------------------------------#
#white='\E[37;40m'
#red='\E[31;40m\033[1m'
#green='\E[32;40m\033[1m'
#yellow='\E[33;40m\033[1m'
red='\E[0;31m'
RED='\E[1;31m'
blue='\E[0;34m'
BLUE='\E[1;34m'
cyan='\E[0;36m'
CYAN='\E[1;36m'
NC='\033[0m' # no color
black='\E[0;30m'
BLACK='\E[1;30m'
green='\E[0;32m'
GREEN='\E[1;32m'
yellow='\E[0;33m'
YELLOW='\E[1;33m'
magenta='\E[0;35m'
MAGENTA='\E[1;35m'
white='\E[0;37m'
WHITE='\E[1;37m'
alias Reset="tput sgr0" # Reset colors #+ without clear command
cecho () # Color-echo.
# Argument $1 = Nachricht
# Argument $2 = Farbe
{
local default_msg="Text fehlt"
message=${1:-$default_msg} # default if no echo text
color=${2:-$white} # default color is white
echo -e "$color$message"
#Reset # Reset to normal color
tput sgr0 # Reset to normal color
return
}
#-------------------------------------------------------------------------------------------------------#
# Script variables #
#-------------------------------------------------------------------------------------------------------#
#INI LAUNCHER
LAUNCHER_SCREENNAME=`ini_get_value LAUNCHER SCREENNAME`
LAUNCHER_USERNAME=`ini_get_value LAUNCHER USERNAME`
LAUNCHER_START_IN_DEBUG_MODE=`ini_get_value LAUNCHER START_IN_DEBUG_MODE`
LAUNCHER_WORLDSERVER_BIN=`ini_get_value LAUNCHER WORLDSERVER_BIN`
LAUNCHER_WORLDSERVER_CONF=`ini_get_value LAUNCHER WORLDSERVER_CONF`
WORLDSERVER_FOLDER=`ini_get_value LAUNCHER WORLDSERVER_FOLDER`
#INI DEBUG
DEBUG_MODE=`ini_get_value DEBUG DEBUG_MODE`
DEBUG_CRASHLOG_FOLDER=`ini_get_value DEBUG CRASHLOG_FOLDER`
#-------------------------------------------------------------------------------------------------------#
# Script start #
#-------------------------------------------------------------------------------------------------------#
if [ "$DEBUG_MODE" = "1" ]; then
if [ -d $DEBUG_CRASHLOG_FOLDER ]; then
cecho "$DEBUG_CRASHLOG_FOLDER exist - Starting" $green
else
cecho "$DEBUG_CRASHLOG_FOLDER dont exist - Creating" $red
mkdir $DEBUG_CRASHLOG_FOLDER
fi
#cd $WORLDSERVER_FOLDER
TODAY=$(date +%Y%m%d-%H:%M)
echo "Copy next line & execute in different screen to see console output. You've to input in this one."
echo "tail -f $DEBUG_CRASHLOG_FOLDER/core.log"
while true; do
echo "run -c $LAUNCHER_WORLDSERVER_CONF" > $DEBUG_CRASHLOG_FOLDER/core.gdb
echo "bt" >> $DEBUG_CRASHLOG_FOLDER/core.gdb
echo "bt full" >> $DEBUG_CRASHLOG_FOLDER/core.gdb
echo "info thread" >> $DEBUG_CRASHLOG_FOLDER/core.gdb
echo "thread apply all backtrace full" >> $DEBUG_CRASHLOG_FOLDER/core.gdb
until gdb ./$LAUNCHER_WORLDSERVER_BIN -x $DEBUG_CRASHLOG_FOLDER/core.gdb --batch >$DEBUG_CRASHLOG_FOLDER/core.log 2>$DEBUG_CRASHLOG_FOLDER/core.err
grep -B 10 -A 1800 "SIG" "$DEBUG_CRASHLOG_FOLDER/core.log" >> "$DEBUG_CRASHLOG_FOLDER/coretrace_$(date +%Y%m%d-%H:%M).log"
#cat "coretrace.log" | ./paster | grep "http" >> "core.link"
cat "$DEBUG_CRASHLOG_FOLDER/core.err" >> "$DEBUG_CRASHLOG_FOLDER/coreerror.log"
echo "Crash... restarting!" >> $DEBUG_CRASHLOG_FOLDER/core.log
do sleep 31
done
done
echo "end"
else
#cd $WORLDSERVER_FOLDER
until ./$LAUNCHER_WORLDSERVER_BIN -c $LAUNCHER_WORLDSERVER_CONF 2>&1;
do date && echo "WorldServer server died with exit code $?. Restarting...";
sleep 1;
done;
fi