Skip to content

Commit b12772d

Browse files
committed
Merge pull request #4381 from aledbf/check-etcd-before-firewall
fix(firewall): check etcd is running
2 parents 404889c + 2b012ea commit b12772d

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

contrib/util/custom-firewall.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
#!/bin/env bash
22

3+
if [ ! -f /opt/bin/jq ]; then
4+
echo "/opt/bin/jq is missing. Downloading..."
5+
curl -sSL -o /opt/bin/jq http://stedolan.github.io/jq/download/linux64/jq
6+
chmod +x /opt/bin/jq
7+
fi
8+
9+
# obtain the etcd node members and check that at least there is three
10+
ETCD_NODES=$(curl -s http://localhost:4001/v2/members | jq '.[] | .[].peerURLs | length' | wc -l)
11+
if test $ETCD_NODES -lt 3; then
12+
echo "etcd is not working correctly. Verify the etcd cluster is running before the execution of this script."
13+
fi
14+
315
echo "Obtaining IP addresses of the nodes in the cluster..."
416
MACHINES_IP=$(fleetctl list-machines --fields=ip --no-legend | awk -vORS=, '{ print $1 }' | sed 's/,$/\n/')
517

@@ -59,7 +71,7 @@ echo "Enabling iptables service"
5971
sudo systemctl enable iptables-restore.service
6072

6173
# Flush custom rules before the restore (so this script is idempotent)
62-
sudo /usr/sbin/iptables -F Firewall-INPUT
74+
sudo /usr/sbin/iptables -F Firewall-INPUT 2> /dev/null
6375

6476
echo "Loading custom iptables firewall"
6577
sudo /sbin/iptables-restore --noflush /var/lib/iptables/rules-save

0 commit comments

Comments
 (0)