Add option to use showmount to check NFS servers before mounting https://www.virtualmin.com/node/52754

This commit is contained in:
Jamie Cameron
2017-07-09 18:28:04 -07:00
parent b1d8f0f724
commit 8396e71c96
36 changed files with 122 additions and 83 deletions

View File

@@ -3,3 +3,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -5,3 +5,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -4,3 +4,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -6,3 +6,4 @@ nmblookup_path=nmblookup
auto_file=/etc/am-utils/amd.conf
autofs_file=/etc/auto.master
show_used=1
nfs_check=1

View File

@@ -6,3 +6,4 @@ smbclient_path=smbclient
long_fstypes=1
fstab_file=/etc/fstab
show_used=1
nfs_check=1

View File

@@ -3,3 +3,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -4,3 +4,4 @@ smbclient_path=smbclient
nmblookup_path=nmblookup
autofs_file=/etc/autofs/auto.master
show_used=1
nfs_check=1

View File

@@ -6,3 +6,4 @@ smbclient_path=smbclient
long_fstypes=1
fstab_file=/etc/fstab
show_used=1
nfs_check=1

View File

@@ -6,3 +6,4 @@ long_fstypes=1
smbclient_path=
fstab_file=/etc/fstab
show_used=1
nfs_check=1

View File

@@ -5,3 +5,4 @@ auto_file=
smbclient_path=smbclient
long_fstypes=1
show_used=1
nfs_check=1

View File

@@ -5,3 +5,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -5,3 +5,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -6,3 +6,4 @@ smbclient_path=smbclient
long_fstypes=1
fstab_file=/etc/fstab
show_used=1
nfs_check=1

View File

@@ -4,3 +4,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -4,3 +4,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -6,3 +6,4 @@ smbclient_path=smbclient
long_fstypes=1
fstab_file=/etc/fstab
show_used=1
nfs_check=1

View File

@@ -4,3 +4,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -6,3 +6,4 @@ long_fstypes=1
smbclient_path=/usr/local/samba/bin/smbclient
fstab_file=/etc/fstab
show_used=1
nfs_check=1

View File

@@ -3,3 +3,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -4,3 +4,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -5,3 +5,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -5,3 +5,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -3,3 +3,4 @@ long_fstypes=1
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -8,3 +8,4 @@ passwd_cindex=2
passwd_mindex=4
by_view=0
show_used=1
nfs_check=1

View File

@@ -4,3 +4,4 @@ long_fstypes=1
smbclient_path=/usr/local/samba/bin/smbclient
nmblookup_path=/usr/local/samba/bin/nmblookup
show_used=1
nfs_check=1

View File

@@ -4,3 +4,4 @@ autofs_file=/etc/auto.master
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -5,3 +5,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -5,3 +5,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -5,3 +5,4 @@ fstab_file=/etc/fstab
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -4,3 +4,4 @@ autofs_file=/etc/auto.master
smbclient_path=smbclient
nmblookup_path=nmblookup
show_used=1
nfs_check=1

View File

@@ -11,3 +11,4 @@ auto_file=NFS automounts file,3
autofs_file=Kernel automounts file,3
smbclient_path=Full path to smbclient,3
nmblookup_path=Full path to nmblookup,3
nfs_check=Check NFS servers before attempting mount,1,1-Yes,0-No

View File

@@ -684,23 +684,25 @@ sub check_location
if ($_[0] eq "nfs") {
local($out, $temp, $mout, $dirlist);
# Use ping and showmount to see if the host exists and is up
if ($in{nfs_host} !~ /^\S+$/) {
&error("'$in{nfs_host}' is not a valid hostname");
}
&execute_command("ping -c 1 '$in{nfs_host}'", undef, \$out, \$out);
if ($out =~ /unknown host/i) {
&error("The host '$in{nfs_host}' does not exist");
}
elsif ($out =~ /100\% packet loss/) {
&error("The host '$in{nfs_host}' is down");
}
&execute_command("showmount -e '$in{nfs_host}'", undef, \$out, \$out);
if ($out =~ /Unable to receive/) {
&error("The host '$in{nfs_host}' does not support NFS");
}
elsif ($?) {
&error("Failed to get mount list : $out");
if ($config{'nfs_check'}) {
# Use ping and showmount to see if the host exists and is up
if ($in{nfs_host} !~ /^\S+$/) {
&error("'$in{nfs_host}' is not a valid hostname");
}
&execute_command("ping -c 1 '$in{nfs_host}'", undef, \$out, \$out);
if ($out =~ /unknown host/i) {
&error("The host '$in{nfs_host}' does not exist");
}
elsif ($out =~ /100\% packet loss/) {
&error("The host '$in{nfs_host}' is down");
}
&execute_command("showmount -e '$in{nfs_host}'", undef, \$out, \$out);
if ($out =~ /Unable to receive/) {
&error("The host '$in{nfs_host}' does not support NFS");
}
elsif ($?) {
&error("Failed to get mount list : $out");
}
}
# Validate directory name

View File

@@ -676,24 +676,26 @@ sub check_location
if ($_[0] eq "nfs") {
local($out, $temp, $mout, $dirlist);
# Use ping and showmount to see if the host exists and is up
if ($in{nfs_host} !~ /^\S+$/) {
&error("'$in{nfs_host}' is not a valid hostname");
}
&execute_command("ping -c 1 '$in{nfs_host}'", undef, \$out, \$out);
if ($out =~ /unknown host/i) {
&error("The host '$in{nfs_host}' does not exist");
}
elsif ($out =~ /100\% packet loss/) {
&error("The host '$in{nfs_host}' is down");
}
&execute_command("showmount -e '$in{nfs_host}'", undef, \$out, \$out);
if ($out =~ /Unable to receive/) {
&error("The host '$in{nfs_host}' does not support NFS");
}
elsif ($?) {
&error("Failed to get mount list : $out");
}
if ($config{'nfs_check'}) {
# Use ping and showmount to see if the host exists and is up
if ($in{nfs_host} !~ /^\S+$/) {
&error("'$in{nfs_host}' is not a valid hostname");
}
&execute_command("ping -c 1 '$in{nfs_host}'", undef, \$out, \$out);
if ($out =~ /unknown host/i) {
&error("The host '$in{nfs_host}' does not exist");
}
elsif ($out =~ /100\% packet loss/) {
&error("The host '$in{nfs_host}' is down");
}
&execute_command("showmount -e '$in{nfs_host}'", undef, \$out, \$out);
if ($out =~ /Unable to receive/) {
&error("The host '$in{nfs_host}' does not support NFS");
}
elsif ($?) {
&error("Failed to get mount list : $out");
}
}
# Validate directory name
foreach (split(/\n/, $out)) {

View File

@@ -1644,7 +1644,7 @@ sub check_location
if (($_[0] eq "nfs") || ($_[0] eq "nfs4")) {
local($out, $temp, $mout, $dirlist, @dirlist);
if (&has_command("showmount")) {
if (&has_command("showmount") && $config{'nfs_check'}) {
# Use ping and showmount to see if the host exists and is up
if ($in{nfs_host} !~ /^\S+$/) {
&error(&text('linux_ehost', $in{'nfs_host'}));
@@ -1665,21 +1665,21 @@ if (($_[0] eq "nfs") || ($_[0] eq "nfs4")) {
elsif ($?) {
&error(&text('linux_elist', $out));
}
}
# Validate directory name for NFSv3 (in v4 '/' exists)
foreach (split(/\n/, $out)) {
if (/^(\/\S+)/) {
$dirlist .= "$1\n";
push(@dirlist, $1);
}
# Validate directory name for NFSv3 (in v4 '/' exists)
foreach (split(/\n/, $out)) {
if (/^(\/\S+)/) {
$dirlist .= "$1\n";
push(@dirlist, $1);
}
if ($_[0] ne "nfs4" && $in{'nfs_dir'} !~ /^\/.*$/ &&
&indexof($in{'nfs_dir'}, @dirlist) < 0) {
&error(&text('linux_enfsdir', $in{'nfs_dir'},
$in{'nfs_host'}, "<pre>$dirlist</pre>"));
}
}
}
if ($_[0] ne "nfs4" && $in{'nfs_dir'} !~ /^\/.*$/ &&
&indexof($in{'nfs_dir'}, @dirlist) < 0) {
&error(&text('linux_enfsdir', $in{'nfs_dir'},
$in{'nfs_host'}, "<pre>$dirlist</pre>"));
}
# Try a test mount to see if filesystem is available
$temp = &tempname();

View File

@@ -522,23 +522,25 @@ sub check_location
if ($_[0] eq "nfs") {
local($out, $temp, $mout, $dirlist);
# Use ping and showmount to see if the host exists and is up
if ($in{nfs_host} !~ /^\S+$/) {
&error("'$in{nfs_host}' is not a valid hostname");
}
$out = &backquote_command("ping -c 1 '$in{nfs_host}' 2>&1");
if ($out =~ /unknown host/i) {
&error("The host '$in{nfs_host}' does not exist");
}
elsif ($out =~ /100\% packet loss/) {
&error("The host '$in{nfs_host}' is down");
}
$out = &backquote_command("showmount -e '$in{nfs_host}' 2>&1");
if ($out =~ /Unable to receive/) {
&error("The host '$in{nfs_host}' does not support NFS");
}
elsif ($?) {
&error("Failed to get mount list : $out");
if ($config{'nfs_check'}) {
# Use ping and showmount to see if the host exists and is up
if ($in{nfs_host} !~ /^\S+$/) {
&error("'$in{nfs_host}' is not a valid hostname");
}
$out = &backquote_command("ping -c 1 '$in{nfs_host}' 2>&1");
if ($out =~ /unknown host/i) {
&error("The host '$in{nfs_host}' does not exist");
}
elsif ($out =~ /100\% packet loss/) {
&error("The host '$in{nfs_host}' is down");
}
$out = &backquote_command("showmount -e '$in{nfs_host}' 2>&1");
if ($out =~ /Unable to receive/) {
&error("The host '$in{nfs_host}' does not support NFS");
}
elsif ($?) {
&error("Failed to get mount list : $out");
}
}
# Validate directory name

View File

@@ -524,23 +524,25 @@ sub check_location
if ($_[0] eq "nfs") {
local($out, $temp, $mout, $dirlist);
# Use ping and showmount to see if the host exists and is up
if ($in{nfs_host} !~ /^\S+$/) {
&error("'$in{nfs_host}' is not a valid hostname");
}
$out = &backquote_command("ping -c 1 '$in{nfs_host}' 2>&1");
if ($out =~ /unknown host/i) {
&error("The host '$in{nfs_host}' does not exist");
}
elsif ($out =~ /100\% packet loss/) {
&error("The host '$in{nfs_host}' is down");
}
$out = &backquote_command("showmount -e '$in{nfs_host}' 2>&1");
if ($out =~ /Unable to receive/) {
&error("The host '$in{nfs_host}' does not support NFS");
}
elsif ($?) {
&error("Failed to get mount list : $out");
if ($config{'nfs_check'}) {
# Use ping and showmount to see if the host exists and is up
if ($in{nfs_host} !~ /^\S+$/) {
&error("'$in{nfs_host}' is not a valid hostname");
}
$out = &backquote_command("ping -c 1 '$in{nfs_host}' 2>&1");
if ($out =~ /unknown host/i) {
&error("The host '$in{nfs_host}' does not exist");
}
elsif ($out =~ /100\% packet loss/) {
&error("The host '$in{nfs_host}' is down");
}
$out = &backquote_command("showmount -e '$in{nfs_host}' 2>&1");
if ($out =~ /Unable to receive/) {
&error("The host '$in{nfs_host}' does not support NFS");
}
elsif ($?) {
&error("Failed to get mount list : $out");
}
}
# Validate directory name