-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check whether orderer is a RAFT leader before starting app
- Loading branch information
Tony Wu
committed
Sep 6, 2023
1 parent
f4a9209
commit 6b53bb5
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
FROM eclipse-temurin:11-jre-focal | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y curl \ | ||
&& rm -rf /var/lib/apt/lists/* # Clean up to reduce image size | ||
|
||
WORKDIR /app | ||
|
||
COPY build/install/blocc-temp-humidity-app/ . | ||
COPY scripts/raft-leader-check.sh . | ||
|
||
ENTRYPOINT ["./bin/blocc-temp-humidity-app"] | ||
ENTRYPOINT ["./raft-leader-check.sh "] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
retries=20 | ||
|
||
while [[ $retries -gt 0 ]]; do | ||
curl -s http://${FABRIC_ORDERER_ADDRESS}/metrics > /tmp/orderer_metrics 2> /dev/null | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "Failed to fetch metrics from orderer. Retrying..." | ||
((retries--)) | ||
sleep 3 | ||
continue | ||
fi | ||
|
||
STATUS=$(grep 'consensus_etcdraft_is_leader' /tmp/orderer_metrics | grep -o '[0-1]$') | ||
|
||
if [ "$STATUS" == "1" ]; then | ||
echo "Orderer is RAFT leader. Starting blocc-temp-humidity-app..." | ||
./bin/blocc-temp-humidity-app # Start the app here | ||
break | ||
else | ||
echo "Orderer is not RAFT leader. Retrying..." | ||
((retries--)) | ||
sleep 3 | ||
fi | ||
done | ||
|
||
if [[ $retries -eq 0 ]]; then | ||
echo "Failed to confirm RAFT leader status after several attempts." | ||
exit 1 | ||
fi |