From 00d853e5fde8fe5549177bad7957be5f9699f63c Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Wed, 19 Mar 2014 14:33:14 -0400 Subject: [PATCH] DHCP: make udev rules want dhcp-interface@.service Updates the dhcp-all-interfaces element to fix a race with the recent udev rules implementation on Fedora. With the new approach we make the udev rule want (require to startup) a generic dhcp-interface@.service template which can be started individually for each interface that is discovered. The dhcp-interface@.service is setup such that it: 1) It calls dhcp-all-interfaces directly with a pre-exec script. This creates the ifcfg file right before we need it but avoids the case where network.service might get greedy and try to start it itself. 2) Only runs if the ifcfg script doesn't already exist. This is important because we only need to bootstrap the DHCP configs... Once they exist the network.service will take care of starting them on reboots, upgrades, etc. 3) On initial boot ensure that the initial DHCP interfaces come up after network.service. Since we really only want dhcp-all-interfaces to help bootstrap that haven't already been configured this seems reasonable. 4) We also try to ensure that cloud-init comes up after the DHCP interfaces. Cloud init has a decently long timeout that this wasn't a functional problem but it keeps log file spew down. Change-Id: I71b026f027182aad49c3435bb903e5e38e524685 Closes-bug: #1294803 --- .../install.d/50-dhcp-all-interfaces | 1 + .../install.d/dhcp-interface@.service | 15 +++++++++++++++ elements/dhcp-all-interfaces/install.d/udev.rules | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 elements/dhcp-all-interfaces/install.d/dhcp-interface@.service diff --git a/elements/dhcp-all-interfaces/install.d/50-dhcp-all-interfaces b/elements/dhcp-all-interfaces/install.d/50-dhcp-all-interfaces index 06098735..32f6f4be 100755 --- a/elements/dhcp-all-interfaces/install.d/50-dhcp-all-interfaces +++ b/elements/dhcp-all-interfaces/install.d/50-dhcp-all-interfaces @@ -9,5 +9,6 @@ DIB_INIT_SYSTEM=$(dib-init-system) if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then install -D -g root -o root -m 0755 ${SCRIPTDIR}/dhcp-all-interfaces.conf /etc/init/dhcp-all-interfaces.conf elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then + install -D -g root -o root -m 0755 ${SCRIPTDIR}/dhcp-interface@.service /usr/lib/systemd/system/dhcp-interface@.service install -D -g root -o root -m 0644 ${SCRIPTDIR}/udev.rules /etc/udev/rules.d/99-dhcp-all-interfaces.rules fi diff --git a/elements/dhcp-all-interfaces/install.d/dhcp-interface@.service b/elements/dhcp-all-interfaces/install.d/dhcp-interface@.service new file mode 100644 index 00000000..e2643c85 --- /dev/null +++ b/elements/dhcp-all-interfaces/install.d/dhcp-interface@.service @@ -0,0 +1,15 @@ +[Unit] +Description=DHCP interface %I +After=network.service network.target + +ConditionPathExists=!/etc/sysconfig/network-scripts/ifcfg-%I + +[Service] +Type=oneshot +User=root +ExecStartPre=/usr/local/sbin/dhcp-all-interfaces.sh %I +ExecStart=/sbin/ifup %I +RemainAfterExit=true + +[Install] +WantedBy=multi-user.target diff --git a/elements/dhcp-all-interfaces/install.d/udev.rules b/elements/dhcp-all-interfaces/install.d/udev.rules index 88ce3e13..302f41ba 100644 --- a/elements/dhcp-all-interfaces/install.d/udev.rules +++ b/elements/dhcp-all-interfaces/install.d/udev.rules @@ -1 +1 @@ -SUBSYSTEM=="net", ACTION=="add", RUN+="/usr/local/sbin/dhcp-all-interfaces.sh $name", RUN+="/sbin/ifup $name" +SUBSYSTEM=="net", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="dhcp-interface@$name.service"