summaryrefslogtreecommitdiff
path: root/upstart/cloud-init-container.conf
blob: b3123721761342d21150ca065dfe8bb07b719588 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# in a lxc container, events for network interfaces do not
# get created or may be missed.  This helps cloud-init-nonet along
# by emitting those events if they have not been emitted.

start on container
stop on static-network-up
task

emits net-device-added

console output

script
   # if we are inside a container, then we may have to emit the ifup
   # events for 'auto' network devices.
   set -f

   # from /etc/network/if-up.d/upstart
   MARK_DEV_PREFIX="/run/network/ifup."
   MARK_STATIC_NETWORK_EMITTED="/run/network/static-network-up-emitted"
   # if the all static network interfaces are already up, nothing to do
   [ -f "$MARK_STATIC_NETWORK_EMITTED" ] && exit 0

   # 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
   set -- ${auto_list}
   [ "$*" = "lo" ] && exit 0

   to_emit=""
   for iface in "$@"; do
      [ "$iface" = "lo" ] && continue
      # skip interfaces that are already up
      [ -f "${MARK_DEV_PREFIX}${iface}" ] && continue
      initctl emit --no-wait net-device-added "INTERFACE=$iface" &&
         emitted="${emitted} ${iface}" || :
   done

   [ -z "${emitted# }" ] ||
      echo "${UPSTART_JOB}: emitted ifup for ${emitted# }"
end script