Josef Stribny e4f4864
From c4733a02d483818c3e9a99f1e94582d9a43593ae Mon Sep 17 00:00:00 2001
Josef Stribny e4f4864
From: Josef Stribny <jstribny@redhat.com>
Josef Stribny e4f4864
Date: Tue, 30 Jun 2015 10:21:58 +0200
Josef Stribny e4f4864
Subject: [PATCH] Rewrite Red Hat nfs caps based on systemd checks
Josef Stribny e4f4864
Josef Stribny e4f4864
---
Josef Stribny e4f4864
 plugins/guests/redhat/cap/nfs_client.rb | 29 +++++++++++++++++++++--------
Josef Stribny e4f4864
 plugins/guests/redhat/plugin.rb         |  5 +++++
Josef Stribny e4f4864
 2 files changed, 26 insertions(+), 8 deletions(-)
Josef Stribny e4f4864
Josef Stribny e4f4864
diff --git a/plugins/guests/redhat/cap/nfs_client.rb b/plugins/guests/redhat/cap/nfs_client.rb
Josef Stribny e4f4864
index 0e80230..14e69d5 100644
Josef Stribny e4f4864
--- a/plugins/guests/redhat/cap/nfs_client.rb
Josef Stribny e4f4864
+++ b/plugins/guests/redhat/cap/nfs_client.rb
Josef Stribny e4f4864
@@ -3,14 +3,27 @@ module GuestRedHat
Josef Stribny e4f4864
     module Cap
Josef Stribny e4f4864
       class NFSClient
Josef Stribny e4f4864
         def self.nfs_client_install(machine)
Josef Stribny e4f4864
-          machine.communicate.tap do |comm|
Josef Stribny e4f4864
-            comm.sudo("yum -y install nfs-utils nfs-utils-lib")
Josef Stribny e4f4864
-            case machine.guest.capability("flavor")
Josef Stribny e4f4864
-            when :rhel_7
Josef Stribny e4f4864
-              comm.sudo("/bin/systemctl restart rpcbind nfs")
Josef Stribny e4f4864
-            else
Josef Stribny e4f4864
-              comm.sudo("/etc/init.d/rpcbind restart; /etc/init.d/nfs restart")
Josef Stribny e4f4864
-            end
Josef Stribny e4f4864
+          machine.communicate.sudo("yum -y install nfs-utils nfs-utils-lib")
Josef Stribny e4f4864
+          restart_nfs(machine)
Josef Stribny e4f4864
+        end
Josef Stribny e4f4864
+
Josef Stribny e4f4864
+        def self.nfs_client_installed(machine)
Josef Stribny e4f4864
+          installed = machine.communicate.test("test -x /sbin/mount.nfs")
Josef Stribny e4f4864
+          restart_nfs(machine) if installed
Josef Stribny e4f4864
+          installed
Josef Stribny e4f4864
+        end
Josef Stribny e4f4864
+
Josef Stribny e4f4864
+        protected
Josef Stribny e4f4864
+
Josef Stribny e4f4864
+        def self.systemd?
Josef Stribny e4f4864
+          `ps -o comm= 1`.chomp == 'systemd'
Josef Stribny e4f4864
+        end
Josef Stribny e4f4864
+
Josef Stribny e4f4864
+        def self.restart_nfs(machine)
Josef Stribny e4f4864
+          if systemd?
Josef Stribny e4f4864
+            machine.communicate.sudo("/bin/systemctl restart rpcbind nfs")
Josef Stribny e4f4864
+          else
Josef Stribny e4f4864
+            machine.communicate.sudo("/etc/init.d/rpcbind restart; /etc/init.d/nfs restart")
Josef Stribny e4f4864
           end
Josef Stribny e4f4864
         end
Josef Stribny e4f4864
       end
Josef Stribny e4f4864
diff --git a/plugins/guests/redhat/plugin.rb b/plugins/guests/redhat/plugin.rb
Josef Stribny e4f4864
index f7a2555..2ea8dce 100644
Josef Stribny e4f4864
--- a/plugins/guests/redhat/plugin.rb
Josef Stribny e4f4864
+++ b/plugins/guests/redhat/plugin.rb
Josef Stribny e4f4864
@@ -36,6 +36,11 @@ class Plugin < Vagrant.plugin("2")
Josef Stribny e4f4864
         Cap::NFSClient
Josef Stribny e4f4864
       end
Josef Stribny e4f4864
 
Josef Stribny e4f4864
+      guest_capability("redhat", "nfs_client_installed") do
Josef Stribny e4f4864
+        require_relative "cap/nfs_client"
Josef Stribny e4f4864
+        Cap::NFSClient
Josef Stribny e4f4864
+      end
Josef Stribny e4f4864
+
Josef Stribny e4f4864
       guest_capability("redhat", "rsync_install") do
Josef Stribny e4f4864
         require_relative "cap/rsync"
Josef Stribny e4f4864
         Cap::RSync
Josef Stribny e4f4864