cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #03762
[Merge] ~smoser/cloud-init:bug/1732964-kill-dhclient-on-ec2 into cloud-init:master
Scott Moser has proposed merging ~smoser/cloud-init:bug/1732964-kill-dhclient-on-ec2 into cloud-init:master.
Commit message:
EC2: Kill dhclient process used in sandbox dhclient.
dhclient runs, obtains a address and then backgrounds itself.
cloud-init did not take care to kill it after it was done with it.
After it has run and created the leases, we can kill it.
LP: #1732964
Requested reviews:
cloud-init commiters (cloud-init-dev)
Related bugs:
Bug #1732964 in cloud-init: "dhclient process started by cloud-init-local.service still running afterwards"
https://bugs.launchpad.net/cloud-init/+bug/1732964
For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/333905
--
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:bug/1732964-kill-dhclient-on-ec2 into cloud-init:master.
diff --git a/cloudinit/net/dhcp.py b/cloudinit/net/dhcp.py
index 0cba703..f3a412a 100644
--- a/cloudinit/net/dhcp.py
+++ b/cloudinit/net/dhcp.py
@@ -8,6 +8,7 @@ import configobj
import logging
import os
import re
+import signal
from cloudinit.net import find_fallback_nic, get_devicelist
from cloudinit import temp_utils
@@ -119,7 +120,13 @@ def dhcp_discovery(dhclient_cmd_path, interface, cleandir):
cmd = [sandbox_dhclient_cmd, '-1', '-v', '-lf', lease_file,
'-pf', pid_file, interface, '-sf', '/bin/true']
util.subp(cmd, capture=True)
- return parse_dhcp_lease_file(lease_file)
+ pid = None
+ try:
+ pid = int(util.load_file(pid_file).strip())
+ return parse_dhcp_lease_file(lease_file)
+ finally:
+ if pid:
+ os.kill(pid, signal.SIGKILL)
def networkd_parse_lease(content):
References