From f2b83ac662742a8d7021f38bf7cb0fbd4f732bf3 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Sat, 24 Aug 2013 19:37:09 +0900 Subject: [PATCH] export nfs gracer way in Linux To reload /etc/exports, /sbin/exportfs is best way to command it in standard. It modify generic linux to check daemon status before restart instead of restarting everytime. Signed-off-by: Hiroshi Miura --- plugins/hosts/fedora/host.rb | 7 +++++-- plugins/hosts/gentoo/host.rb | 4 +++- plugins/hosts/linux/host.rb | 16 ++++++++++++---- plugins/hosts/opensuse/host.rb | 4 +++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/plugins/hosts/fedora/host.rb b/plugins/hosts/fedora/host.rb index 40b1ca33d..5d5c246a8 100644 --- a/plugins/hosts/fedora/host.rb +++ b/plugins/hosts/fedora/host.rb @@ -27,7 +27,7 @@ module VagrantPlugins def initialize(*args) super - @nfs_server_binary = "/etc/init.d/nfs" + nfs_server_binary = "/etc/init.d/nfs" # On Fedora 16+, systemd replaced init.d, so we have to use the # proper NFS binary. This checks to see if we need to do that. @@ -38,13 +38,16 @@ module VagrantPlugins if version_number >= 16 # "service nfs-server" will redirect properly to systemctl # when "service nfs-server restart" is called. - @nfs_server_binary = "/usr/sbin/service nfs-server" + nfs_server_binary = "/usr/sbin/service nfs-server" end end rescue Errno::ENOENT # File doesn't exist, not a big deal, assume we're on a # lower version. end + @nfs_apply_command = "/usr/sbin/exportfs -r" + @nfs_check_command = "#{nfs_server_binary} status" + @nfs_start_command = "#{nfs_server_binary} start" end end end diff --git a/plugins/hosts/gentoo/host.rb b/plugins/hosts/gentoo/host.rb index becaaf847..58179441b 100644 --- a/plugins/hosts/gentoo/host.rb +++ b/plugins/hosts/gentoo/host.rb @@ -17,7 +17,9 @@ module VagrantPlugins def initialize(*args) super - @nfs_server_binary = "/etc/init.d/nfs" + @nfs_apply_command = "/usr/sbin/exportfs -r" + @nfs_check_command = "service nfs status" + @nfs_start_command = "service nfs start" end end end diff --git a/plugins/hosts/linux/host.rb b/plugins/hosts/linux/host.rb index 265992389..56b25f95f 100644 --- a/plugins/hosts/linux/host.rb +++ b/plugins/hosts/linux/host.rb @@ -24,7 +24,9 @@ module VagrantPlugins super @logger = Log4r::Logger.new("vagrant::hosts::linux") - @nfs_server_binary = "/etc/init.d/nfs-kernel-server" + @nfs_apply_command = "/usr/sbin/exportfs -r" + @nfs_check_command = "/etc/init.d/nfs-kernel-server status" + @nfs_start_command = "/etc/init.d/nfs-kernel-server start" end def nfs? @@ -51,9 +53,11 @@ module VagrantPlugins system(%Q[sudo su root -c "echo '#{line}' >> /etc/exports"]) end - # We run restart here instead of "update" just in case nfsd - # is not starting - system("sudo #{@nfs_server_binary} restart") + if nfs_running? + system("sudo #{@nfs_apply_command}") + else + system("sudo #{@nfs_start_command}") + end end def nfs_prune(valid_ids) @@ -83,6 +87,10 @@ module VagrantPlugins protected + def nfs_running? + system("#{@nfs_check_command}") + end + def nfs_cleanup(id) return if !File.exist?("/etc/exports") diff --git a/plugins/hosts/opensuse/host.rb b/plugins/hosts/opensuse/host.rb index b560a4944..4c564bb45 100644 --- a/plugins/hosts/opensuse/host.rb +++ b/plugins/hosts/opensuse/host.rb @@ -27,7 +27,9 @@ module VagrantPlugins def initialize(*args) super - @nfs_server_binary = "/etc/init.d/nfsserver" + @nfs_apply_command = "/usr/sbin/exportfs -r" + @nfs_check_command = "service nfsserver status" + @nfs_start_command = "service nfsserver start" end end end