-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_consensus_legacy.sh
64 lines (58 loc) · 2.19 KB
/
check_consensus_legacy.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
## Version 0.9.5.1
#!/bin/bash
## Check for config file
CONFIG_FILE="config.json"
## Read config file
CONFIGFILE=$(cat "$CONFIG_FILE")
SECRET=$( echo "$CONFIGFILE" | jq -r '.secret')
SRV1=$( echo "$CONFIGFILE" | jq -r '.srv1')
PRT=$( echo "$CONFIGFILE" | jq -r '.port')
PRTS=$( echo "$CONFIGFILE" | jq -r '.https_port')
SERVERS=()
### Get servers array
size=$( echo "$CONFIGFILE" | jq '.servers | length')
i=0
while [ $i -le "$size" ]
do
SERVERS[$i]=$(echo "$CONFIGFILE" | jq -r --argjson i $i '.servers[$i]')
i=$((i + 1))
done
###
#########################
# Set colors
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
CYAN=$(tput setaf 6)
RESETCOLOR=$(tput sgr0)
## Log start of script
date +"%Y-%m-%d %H:%M:%S || ${GREEN}Starting MrV's legacy consensus script${RESETCOLOR}"
while true; do
## Get recent log
INADEQUATE=$(tail ~/onz/logs/onz.log -n 2| grep 'Inadequate')
if [ -n "$INADEQUATE" ];
then
date +"%Y-%m-%d %H:%M:%S || ${RED}WARNING: Inadequate consensus to forge.${RESETCOLOR}"
## Disable forging on local server first. If successful, loop through servers until we are able to enable forging on one
DISABLEFORGE=$(curl -s -S --connect-timeout 1 --retry 3 --retry-delay 0 --retry-max-time 3 -k -H "Content-Type: application/json" -X POST -d '{"secret":"'"$SECRET"'"}' https://"$SRV1""$PRTS"/api/delegates/forging/disable | jq '.success')
if [ "$DISABLEFORGE" = "true" ];
then
for SERVER in "${SERVERS[@]}"
do
ENABLEFORGE=$(curl -s -S --connect-timeout 1 --retry 2 --retry-delay 0 --retry-max-time 2 -k -H "Content-Type: application/json" -X POST -d '{"secret":"'"$SECRET"'"}' https://"$SERVER""$PRTS"/api/delegates/forging/enable | jq '.success')
if [ "$ENABLEFORGE" = "true" ];
then
date +"%Y-%m-%d %H:%M:%S || ${CYAN}Successsfully switching to Server $SERVER to try and forge.${RESETCOLOR}"
sleep 10
break ## Leave servers loop
else
date +"%Y-%m-%d %H:%M:%S || ${RED}Failed to enable forging on $SERVER. Trying next server.${RESETCOLOR}"
fi
done
else
date +"%Y-%m-%d %H:%M:%S || ${RED}Failed to disable forging on $SRV1.${RESETCOLOR}"
fi
fi
date +"%Y-%m-%d %H:%M:%S || ${GREEN}Everything is Okay.${RESETCOLOR}"
sleep 1
done