diff options
author | Scott Moser <smoser@ubuntu.com> | 2013-03-07 16:27:47 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2013-03-07 16:27:47 -0500 |
commit | 3199df6e1489da03d51ac8a2a4574c27fd325189 (patch) | |
tree | 921700212c063d1b468a8ea2cac4f7df0f3a68d9 /upstart | |
parent | 21aec9e44c27b9bf1c96314f0449fd39793d1c73 (diff) | |
parent | 8013c284e82349246b2274f5475c138323fd7c55 (diff) | |
download | vyos-cloud-init-3199df6e1489da03d51ac8a2a4574c27fd325189.tar.gz vyos-cloud-init-3199df6e1489da03d51ac8a2a4574c27fd325189.zip |
merge from trunk
Diffstat (limited to 'upstart')
-rw-r--r-- | upstart/cloud-init-container.conf | 6 | ||||
-rw-r--r-- | upstart/cloud-init-nonet.conf | 58 |
2 files changed, 53 insertions, 11 deletions
diff --git a/upstart/cloud-init-container.conf b/upstart/cloud-init-container.conf index 051c6e50..6bdbe77e 100644 --- a/upstart/cloud-init-container.conf +++ b/upstart/cloud-init-container.conf @@ -21,6 +21,12 @@ script # if the all static network interfaces are already up, nothing to do [ -f "$MARK_STATIC_NETWORK_EMITTED" ] && exit 0 + # ifquery will exit failure if there is no /run/network directory. + # normally that would get created by one of network-interface.conf + # or networking.conf. But, it is possible that we're running + # before either of those have. + mkdir -p /run/network + # get list of all 'auto' interfaces. if there are none, nothing to do. auto_list=$(ifquery --list --allow auto 2>/dev/null) || : [ -z "$auto_list" ] && exit 0 diff --git a/upstart/cloud-init-nonet.conf b/upstart/cloud-init-nonet.conf index 118ffc1c..36b99fb5 100644 --- a/upstart/cloud-init-nonet.conf +++ b/upstart/cloud-init-nonet.conf @@ -10,19 +10,55 @@ 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() { + local uptime="" idle="" + if [ -r /proc/uptime ]; then + read uptime idle < /proc/uptime + fi + echo "$UPSTART_JOB${uptime:+[${uptime}]}:" "$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 + msg "recieved SIGTERM, networking not up" + 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 |