Merge pull request #3638 from jtopper/nfs-sudo-improvements
Improve use of sudo for NFS export manipulation
This commit is contained in:
commit
771f951096
|
@ -0,0 +1,8 @@
|
|||
# These work with Ubuntu - they might need tweaking for other distributions
|
||||
|
||||
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
|
||||
Cmnd_Alias VAGRANT_NFSD_CHECK = /etc/init.d/nfs-kernel-server status
|
||||
Cmnd_Alias VAGRANT_NFSD_START = /etc/init.d/nfs-kernel-server start
|
||||
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
|
||||
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /etc/exports
|
||||
%sudo ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY, VAGRANT_EXPORTS_REMOVE
|
|
@ -0,0 +1,5 @@
|
|||
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
|
||||
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
|
||||
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
|
||||
%admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE
|
||||
|
|
@ -105,7 +105,7 @@ module VagrantPlugins
|
|||
# Output the rendered template into the exports
|
||||
output.split("\n").each do |line|
|
||||
line = Vagrant::Util::ShellQuote.escape(line, "'")
|
||||
system("sudo", "-s", "--", "echo '#{line}' >> /etc/exports")
|
||||
system("echo '#{line}' | sudo tee -a /etc/exports >/dev/null")
|
||||
end
|
||||
|
||||
# We run restart here instead of "update" just in case nfsd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require "vagrant/util"
|
||||
require "vagrant/util/shell_quote"
|
||||
require "vagrant/util/retryable"
|
||||
|
||||
module VagrantPlugins
|
||||
|
@ -38,9 +39,8 @@ module VagrantPlugins
|
|||
nfs_cleanup(id)
|
||||
|
||||
output.split("\n").each do |line|
|
||||
# This should only ask for administrative permission once, even
|
||||
# though its executed in multiple subshells.
|
||||
system(%Q[sudo su root -c "echo '#{line}' >> /etc/exports"])
|
||||
line = Vagrant::Util::ShellQuote.escape(line, "'")
|
||||
system(%Q[echo '#{line}' | sudo tee -a /etc/exports >/dev/null])
|
||||
end
|
||||
|
||||
if nfs_running?(nfs_check_command)
|
||||
|
|
Loading…
Reference in New Issue