From 166d10d4e16836e908be0bd94c2f671cac2b38b4 Mon Sep 17 00:00:00 2001 From: Latchezar Tzvetkoff Date: Tue, 29 Nov 2016 15:40:48 +0200 Subject: [PATCH] Fix `service network restart` on RHEL-7 / Fedora RHEL-7 / Current Fedora versions tend to use NetworkManager for configuring the networks, and `service network restart` might fail. If the `NetworkManager` service is running, we should restart it, otherwise we try restarting `network`. --- plugins/guests/redhat/cap/change_host_name.rb | 8 ++++++-- plugins/guests/redhat/cap/configure_networks.rb | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/plugins/guests/redhat/cap/change_host_name.rb b/plugins/guests/redhat/cap/change_host_name.rb index afe461d4f91..e950c987b90 100644 --- a/plugins/guests/redhat/cap/change_host_name.rb +++ b/plugins/guests/redhat/cap/change_host_name.rb @@ -31,8 +31,12 @@ def self.change_host_name(machine, name) sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts } - # Restart network - service network restart + # Restart network (through NetworkManager if running) + if service NetworkManager status 2>&1 | grep -q running; then + service NetworkManager restart + else + service network restart + fi EOH end end diff --git a/plugins/guests/redhat/cap/configure_networks.rb b/plugins/guests/redhat/cap/configure_networks.rb index 6749f1bdcdc..39645796883 100644 --- a/plugins/guests/redhat/cap/configure_networks.rb +++ b/plugins/guests/redhat/cap/configure_networks.rb @@ -36,7 +36,7 @@ def self.configure_networks(machine, networks) # Add the new interface and bring it back up final_path = "#{network_scripts_dir}/ifcfg-#{network[:device]}" - commands << <<-EOH.gsub(/^ */, '') + commands << <<-EOH.gsub(/^ {14}/, '') # Down the interface before munging the config file. This might # fail if the interface is not actually set up yet so ignore # errors. @@ -48,9 +48,13 @@ def self.configure_networks(machine, networks) EOH end - commands << <<-EOH.gsub(/^ */, '') - # Restart network - service network restart + commands << <<-EOH.gsub(/^ {12}/, '') + # Restart network (through NetworkManager if running) + if service NetworkManager status 2>&1 | grep -q running; then + service NetworkManager restart + else + service network restart + fi EOH comm.sudo(commands.join("\n"))