This repository has been archived by the owner on Jan 15, 2020. It is now read-only.
forked from aionnetwork/aion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aion.sh
executable file
·239 lines (199 loc) · 5.87 KB
/
aion.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
cd "$(dirname $(realpath $0))"
KERVER=$(uname -r | grep -o "^4\.")
if [ "$KERVER" != "4." ]; then
echo "Warning! The linux kernel must be greater than or equal to version 4."
fi
HW=$(uname -m)
if [ "$HW" != "x86_64" ]; then
echo "Warning! Aion blockchain platform must be running on 64 bits architecture"
fi
DIST=$(lsb_release -i | grep -o "Ubuntu")
if [ "$DIST" != "Ubuntu" ]; then
echo "Warning! Aion blockchain is fully compatible with Ubuntu distribution. Your current system is not Ubuntu distribution. It may have some issues."
fi
MAJVER=$(lsb_release -r | grep -o "[0-9][0-9]" | sed -n 1p)
if [ "$MAJVER" -lt "16" ]; then
echo "Warning! Aion blockchain is fully compatible with Ubuntu version 16.04. Your current system is older than Ubuntu 16.04. It may have some issues."
fi
ARG=$@
#if [ "$ARG" == "--close" ]; then
# PID=$(<./tmp/aion.pid)
# kill -2 $PID
# rm -r ./tmp
# exit 0
#fi
# add execute permission to rt
chmod +x ./rt/bin/*
# prepare jvm params
# default to minimum 4gb heap if Xms not set.
JAVA_OPTS="$JAVA_OPTS"
if [[ ! ${JAVA_OPTS} = *"-Xms"* ]]; then
JAVA_OPTS+=" -Xms4g"
fi
# to suppress illegal reflective access warning out of xnio and protobuf
# (we depend on xnio transitively via undertow-core)
JAVA_OPTS+=" --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED"
####### WATCHGUARD IMPLEMENTATION #######
# #
# To kill: ps aux | egrep "aion.sh" #
# #
# Wait - reboot timer condition #
# Sample - kernel checking rate #
# Tolerance - kernel dead condition #
# ThreadRate - thread checking rate #
# (threadRate * sample) #
# #
#########################################
# Enable "watch" as first command line argument
guard=false
if [[ $1 == "watch" ]]; then
first=true
for arg in $@; do
if $first; then
set --
first=false
else
set -- "$@" "$arg"
fi
done
guard=true
fi
if $guard; then
echo "######################"
echo " Watchguard Enabled "
echo "######################"
echo
wait=300 # sec
sample=30 # sec
tolerance=60 # sec
threadRate=2 # rate
noInterrupt=true
countRebounce=0
running=false
watching=false
lastBoot=0
trap "exit" SIGINT SIGTERM
trap "interrupt" EXIT
function interrupt() {
# Interrupts the Aion kernel and awaits shutdown complete
if $running; then
kill $kPID
temp=$(ps --pid $kPID | egrep -o "$kPID")
while [[ $temp -eq $kPID ]] ; do
sleep 2s
temp=$(ps --pid $kPID | egrep -o "$kPID")
done
running=false
watching=false
noInterrupt=false
fi
# Interrupts the watchguard (current process)
kill -9 $$
}
# Keep executing aion kernel until interrupted
while $noInterrupt; do
# Reboot timer
newBoot=$(date +"%s")
let "duration=$newBoot-$lastBoot"
if [[ $duration -lt $wait ]]; then
let "sleep=$wait-$duration"
echo "[Reboot Timer: $sleep]"
sleep $sleep
fi
lastBoot=$newBoot
# Execute Java kernel
env EVMJIT="-cache=1" ./rt/bin/java ${JAVA_OPTS} \
-cp "./lib/*:./lib/libminiupnp/*:./mod/*" org.aion.Aion "$@" &
kPID=$!
running=true
watching=true
checkRate=0
tPrev=0
# Locate logger detail
config=config/config.xml
logging=$(egrep -o "log-file.*log-file" $config | cut -d">" -f2 | cut -d"<" -f1)
logpath=$(egrep -o "log-path.*log-path" $config | cut -d">" -f2 | cut -d"<" -f1)
file=$logpath/aionCurrentLog.dat
# Watchguard
while $watching; do
sleep $sample
# [1] Log timestamp (last 60 sec) OR [2] PID process state ZOMBIE/DEAD
if $logging; then
last=$(stat $file | egrep "Modify\:" | cut -d" " -f3 | cut -d"." -f1)
lastUTC=$(date --date="$last" +"%s")
nowUTC=$(date +"%s")
if [[ $lastUTC -lt $((nowUTC-$tolerance)) ]] || (ps $kPID | cut -c 16-22 | egrep -v "STAT" | egrep -q "Z"); then
echo "## KERNEL DEAD FOR $tolerance SEC ##"
watching=false
fi
fi
# [1] Thread runtime (last 60 sec) AND [2] PID thread state BLOCKED
if [ $checkRate -eq $threadRate ]; then
let "duration=$sample*$threadRate"
temp='p2p-in sync-ib'
threads=($temp)
checkRate=0
for ((i=0; i<${#threads[@]}; ++i)); do
tTime=$(ps --pid $kPID | egrep -o "[0-9]{2}\.[0-9]{2} ${threads[i]}" | cut -d" " -f1)
tState=$(./rt/bin/jstack -l $kPID | egrep -A1 "${threads[i]}" | egrep -o "State.*" | cut -d" " -f2)
if [[ $tTime == ${tPrev[i]} ]] && [[ $tState == "BLOCKED" ]]; then
echo "## ${threads[i]} THREAD DEAD ##"
(./rt/bin/jstack -l $kPID | egrep -A1 "${threads[i]}") > threadDump_$countRebounce.txt
watching=false
fi
tPrev[i]=$tTime
done
else
((checkRate++))
fi
done
# Shutsdown Aion kernel
echo "## Killing Kernel ##"
kill $kPID
timer=0
temp=$(ps --pid $kPID | egrep -o "$kPID")
while [[ $temp -eq $kPID ]] ; do
# If shutdown exceeds 1 minute
((timer+=2))
if [[ $timer -ge 60 ]]; then
kill -9 $kPID
fi
sleep 2s
temp=$(ps --pid $kPID | egrep -o "$kPID")
done
running=false
((countRebounce++))
echo
echo "############################## REBOUNCE COUNT [$countRebounce] ##############################"
done
else
JAVA_CMD=java
if [ -d "./rt" ]; then
JAVA_CMD="./rt/bin/java"
elif [ -d "./pack/rt" ]; then
JAVA_CMD="./pack/rt/bin/java"
elif [ -d "$JAVA_HOME" ]; then
JAVA_CMD="$JAVA_HOME/bin/java"
fi
# if there's CLI args, we just run it and quit
if [ "$#" -gt 0 ]; then
env EVMJIT="-cache=1" $JAVA_CMD ${JAVA_OPTS} \
-cp "./lib/*:./lib/libminiupnp/*:./mod/*" org.aion.Aion "$@"
exit
fi
# otherwise, kernel will start; run it in background
trap "exit" INT TERM
trap "exit_kernel" EXIT
exit_kernel() {
if [ ! -z "$kernel_pid" ]; then
kill "$kernel_pid" &> /dev/null
wait "$kernel_pid" &> /dev/null
fi
exit 1
}
env EVMJIT="-cache=1" $JAVA_CMD ${JAVA_OPTS} \
-cp "./lib/*:./lib/libminiupnp/*:./mod/*" org.aion.Aion "$@" &
kernel_pid=$!
wait
fi