sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init 10 months ago
Clone
ea00c4
From d3889c4645a1319c3d677006164b618ee53f4c8b Mon Sep 17 00:00:00 2001
ea00c4
From: Eduardo Otubo <otubo@redhat.com>
ea00c4
Date: Mon, 7 Dec 2020 14:23:22 +0100
ea00c4
Subject: [PATCH 3/4] Fix unit failure of cloud-final.service if NetworkManager
ea00c4
 was not present.
ea00c4
ea00c4
RH-Author: Eduardo Terrell Ferrari Otubo (eterrell)
ea00c4
RH-MergeRequest: 27: Fix unit failure of cloud-final.service if NetworkManager was not present.
ea00c4
RH-Commit: [1/1] 3c65a2cca140fff48df1ef32919e3cb035506a2b (eterrell/cloud-init)
ea00c4
RH-Bugzilla: 1898943
ea00c4
ea00c4
cloud-final.service would fail if NetworkManager was not installed.
ea00c4
ea00c4
journal -u cloud-final.service would show:
ea00c4
ea00c4
   cloud-init[5328]: Cloud-init v. 19.4 finished at ...
ea00c4
   echo[5346]: try restart NetworkManager.service
ea00c4
   systemctl[5349]: Failed to reload-or-try-restart
ea00c4
       NetworkManager.service: Unit not found.
ea00c4
   systemd[1]: cloud-final.service: control process exited,
ea00c4
       code=exited status=5
ea00c4
   systemd[1]: Failed to start Execute cloud user/final scripts.
ea00c4
   systemd[1]: Unit cloud-final.service entered failed state.
ea00c4
   systemd[1]: cloud-final.service failed.
ea00c4
ea00c4
The change here is to only attempt to restart NetworkManager if it is
ea00c4
present, and its SubState is 'running'.
ea00c4
ea00c4
The multi-line shell in a systemd unit is less than ideal, but I'm not
ea00c4
aware of any other way of conditionally doing this.
ea00c4
ea00c4
Note that both of 'try-reload-or-restart' and 'reload-or-try-restart'
ea00c4
will fail if the service is not present.  So this would also affect rhel
ea00c4
8 systems that do not use NetworkManager.
ea00c4
ea00c4
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
ea00c4
---
ea00c4
 rhel/systemd/cloud-final.service | 7 +++++--
ea00c4
 1 file changed, 5 insertions(+), 2 deletions(-)
ea00c4
ea00c4
diff --git a/rhel/systemd/cloud-final.service b/rhel/systemd/cloud-final.service
ea00c4
index 05add077..e281c0cf 100644
ea00c4
--- a/rhel/systemd/cloud-final.service
ea00c4
+++ b/rhel/systemd/cloud-final.service
ea00c4
@@ -11,8 +11,11 @@ ExecStart=/usr/bin/cloud-init modules --mode=final
ea00c4
 RemainAfterExit=yes
ea00c4
 TimeoutSec=0
ea00c4
 KillMode=process
ea00c4
-ExecStartPost=/bin/echo "trying to reload or restart NetworkManager.service"
ea00c4
-ExecStartPost=/usr/bin/systemctl try-reload-or-restart NetworkManager.service
ea00c4
+# Restart NetworkManager if it is present and running.
ea00c4
+ExecStartPost=/bin/sh -c 'u=NetworkManager.service; \
ea00c4
+ out=$(systemctl show --property=SubState $u) || exit; \
ea00c4
+ [ "$out" = "SubState=running" ] || exit 0; \
ea00c4
+ systemctl reload-or-try-restart $u'
ea00c4
 
ea00c4
 # Output needs to appear in instance console output
ea00c4
 StandardOutput=journal+console
ea00c4
-- 
ea00c4
2.18.4
ea00c4