From 1a3e0fa19b6c3224ea986141b37f74d5464b7c82 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 4 Mar 2013 09:56:24 -0500 Subject: if sigterm received, and networking is up, exit 0 LP: #1015223 --- upstart/cloud-init-nonet.conf | 53 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'upstart/cloud-init-nonet.conf') diff --git a/upstart/cloud-init-nonet.conf b/upstart/cloud-init-nonet.conf index 118ffc1c..bdeb5a2e 100644 --- a/upstart/cloud-init-nonet.conf +++ b/upstart/cloud-init-nonet.conf @@ -10,19 +10,50 @@ task console output script - # /run/network/static-network-up-emitted is written by - # upstart (via /etc/network/if-up.d/upstart). its presense would - # indicate that static-network-up has already fired. - EMITTED="/run/network/static-network-up-emitted" - [ -e "$EMITTED" -o -e "/var/$EMITTED" ] && exit 0 + set +e # you cannot trap TERM reliably with 'set -e' + SLEEP_CHILD="" + static_network_up() { + local emitted="/run/network/static-network-up-emitted" + # /run/network/static-network-up-emitted is written by + # upstart (via /etc/network/if-up.d/upstart). its presense would + # indicate that static-network-up has already fired. + [ -e "$emitted" -o -e "/var/$emitted" ] + } + msg() { + echo "$UPSTART_JOB:" "$1" + } + + handle_sigterm() { + # if we received sigterm and static networking is up then it probably + # came from upstart as a result of 'stop on static-network-up' + [ -z "$SLEEP_CHILD" ] || kill $SLEEP_CHILD + if static_network_up; then + msg "static networking is now up" + exit 0 + fi + exit 2 + } + + dowait() { + msg "waiting $1 seconds for network device" + sleep "$1" & + SLEEP_CHILD=$! + wait $SLEEP_CHILD + SLEEP_CHILD="" + } + + trap handle_sigterm TERM + + # static_network_up already occurred + static_network_up && exit 0 + + # obj.pkl comes from cloud-init-local (or previous boot and + # manual_cache_clean) [ -f /var/lib/cloud/instance/obj.pkl ] && exit 0 - short=10; long=120; - sleep ${short} - echo $UPSTART_JOB "waiting ${long} seconds for a network device." - sleep ${long} - echo $UPSTART_JOB "gave up waiting for a network device." + dowait 10 + dowait 120 + msg "gave up waiting for a network device." : > /var/lib/cloud/data/no-net end script -# EOF -- cgit v1.2.3