-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcorruption.sh
More file actions
56 lines (55 loc) · 2.24 KB
/
corruption.sh
File metadata and controls
56 lines (55 loc) · 2.24 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
#!/usr/bin/env bash
CONFIG_DIR=${CONFIG_DIR:-$COIN}
CFG_FILE=/root/blockchaincfg.json
CF_LOGS=/root/corrupion_events.log
#echo -e "| Awaiting for Blockbook build..."
#echo -e "| CONFIG_DIR: $CONFIG_DIR"
while true; do
if [[ -f $CFG_FILE && -f $HOME/blockbook/blockbook ]]; then
sleep 240
break
fi
sleep 30
done
echo -e "------------------------------------------ [$(date '+%Y-%m-%d %H:%M:%S')][START]"
echo -e "| Checking blockbook logs...."
if [[ -f /root/blockbook.log ]]; then
WALs_CHECK=$(grep -ao "rocksDB: Corruption" /root/blockbook.log)
if [[ "$WALs_CHECK" != "" ]]; then
echo "[$(date "+%d/%m/%y %H:%M:%S %Z %z")] - BlockBook Corruption detected" >> $CF_LOGS
echo -e "| RocksDB Corruption detected!..."
echo -e "| Stopping blockbook service..."
supervisorctl stop blockbook > /dev/null 2>&1
echo -e "| Removing old log file..."
rm -rf /root/blockbook.log
echo -e "| Clean the database..."
rm -rf /root/blockbook-db/*
#./opt/blockbook/blockbook -repair -datadir=/root/blockbook-db
echo -e "| Starting blockbook service..."
supervisorctl start blockbook > /dev/null 2>&1
else
echo -e "| Corruption NOT detected, all looks fine ;)"
fi
else
echo -e "| File does not exists, operation aborted...."
fi
echo -e "----------------------------------------------------------------"
echo -e "| Checking backend logs...."
if [[ -f /root/$CONFIG_DIR/backend/debug.log ]]; then
corruption=$(egrep -ao "Corrupted|Corruption|ERROR: VerifyDB|printcrashinfo|ERROR: invalid header received|InvalidChainFound: invalid" /root/$CONFIG_DIR/backend/debug.log)
if [[ "$corruption" != "" ]]; then
echo "[$(date "+%d/%m/%y %H:%M:%S %Z %z")] - Backend Corruption detected" >> $CF_LOGS
echo -e "| Backend Corruption detected!..."
echo -e "| Stopping backend service..."
supervisorctl stop daemon > /dev/null 2>&1
echo -e "| Removing backend directory contents..."
rm -rf /root/$CONFIG_DIR/backend/*
echo -e "| Starting backend service..."
supervisorctl start daemon > /dev/null 2>&1
else
echo -e "| Corruption NOT detected, all looks fine ;)"
fi
else
echo -e "| File does not exists, operation aborted...."
fi
echo -e "----------------------------------------------------------------[END]"