summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-03-04 14:46:01 -0500
committerScott Moser <smoser@ubuntu.com>2013-03-04 14:46:01 -0500
commit2a64b4e7a702933ec5e5a726155cc7acbe4d8144 (patch)
tree4f9636df527ae904a54d1a082049cf3acf93f556
parent7ec5f0fcce2dad57e7f336264a50b000eeec3ed0 (diff)
parentbcf04395be323c60b013e531ef3bf32b722a780a (diff)
downloadvyos-cloud-init-2a64b4e7a702933ec5e5a726155cc7acbe4d8144.tar.gz
vyos-cloud-init-2a64b4e7a702933ec5e5a726155cc7acbe4d8144.zip
upstart/cloud-init-nonet.conf: handle SIGTERM gracefully
this fixes a confusing message, most commonly found in /var/log/dmesg or seen on log screens: init: cloud-init-nonet main process (307) killed by TERM signal This was actually *expected* as the upstart job was supposed to block until networking came up, and the SIGTERM was sent by upstart. That said, the message was confusing. Now, instead we will see something like cloud-init-nonet[6.54]: waiting 10 seconds for network device cloud-init-nonet[12.13]: static networking is now up Which is much nicer. In the event that networking does not come up you'll see: cloud-init-nonet[X.Y]: gave up waiting for a network device. LP: #1015223
-rw-r--r--ChangeLog2
-rw-r--r--upstart/cloud-init-nonet.conf58
2 files changed, 49 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index fcde14fc..110cdec2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -502,4 +502,6 @@
- do not require public key if private is given in ssh cloud-config
(LP: #648905)
- fix issue when writing ssh keys to .ssh/authorized_keys (LP: #1136343)
+ - upstart: cloud-init-nonet.conf trap the TERM signal, so that dmesg or other
+ output does not get a 'killed by TERM signal' message.
# vi: syntax=text textwidth=79
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