sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init a year ago
Clone
212f0f
From 9969cf3eaa23398816d140b319b3277465aa4bb8 Mon Sep 17 00:00:00 2001
212f0f
From: Eduardo Otubo <otubo@redhat.com>
212f0f
Date: Fri, 6 Sep 2019 12:12:11 +0200
212f0f
Subject: [PATCH] Fix for network configuration not persisting after reboot
212f0f
212f0f
RH-Author: Eduardo Otubo <otubo@redhat.com>
212f0f
Message-id: <20190906121211.23172-1-otubo@redhat.com>
212f0f
Patchwork-id: 90300
212f0f
O-Subject: [RHEL-7.8/RHEL-8.1.0 cloud-init PATCH] Fix for network configuration not persisting after reboot
212f0f
Bugzilla: 1593010
212f0f
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
212f0f
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
212f0f
212f0f
The reasons the configuration does not persist after reboot includes
212f0f
different aspects and they're all fixed on this patch:
212f0f
212f0f
  1) The rpm package doesn't include the systemd-generator and
212f0f
ds-identify. The systemd-generator is called early in the boot process
212f0f
that calls ds-identify to check if there's any Data Source available in
212f0f
the current boot. In the current use case, the Data Source is removed
212f0f
from the VM on the second boot, this means cloud-init should disable
212f0f
itself in order to keep the configuration it did in the first boot.
212f0f
212f0f
  2) Even after adding those scripts, cloud-init was still being
212f0f
executed and the configurations were being lost. The reason for this is
212f0f
that the cloud-init systemd units had a wrong dependency
212f0f
212f0f
     WantedBy: multi-user.target
212f0f
212f0f
     Which would start them every time no matter the return of
212f0f
ds-identify. The fix is to replace the dependency by the systemd unit to
212f0f
cloud-init.target, which is the main cloud-init target enabled - or in
212f0f
this case, disabled by ds-identify. The file cloud-init.target was also
212f0f
missing on rpm package.
212f0f
212f0f
After adding both scripts, the main cloud-init systemd target and
212f0f
adjusting the systemd dependencies the configuration persists after
212f0f
reboots and shutdowns.
212f0f
212f0f
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
212f0f
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
212f0f
---
212f0f
 redhat/cloud-init.spec.template       | 15 +++++++++++++++
212f0f
 rhel/systemd/cloud-config.service     |  2 +-
212f0f
 rhel/systemd/cloud-final.service      |  2 +-
212f0f
 rhel/systemd/cloud-init-local.service |  2 +-
212f0f
 rhel/systemd/cloud-init.service       |  2 +-
212f0f
 rhel/systemd/cloud-init.target        |  7 +++++++
212f0f
 6 files changed, 26 insertions(+), 4 deletions(-)
212f0f
 create mode 100644 rhel/systemd/cloud-init.target
212f0f
212f0f
diff --git a/rhel/systemd/cloud-config.service b/rhel/systemd/cloud-config.service
212f0f
index 12ca9df..f3dcd4b 100644
212f0f
--- a/rhel/systemd/cloud-config.service
212f0f
+++ b/rhel/systemd/cloud-config.service
212f0f
@@ -15,4 +15,4 @@ TimeoutSec=0
212f0f
 StandardOutput=journal+console
212f0f
 
212f0f
 [Install]
212f0f
-WantedBy=multi-user.target
212f0f
+WantedBy=cloud-init.target
212f0f
diff --git a/rhel/systemd/cloud-final.service b/rhel/systemd/cloud-final.service
212f0f
index 32a83d8..739b7e3 100644
212f0f
--- a/rhel/systemd/cloud-final.service
212f0f
+++ b/rhel/systemd/cloud-final.service
212f0f
@@ -16,4 +16,4 @@ KillMode=process
212f0f
 StandardOutput=journal+console
212f0f
 
212f0f
 [Install]
212f0f
-WantedBy=multi-user.target
212f0f
+WantedBy=cloud-init.target
212f0f
diff --git a/rhel/systemd/cloud-init-local.service b/rhel/systemd/cloud-init-local.service
212f0f
index 656eddb..8f9f6c9 100644
212f0f
--- a/rhel/systemd/cloud-init-local.service
212f0f
+++ b/rhel/systemd/cloud-init-local.service
212f0f
@@ -28,4 +28,4 @@ TimeoutSec=0
212f0f
 StandardOutput=journal+console
212f0f
 
212f0f
 [Install]
212f0f
-WantedBy=multi-user.target
212f0f
+WantedBy=cloud-init.target
212f0f
diff --git a/rhel/systemd/cloud-init.service b/rhel/systemd/cloud-init.service
212f0f
index 68fc5f1..d0023a0 100644
212f0f
--- a/rhel/systemd/cloud-init.service
212f0f
+++ b/rhel/systemd/cloud-init.service
212f0f
@@ -22,4 +22,4 @@ TimeoutSec=0
212f0f
 StandardOutput=journal+console
212f0f
 
212f0f
 [Install]
212f0f
-WantedBy=multi-user.target
212f0f
+WantedBy=cloud-init.target
212f0f
diff --git a/rhel/systemd/cloud-init.target b/rhel/systemd/cloud-init.target
212f0f
new file mode 100644
212f0f
index 0000000..083c3b6
212f0f
--- /dev/null
212f0f
+++ b/rhel/systemd/cloud-init.target
212f0f
@@ -0,0 +1,7 @@
212f0f
+# cloud-init target is enabled by cloud-init-generator
212f0f
+# To disable it you can either:
212f0f
+#  a.) boot with kernel cmdline of 'cloud-init=disabled'
212f0f
+#  b.) touch a file /etc/cloud/cloud-init.disabled
212f0f
+[Unit]
212f0f
+Description=Cloud-init target
212f0f
+After=multi-user.target
212f0f
-- 
212f0f
1.8.3.1
212f0f