-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathforce-sync-loop.sh
executable file
·69 lines (59 loc) · 1.83 KB
/
force-sync-loop.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
#!/bin/bash
API_KEY=$(cat ~/qortal/apikey.txt)
if [ "$#" -ne 2 ]; then
echo "Usage: $0 [1|2] <node>"
exit 1
fi
OPTION=$1
NODE=$2
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
case $OPTION in
1)
while true; do
log "Deleting known peers"
./qort DELETE peers/known
sleep 3
log "Adding peer: $NODE"
./qort peers "$NODE"
sleep 3
for i in {1..15}; do
log "Forcing sync with: $NODE (attempt $i)"
./qort admin/forcesync "$NODE"
RESPONSE=$(curl -s -X POST localhost:12391/admin/forcesync -H "X-API-KEY:$API_KEY" -d "$NODE")
if [[ "$RESPONSE" == *"true"* ]]; then
log "Sync successful, sleeping for 1 hour"
sleep 3600
break
fi
sleep 3
done
done
;;
2)
while true; do
log "Deleting known peers via curl"
curl -X DELETE localhost:12391/peers/known -H "X-API-KEY:$API_KEY"
sleep 3
log "Adding peer via curl: $NODE"
curl -X POST localhost:12391/peers -H "X-API-KEY:$API_KEY" -d "$NODE"
sleep 3
for i in {1..15}; do
log "Forcing sync via curl with: $NODE (attempt $i)"
curl -X POST localhost:12391/admin/forcesync -H "X-API-KEY:$API_KEY" -d "$NODE"
RESPONSE=$?
if [[ "$RESPONSE" == *"true"* ]]; then
log "Sync successful, sleeping for 1 hour"
sleep 3600
break
fi
sleep 3
done
done
;;
*)
echo "Invalid option. Use 1 for qort script method or 2 for curl method."
exit 1
;;
esac