sailesh1993 / rpms / cloud-init

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