/
serverchk.sh
executable file
·149 lines (141 loc) · 4.73 KB
/
serverchk.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
#!/bin/bash
# server checker
ping 103.214.111.90 -c 2 -i .25 &> /dev/null
if [ $? -ne 0 ];
then
echo "MAIN IP DOWN! NOT CHECKING!"
exit 1
fi
ping 1.1.1.1 -c 2 -i .25 &> /dev/null
if [ $? -ne 0 ];
then
echo "CANNOT ACCESS INTERNET! NOT CHECKING!"
exit 2
fi
ping google.com -c 2 -i .25 &> /dev/null
if [ $? -ne 0 ];
then
echo "DNS NONFUNCTIONAL! NOT CHECKING!"
exit 4
fi
declare -a tfServerList=(
"tfCOMP"
"tfPUG1"
"tfPUG2"
"tfNOOB1"
"tfMGE"
"tfMGE_ELO1"
"tfMGE_ELO2"
"tfDM1"
"tfDM2"
"tfDM3"
"tfDM4"
"tfJUMP1"
"tfBB1"
"tfULTI1"
"tfPUB"
"tfBLAZER"
)
for entry in "${tfServerList[@]}"; do
if [[ "$entry" == *"RGL"* ]] || [[ "$entry" == *"PUG"* ]];
then
tfPath="/home/game/rglSRV/$entry/"
elif [[ "$entry" == *"NOOB"* ]];
then
tfPath="/home/game/newbieSRV/$entry/"
elif [[ "$entry" == *"BLAZE"* ]];
then
tfPath="/home/game/blazer/$entry/"
else
tfPath="/home/game/$entry/"
fi
pgrep -fal "$tfPath"tf2/srcds &> /dev/null
if [ $? -ne 0 ];
then
echo -e "\e[31m$entry down! \e[39mRestarting..."
tmux kill-session -t $entry ; tmux new-session -d -s $entry ;
tmux send-keys -t $entry "$tfPath"tf.sh ENTER ;
else
if [[ $( echo ""$(awk '{print $1}' /proc/uptime)" / 60 < 30" | bc -l ) -eq 1 ]] || [[ $(echo "$(uptime | sed 's/,//g' | awk '{ print $8 }')" ">= 8" | bc -l) -eq 1 ]]
then
echo -e "\e[36m-> SYSTEM LOAD IS TOO HIGH OR MASTER WAS JUST RESTARTED!! SERVER PROCESS EXISTS BUT HAS NOT BEEN CHECKED WITH GAMEDIG!\e[39m"
else
# ugly
ip=$(cat "$tfPath"tf.sh | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
port=$(cat "$tfPath"tf.sh | grep -oE "\bport \b(.....)\b" | grep -oE "\b[0-9]{5}\b")
for (( i=1; i<=5; i++ )); do
#echo $ip
#echo $port
#echo "$ip":"$port"
gamedig --type tf2 "$ip":"$port" | grep "Failed all" &> /dev/null
if [ $? -ne 0 ]; # succeeded!
then
echo -e "\e[32m$entry \e[39mfunctional."
break
else
echo -e "\e[33m$entry not responding. \e[39mRechecking..."
sleep 5
fi
if [ $i -eq 5 ]
then
echo -e "\e[31m$entry down! \e[39mRestarting..."
tmux kill-session -t $entry ; tmux new-session -d -s $entry ;
tmux send-keys -t $entry "$tfPath"tf.sh ENTER ;
fi
done
fi
fi
done
declare -a mcServerList=(
"mcOLD"
"mcNEW"
"mcNAT"
)
for mcEntry in "${mcServerList[@]}";
do
if [[ "$mcEntry" == *"mcOLD" ]]; then
mcPath="/home/game/mc/server_old/"
elif [[ "$mcEntry" == *"mcNAT" ]]; then
mcPath="/home/game/mc/serverNAT/"
elif [[ "$mcEntry" == "mcNEW" ]]; then
mcPath="/home/game/mc/server/"
fi
pgrep -fal "$mcPath" &> /dev/null
if [ $? -ne 0 ];
then
echo -e "\e[31m$mcEntry down! \e[39mRestarting..."
tmux kill-session -t $mcEntry ; tmux new-session -d -s $mcEntry ;
tmux send-keys -t $mcEntry cd ' ' "$mcPath" ENTER
tmux send-keys -t $mcEntry "$mcPath"mc.sh ENTER
else
if [[ $( echo ""$(awk '{print $1}' /proc/uptime)" / 60 < 30" | bc -l ) -eq 1 ]] || [[ $(echo "$(uptime | sed 's/,//g' | awk '{ print $8 }')" ">= 8" | bc -l) -eq 1 ]]
then
echo -e "\e[36m-> SYSTEM LOAD IS TOO HIGH OR MASTER WAS JUST RESTARTED!! SERVER PROCESS EXISTS BUT HAS NOT BEEN CHECKED WITH GAMEDIG!\e[39m"
else
# ugly
ip=$(cat "$mcPath"server.properties | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
port=$(cat "$mcPath"server.properties | grep -oE "\b(query\-port\=)\b(.....)\b" | grep -oE "\b[0-9]{5}\b")
for (( i=1; i<=5; i++ )); do
#echo $ip
#echo $port
#echo "$ip":"$port"
gamedig --type minecraft "$ip":"$port" | grep "Failed all"
if [ $? -ne 0 ]; # succeeded!
then
echo -e "\e[32m$mcEntry \e[39mfunctional."
break
else
echo -e "\e[33m$mcEntry not responding. \e[39mRechecking..."
sleep 5
fi
if [ $i -eq 5 ]
then
echo -e "\e[31m$mcEntry down! \e[39mRestarting..."
tmux kill-session -t $mcEntry ; tmux new-session -d -s $mcEntry ;
tmux send-keys -t $mcEntry cd ' ' "$mcPath" ENTER
tmux send-keys -t $mcEntry "$mcPath"mc.sh ENTER
fi
done
fi
fi
done