From 5aa09d5afecb195692ed7cfc870d584cec2c0d95 Mon Sep 17 00:00:00 2001 From: Steve Lewis Date: Mon, 30 Mar 2015 13:07:23 -0700 Subject: [PATCH] Ensure LXC bridge exists, is up, and has rules Additional check to ensure the lxc bridge interface exists added when starting networks. Additional edge cases in the bridge being created and the interface made usable are tested and resolved when they fail. In addition dnsmasq is only kicked when the container network is modified. Co-Authored-By: Kevin Carter Change-Id: I7350626bd736f815bd2a9ed0d4949d42cd5db9af Closes-Bug: 1438374 --- .../lxc_hosts/templates/lxc-system-manage.j2 | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/playbooks/roles/lxc_hosts/templates/lxc-system-manage.j2 b/playbooks/roles/lxc_hosts/templates/lxc-system-manage.j2 index 74438508d5..b191852fef 100644 --- a/playbooks/roles/lxc_hosts/templates/lxc-system-manage.j2 +++ b/playbooks/roles/lxc_hosts/templates/lxc-system-manage.j2 @@ -178,28 +178,34 @@ function stop_containers_with_fire() { function start_networks() { set -e - info "Building the LXC container network." + if [ -f "/sys/class/net/${LXC_BRIDGE}/bridge/bridge_id" ];then + success "LXC container network is already online." + else + if [ ! "$(ifup ${LXC_BRIDGE})" ];then + info "Building the LXC container network." - # Create lxc bridge - brctl addbr "${LXC_BRIDGE}" + # Create lxc bridge + brctl addbr "${LXC_BRIDGE}" || true - # Set the lxc bridge up - ip link set "${LXC_BRIDGE}" up || true + # Set the lxc bridge up + ip link set "${LXC_BRIDGE}" up || true - # Assign an address to the lxc bridge - ip addr add "${LXC_ADDR}"/"${LXC_NETMASK}" dev "${LXC_BRIDGE}" + # Assign an address to the lxc bridge + ip addr add "${LXC_ADDR}"/"${LXC_NETMASK}" dev "${LXC_BRIDGE}" - add_rules + add_rules - LXC_DOMAIN_ARG="" - if [ -n "$LXC_DOMAIN" ]; then - LXC_DOMAIN_ARG="-s $LXC_DOMAIN -S /$LXC_DOMAIN/" + LXC_DOMAIN_ARG="" + if [ -n "$LXC_DOMAIN" ]; then + LXC_DOMAIN_ARG="-s $LXC_DOMAIN -S /$LXC_DOMAIN/" + fi + + # Start DNS mask + DHCP_LEASE_FILE="/var/lib/misc/dnsmasq.${LXC_BRIDGE}.leases" + start_dnsmasq + success "LXC container network has been created." + fi fi - - # Start DNS mask - DHCP_LEASE_FILE="/var/lib/misc/dnsmasq.${LXC_BRIDGE}.leases" - start_dnsmasq - success "LXC container network has been created." } function stop_dnsmasq() {