forked from RunOnFlux/blockbook-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorruption.sh
51 lines (49 loc) · 1.96 KB
/
corruption.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
#!/usr/bin/env bash
CONFIG_DIR=${CONFIG_DIR:-$COIN}
CFG_FILE=/root/blockchaincfg.json
echo -e "| Awaiting for Blockbook build..."
while true; do
if [[ -f $CFG_FILE && -f $HOME/blockbook/blockbook ]]; then
sleep 300
break
fi
sleep 20
done
if [[ -f /root/blockbook.log ]]; then
echo -e "------------------------------------------ [$(date '+%Y-%m-%d %H:%M:%S')][START]"
echo -e "| Checking blockbook logs...."
WALs_CHECK=$(grep -ao "rocksDB: Corruption" /root/blockbook.log)
if [[ "$WALs_CHECK" != "" ]]; then
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 "| Repair the database..."
# ./opt/blockbook/blockbook -repair -datadir=/root/blockbook-db
echo -e "| Removing blockbook directory..."
rm -rf /root/$CONFIG_DIR/backend/*
echo -e "| Starting blockbook service..."
supervisorctl start blockbook > /dev/null 2>&1
else
echo -e "| Corruption NOT detected, all looks fine ;)"
fi
echo -e "----------------------------------------------------------------[END]"
fi
if [[ -f /root/$CONFIG_DIR/backend/debug.log ]]; then
echo -e "------------------------------------------ [$(date '+%Y-%m-%d %H:%M:%S')][START]"
echo -e "| Checking backend logs...."
corruption=$(grep -ao "Corrupted block database detected" /root/$CONFIG_DIR/backend/debug.log)
if [[ "$corruption" != "" ]]; then
echo -e "| Backend corruption detected!..."
echo -e "| Stopping backend service..."
supervisorctl stop backend > /dev/null 2>&1
echo -e "| Removing backend directory contents..."
rm -rf /root/$CONFIG_DIR/backend/*
echo -e "| Starting backend service..."
supervisorctl start backend > /dev/null 2>&1
else
echo -e "| Corruption NOT detected, all looks fine ;)"
fi
echo -e "----------------------------------------------------------------[END]"
fi