forked from mtusi2026/mtusi2026lab4
Grade 4
This commit is contained in:
+9
-3
@@ -5,12 +5,18 @@ update_backends() {
|
||||
: > "$next"
|
||||
for address in $(getent ahostsv4 api | awk '{print $1}' | sort -u); do
|
||||
if wget -q -T 1 -O /dev/null "http://$address:8080/health/ready"; then
|
||||
echo "server $address:8080 max_fails=1 fail_timeout=2s;" >> "$next"
|
||||
echo "server $address:8080;" >> "$next"
|
||||
fi
|
||||
done
|
||||
# An empty upstream is invalid; a down placeholder returns 502 without
|
||||
# sending business requests to an unready API.
|
||||
# If every running API temporarily loses a shared dependency (for example
|
||||
# S3), retain the last addresses. The API can then return the contracted
|
||||
# 503 instead of Nginx replacing it with a 502. At initial startup there
|
||||
# is no previous healthy set, so use an inert placeholder.
|
||||
if [ ! -s "$next" ]; then
|
||||
if [ -s /etc/nginx/ready-backends.conf ] && ! grep -q '127.0.0.1:9 down' /etc/nginx/ready-backends.conf; then
|
||||
rm -f "$next"
|
||||
return
|
||||
fi
|
||||
echo 'server 127.0.0.1:9 down;' > "$next"
|
||||
fi
|
||||
if ! cmp -s "$next" /etc/nginx/ready-backends.conf; then
|
||||
|
||||
Reference in New Issue
Block a user