LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   exports.d (https://www.linuxquestions.org/questions/slackware-14/exports-d-4175668873/)

slacker1337 02-02-2020 07:29 PM

exports.d
 
I noticed today that /etc/exports.d isn't supported in Slackware's /etc/rc.d/rc.nfsd init script. I'm running 64bit 14.2 and have a few files in /etc/exports.d/ but my /etc/exports is empty.

Anyways, I found rc.nfsd checks whether /etc/exports is readable, then checks if there are any exports but it exists there if /etc/exports is empty, without checking /etc/exports.d.

Has anyone else noticed this behavior? How do you all handle exports?

upnort 02-02-2020 07:53 PM

Do the files use the .exports extension?

Man page:

After reading /etc/exports exportfs reads files in the /etc/exports.d directory as extra export tables. Only files ending in .exports are considered. Files beginning with a dot are ignored. The format for extra export tables is the same as /etc/exports.

slacker1337 02-02-2020 08:28 PM

Yes, all of my <dot> files have the ".exports" extension. The issue I found is here:
<code>
nfsd_start() {
# Sanity checks. Exit if there's no /etc/exports, or if there aren't any
# shares defined in it.
if [ ! -r /etc/exports ]; then # no config file, exit:
exit
elif ! grep -v '^#' /etc/exports | grep '/' 1> /dev/null 2> /dev/null ; then
exit # no uncommented shares in /etc/exports
fi
</code>

upnort 02-02-2020 08:57 PM

The rc.nfsd script executes exportfs -r.

According to the man page, the exportfs command looks for /etc/exports.d. Thus no rc.d script support should be needed to source /etc/exports.d.

exportfs -r:

Reexport all directories, synchronizing /var/lib/nfs/etab with /etc/exports and files under /etc/exports.d. This option removes entries in /var/lib/nfs/etab which have been deleted from /etc/exports or files under /etc/exports.d, and removes any entries from the kernel export table which are no longer valid.

All well and good, but the rc.nfsd script terminates if /etc/exports does not exist or is empty, regardless of anything in /etc/exports.d.

Seems the script needs a little love to look at /etc/exports.d before terminating.

slacker1337 02-02-2020 09:17 PM

This is what I noticed as well. I could run /usr/sbin/exportfs and see the output from the exported filesystems, but I would get nothing running /usr/sbin/showmount -e <server_name> from the client side. In short, rc.nfsd was immediately exiting but it wasn't informing me of any problems.

upnort 02-02-2020 10:03 PM

Proposed patch with informative exit output. Please test.

Code:

--- rc.nfsd        2020-02-02 21:32:40.079584735 -0600
+++ rc.nfsd.new        2020-02-02 22:00:02.939046867 -0600
@@ -8,12 +8,17 @@
 # Written for Slackware Linux by Patrick J. Volkerding <volkerdi@slackware.com>.
 
 nfsd_start() {
-  # Sanity checks.  Exit if there's no /etc/exports, or if there aren't any
-  # shares defined in it.
-  if [ ! -r /etc/exports ]; then # no config file, exit:
+  # Sanity checks. Exit if there is no /etc/exports, /etc/exports.d is
+  # empty, or /etc/exports contains no uncommented entries
+  if [ ! -r /etc/exports ] && [ ! -d /etc/exports.d ]; then
+    echo "/etc/exports and /etc/exports.d do not exist. Exiting."
+    exit
+  elif [ ! -r /etc/exports ] && [ -d /etc/exports.d ] && [ "$(/bin/ls -A /etc/exports.d 2>/dev/null)" = "" ]; then
+    echo "/etc/exports does not exist and /etc/exports.d is empty. Exiting."
+    exit
+  elif [ ! -r /etc/exports ] && ! grep -v '^#' /etc/exports | grep '/' 1> /dev/null 2> /dev/null ; then
+    echo "/etc/exports exists but is empty or contains only comments. Exiting."
    exit
-  elif ! grep -v '^#' /etc/exports | grep '/' 1> /dev/null 2> /dev/null ; then
-    exit # no uncommented shares in /etc/exports
  fi
 
  # If we do not detect nfsd support built into the kernel (or previously


slacker1337 02-03-2020 05:21 AM

That's good, but doesn't check the original intent of PV's script - i.e. doesn't check to see if exports.d is actually exporting anything. I'd recommend the following:
*** /etc/rc.d/rc.nfsd 2020-02-03 06:13:21.621520725 -0500
--- /etc/rc.d/rc.nfsd.orig 2020-02-02 13:38:44.993237455 -0500
*************** nfsd_start() {
*** 11,22 ****
# Sanity checks. Exit if there's no /etc/exports, or if there aren't any
# shares defined in it.
if [ ! -r /etc/exports ]; then # no config file, exit:
! echo "/etc/exports is not readable" && exit
elif ! grep -v '^#' /etc/exports | grep '/' 1> /dev/null 2> /dev/null ; then
! # exit # no uncommented shares in /etc/exports
! if [[ ! $( grep -v '^#' /etc/exports.d/*.exports | grep '^/' ) ]]; then
! echo "exports or exports.d export nothing" && exit # no uncommented shares in /etc/exports.d
! fi
fi

# If we do not detect nfsd support built into the kernel (or previously
--- 11,19 ----
# Sanity checks. Exit if there's no /etc/exports, or if there aren't any
# shares defined in it.
if [ ! -r /etc/exports ]; then # no config file, exit:
! exit
elif ! grep -v '^#' /etc/exports | grep '/' 1> /dev/null 2> /dev/null ; then
! exit # no uncommented shares in /etc/exports
fi

# If we do not detect nfsd support built into the kernel (or previously

upnort 02-03-2020 07:31 PM

Might want to check the change in Current. The sanity checks have been removed. I don't know if Pat will backport the change to 14.2, but straightforward to fix.

slacker1337 02-03-2020 09:00 PM

I saw! It looks like he added the creation of /etc/exports.d as well. Thanks for your help upnort.

perbh 02-05-2020 01:36 PM

I always remove the test - I prefer (rightly or wrongly) to use /etc/rc.d/rc.local for my exports. Why? - well why not?
Sooo - it goes something like this:
Code:

df -a | grep -wq '/pub$' || {
        pub=/usb/public
        test -d $pub && {
                mount --bind $pub /pub && {
                        echo ":: mounted /pub on $pub ..."
                        mount --bind /pub /home/ftp/pub && {
                                echo ":: mounted /home/ftp/pub on /pub ..."
                                mops="rw,insecure,async,no_root_squash,anonuid=0,anongid=0"
                                exportfs -iv -o $mops 192.168.1.0/22:/pub
                                unset mops
                        }
                }
        }
        unset pub
}

I have similar exports on other machines where the fs I want to export may or may not be available (probably because it is an external disk).
/etc/exports (or exports.d) are fine if the exported fs is always available. Using rc.local I can do extensive checks as to the availability of the fs.


All times are GMT -5. The time now is 09:12 PM.