-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoCheck.sh
More file actions
147 lines (132 loc) · 5.53 KB
/
AutoCheck.sh
File metadata and controls
147 lines (132 loc) · 5.53 KB
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
#!/bin/bash
echo " _______ _ "
echo "|__ __| | | "
echo " | | __ _ _ __ __ _ __| | ___ ___ "
echo " | |/ _' | '_ \ / _' |/ _' |/ _ \/ __| "
echo " | | (_| | | | | (_| | (_| | (_) \__ \ "
echo " |_|\__,_|_| |_|\__,_|\__,_|\___/|___/ "
echo " "
echo -n "=> 0% "
for i in {1..100}
do
# Create a string with the current loading percentage
percent="$(printf "=>%3d%%" "$i")"
# Overwrite the current line with the updated percentage
echo -ne "$percent\r"
# Sleep for a short interval to simulate some processing
sleep 0.20
done
# Realm Configuration
current_date=$(date +'%Y-%m-%d_%H:%M')
realm1_auth_log="logs/realms/realm1/Auth.log" #location of your Auth.log
realm1_dberrors_log="logs/realms/realm1/DBErrors.log" #location of your DBErrors.log
realm1_auth_tmux="auth" #tmux session name
realm1_auth_command="/root/wow/acore.sh run-authserver" #Command to run in tmux session
realm1_auth_log_path="logs/AutoCheck/realm1/Auth.log"
realm1_auth_log_path_error="logs/AutoCheck/realm1/Auth-$(date +'%Y-%m-%d_%H:%M').log"
realm1_server_log="logs/realms/realm1/Server.log" #location of your Server.log
realm1_world_tmux="world" #tmux session name
realm1_world_command="/root/wow/acore.sh run-worldserver" #Command to run in tmux session
realm1_world_log_path="logs/AutoCheck/realm1/Realm1.log"
realm1_world_log_path_error="logs/AutoCheck/realm1/Realm1-$(date +'%Y-%m-%d_%H:%M').log"
realm2_server_log="logs/realms/realm2/Server.log" #location of your Server.log
realm2_dberrors_log="logs/realms/realm2/DBErrors.log" #location of your DBErrors.log
realm2_world_tmux="world2" #tmux session name
realm2_world_command="/root/wow2/acore.sh run-worldserver" #Command to run in tmux session
realm2_world_log_path="logs/AutoCheck/realm2/Realm2.log"
realm2_world_log_path_error="logs/AutoCheck/realm2/Realm2-$(date +'%Y-%m-%d_%H:%M').log"
external_ip="your.logon.com" #your external ip or dns
auth_port="3724" #Port of your auth server
realm1_port="8085" #Port of your Realm1 World server
realm2_port="8086" #Port of your Realm2 World server
mysql_ip="127.0.0.1" #internal mysql ip or external
mysql_port="3306" #port of your Mysql
realm1_name="Realm1" #name of your realm1
realm2_name="Realm2" #name of your realm2
noerror="/root/wow/logs/AutoCheck/NoErrorFound.log" #No Error log file that discord.sh will youse to send to you in event of non error
WEBHOOK="https://discord.com/api/webhooks/" #A discord configuration for WebHooks
# Check Auth Log for Errors
if grep -q 'ERROR' $realm1_auth_log; then
ping -c 3 $external_ip -p $auth_port &>/dev/null
if [ $? -ne 0 ]; then
if grep -q 'Lost connection' $realm1_dberrors_log; then
ping -c 3 $mysql_ip -p $mysql_port &>/dev/null
if [ $? -ne 0 ]; then
systemctl restart mysql
fi
fi
tmux kill-session -t $realm1_auth_tmux
tmux new-session -s $realm1_auth_tmux -d $realm1_auth_command
fi
echo "Auth log check complete, Error log located at $realm1_auth_log_path" &>> $realm1_auth_log_path_error
else
echo "No errors found in Auth log." &>> $realm1_auth_log_path
fi
sleep 5
# Check World Log for Errors
if grep -q 'ERROR' $realm1_server_log; then
ping -c 3 $external_ip -p $realm1_port &>/dev/null
if [ $? -ne 0 ]; then
if grep -q 'Lost connection' $realm1_dberrors_log; then
ping -c 3 $mysql_ip -p $mysql_port &>/dev/null
if [ $? -ne 0 ]; then
systemctl restart mysql
fi
fi
tmux kill-session -t $realm1_world_tmux
tmux new-session -s $realm1_world_tmux -d $realm1_world_command
fi
echo "$realm1_name log check complete, Error log located at $realm1_world_log_path" &>> $realm1_world_log_path_error
else
echo "No errors found in $realm1_name log." &>> $realm1_world_log_path
fi
sleep 5
# Check World2 Log for Errors
if grep -q 'ERROR' $realm2_server_log; then
ping -c 3 $external_ip -p $realm2_port &>/dev/null
if [ $? -ne 0 ]; then
if grep -q 'Lost connection' $realm2_dberrors_log; then
ping -c 3 $mysql_ip -p $mysql_port &>/dev/null
if [ $? -ne 0 ]; then
systemctl restart mysql
fi
fi
tmux kill-session -t $realm2_world_tmux
tmux new-session -s $realm2_world_tmux -d $realm2_world_command
fi
echo "$realm2_name log check complete, log located at $realm2_world_log_path" &>> $realm2_world_log_path_error
else
echo "No errors found in $realm2_name log." &>> $realm2_world_log_path
fi
#Discord send only Error files
current_date2=$(date +%Y-%m-%d)
last_run_date=$(cat last_run_date.txt 2>/dev/null)
listfiles=($realm1_auth_log_path_error $realm1_world_log_path_error $realm2_world_log_path_error)
existing_files=()
for file in "${listfiles[@]}"; do
if [ -f "$file" ]; then
existing_files+=( "$file" )
fi
done
if [ ${#existing_files[@]} -eq 0 ] && [ "$current_date2" != "$last_run_date" ]; then
existing_files=($noerror)
echo "$current_date2" > last_run_date.txt
fi
cd ~/wow/discord
for existing_file in "${existing_files[@]}"; do
./discord.sh \
--webhook-url=$WEBHOOK \
--file $existing_file \
--username "The Watcher" \
--text "AutoCheck Service for $current_date\nPlece take a look for errors!"
done
echo "AutoCheck Service for $current_date is complete"
# Check if servers are back
nc -zw 10 $external_ip $auth_port || \
nc -zw 10 $external_ip $realm1_port || \
nc -zw 10 $external_ip $realm2_port && {
echo "Servers are down. Rebooting PC...";
timeout -t 10 reboot
}
echo "Servers are Online."
echo "Check the logfiles for missed errors."