institute better timeouts for metadata wgets, LP: #1564320

This commit is contained in:
Dustin Kirkland 2016-04-07 16:39:51 -05:00
commit 430349ff05
5 changed files with 9 additions and 9 deletions

1
debian/changelog vendored
View file

@ -14,6 +14,7 @@ byobu (5.105) unreleased; urgency=medium
- fix color comment - fix color comment
* usr/bin/byobu-janitor.in: * usr/bin/byobu-janitor.in:
- no longer default to enabling ec2 status, LP: #1564320 - no longer default to enabling ec2 status, LP: #1564320
- institute better timeouts for metadata wgets, LP: #1564320
[ Mark King ] [ Mark King ]
* usr/lib/byobu/battery: * usr/lib/byobu/battery:

View file

@ -37,11 +37,11 @@ __ec2_cost() {
read rate < "$cache.rate" read rate < "$cache.rate"
elif metadata_available; then elif metadata_available; then
# Try to use metadata service # Try to use metadata service
[ -s "$cache.zone" ] || wget -q -O- http://169.254.169.254/latest/meta-data/placement/availability-zone </dev/null >"$cache.zone" 2>/dev/null & [ -s "$cache.zone" ] || timeout 0.2 wget -q -O- http://169.254.169.254/latest/meta-data/placement/availability-zone </dev/null >"$cache.zone" 2>/dev/null &
sleep 0.02 sleep 0.02
[ -s "$cache.zone" ] && read zone < "$cache.zone" [ -s "$cache.zone" ] && read zone < "$cache.zone"
zone=${zone%%[a-z]} zone=${zone%%[a-z]}
[ -s "$cache.type" ] || wget -q -O- http://169.254.169.254/latest/meta-data/instance-type </dev/null >"$cache.type" 2>/dev/null & [ -s "$cache.type" ] || timeout 0.2 wget -q -O- http://169.254.169.254/latest/meta-data/instance-type </dev/null >"$cache.type" 2>/dev/null &
sleep 0.02 sleep 0.02
[ -s "$cache.type" ] && read type < "$cache.type" [ -s "$cache.type" ] && read type < "$cache.type"
$BYOBU_PREFIX/lib/byobu/include/ec2instancespricing.py --type ondemand --filter-region $zone --filter-type $type --filter-os-type linux --format csv | tail -n1 > "$cache.rate" $BYOBU_PREFIX/lib/byobu/include/ec2instancespricing.py --type ondemand --filter-region $zone --filter-type $type --filter-os-type linux --format csv | tail -n1 > "$cache.rate"

View file

@ -25,14 +25,13 @@ __hostname_detail() {
__hostname() { __hostname() {
local h= local h=
h=$(hostname -s 2>/dev/null || hostname)
if metadata_available; then if metadata_available; then
local cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/hostname" local cache="$BYOBU_RUN_DIR/cache.$BYOBU_BACKEND/hostname"
# Background a retrieval of our public hostname # Background a retrieval of our public hostname
wget -q -O- http://169.254.169.254/latest/meta-data/public-hostname </dev/null >"$cache" 2>/dev/null & timeout 0.2 wget -q -O- http://169.254.169.254/latest/meta-data/public-hostname </dev/null >"$cache" 2>/dev/null &
sleep 0.02 sleep 0.02
[ -s "$cache" ] && read h < "$cache" [ -s "$cache" ] && read h < "$cache"
else
h=$(hostname -s 2>/dev/null || hostname)
fi fi
[ -n "$h" ] || return [ -n "$h" ] || return
color bold2; printf "%s" "$h"; color -- color bold2; printf "%s" "$h"; color --

View file

@ -218,7 +218,7 @@ metadata_available() {
# Must seed the cache # Must seed the cache
if [ -e /etc/ec2_version ] || [ -e /usr/sbin/update-grub-legacy-ec2 ]; then if [ -e /etc/ec2_version ] || [ -e /usr/sbin/update-grub-legacy-ec2 ]; then
# This *looks* like a machine with metadata, so background a potentially slow check # This *looks* like a machine with metadata, so background a potentially slow check
wget -q -O- --timeout=10 --tries=1 http://169.254.169.254 </dev/null >"$cache" 2>/dev/null & timeout 1 wget -q -O- --tries=1 http://169.254.169.254 </dev/null >"$cache" 2>/dev/null &
sleep 0.02 sleep 0.02
[ -s "$cache" ] && x=1 [ -s "$cache" ] && x=1
fi fi

View file

@ -42,7 +42,7 @@ __ip_address() {
1|true|yes) 1|true|yes)
if [ "$IP_EXTERNAL" = "1" ]; then if [ "$IP_EXTERNAL" = "1" ]; then
# Background an update # Background an update
wget -q -O- http://v6.ipv6-test.com/api/myip.php </dev/null >"$cache" 2>/dev/null & timeout 1 wget -q -O- http://v6.ipv6-test.com/api/myip.php </dev/null >"$cache" 2>/dev/null &
sleep 0.02 sleep 0.02
else else
# Background an update # Background an update
@ -61,12 +61,12 @@ __ip_address() {
;; ;;
*) *)
if [ "$IP_EXTERNAL" = "1" ]; then if [ "$IP_EXTERNAL" = "1" ]; then
wget -q -O- http://v4.ipv6-test.com/api/myip.php </dev/null >"$cache" 2>/dev/null & timeout 1 wget -q -O- http://v4.ipv6-test.com/api/myip.php </dev/null >"$cache" 2>/dev/null &
sleep 0.02 sleep 0.02
[ -s "$cache" ] && read ipaddr < "$cache" [ -s "$cache" ] && read ipaddr < "$cache"
elif metadata_available; then elif metadata_available; then
# We're in EC2, so get our public IP address # We're in EC2, so get our public IP address
wget -q -O- http://169.254.169.254/latest/meta-data/public-ipv4 </dev/null >"$cache" 2>/dev/null & timeout 0.2 wget -q -O- http://169.254.169.254/latest/meta-data/public-ipv4 </dev/null >"$cache" 2>/dev/null &
sleep 0.02 sleep 0.02
[ -s "$cache" ] && read ipaddr < "$cache" [ -s "$cache" ] && read ipaddr < "$cache"
else else