Quote:
Originally Posted by harshaabba
But during the server boot if remote nfs mount point does not exist, server might hang.
I want to include this to start up script. Is there any predefined script you created which I can use.
|
Predefined? No. (Well,
I've never seen one.) Easy to write? Yes.
I also had problems with a system (not a Linux system but the concepts are the same) hanging because we had defined the NFS mount in /etc/fstab. If the NFS server was down for maintenance we'd hang on a reboot. So I used a script to mount (and umount) NFS filesystems at work some years ago. The script was written like a typical `init' script with a case/esac structure and `start'/`stop' sections). The script pinged the system hosting the remote filesystem. If the pings succeeded, I'd then use ``showmount -e remote-host'' and grep the output to see if the NFS service on that host was actually exporting the filesystem we wanted to mount. If both of those checks were successful,
then we'd mount the NFS filesystem. I seem to recall that we'd hang if we were shutting down and the NFS server was down as well. The umount would sit there until what seemed like forever so the `stop' section pinged the NFS server before doing the umount. If the pings failed, we'd issue ``umount -f''.
I put the script in ``/usr/local/etc/init.d/mount_umount_nfs_fs'' and created a symbolic link to it in /etc/rc3.d called ``S95mount_nfs_filesystems'' and another in /etc/rc0.d (``K00umount_nfs_filesystems'').
The script we used was actually table-driven as we needed to access multiple NFS servers. A record in the table/file looked like:
Code:
nfssvr:exported-fs:mount-options:local_mount-point
The complication added by reading from the file is minor and only involves performing those checks and the eventual mount inside a loop that uses parameters read from the file:
Code:
NFSFSDAT=whereever-you-stash-the-nfs-export-mount-point-data-file
case $1 in
'start')
cat ${NFSFSDAT} | while read REC
do
NFSSVR=`echo $REC | cut -d: -f1`
EXPFS=`echo $REC | cut -d: -f2`
MNTOPTS=`echo $REC | cut -d: -f3`
MNTPT=`echo $REC | cut -d: -f4`
# Test to see if the NFS filesystem is not mounted. If so, we proceed.
# If it is we drop through to the bottom of the loop.
if [ -z "`mount | grep nfs | grep ${NFSSVR}:${EXPFS}`" ]
then
# Ping $NFSSVR and test if alive
ping -c 3 $NFSSVR -q > /dev/null
if [ $? -eq 0 ]
then
if [ -n "`showmount -e $NFSSVR | grep $EXPFS`" ]
then
# NFS server is up so perform mount
echo "Mounting ${NFSSVR}:${EXPFS}..."
mount -t nfs -o ${MNTOPTS} ${NFSSVR}:${EXPFS} ${MNTPT}
else
echo "NFS server ${NFSSVR} is not exporting \"${EXPFS}\". Not mounted."
fi
else
echo "NFS server not reachable. Not mounting ${NFSSVR}:${EXPFS}."
fi
else
echo "${NFSSVR}:${EXPFS} is already mounted."
fi
done
;;
'stop')
(same sort of stuff done here but for unmounting... and remember the different umount if the pings fail)
;;
esac
(Note: I don't have access to the systems where I was using this script so I wrote this from memory; I can't guarantee that everything's error-free.)
The first check looks to see if the filesystem is already mounted and skips the other checks and the mount if it is. Why? Well, if there had been a failure of one (or more) of the NFS servers while our system was booting and mounting, once the remote system was back up, we could merely run the script by hand to mount the missing filesystem(s). We got a simple reminder that the the mount had already been done but no ugly error messages from mount(8). (Similar logic was in there for the umounts: don't umount if it's not mounted.) After that the ping check is done and, if successful, the mount is done.
One thing I didn't take into account in the above script fragment is checking to see if the host trying to mount the NFS exported filesystem is able/authorized to do so. That would be an extra pipe from the `showmount -e' command into a grep for the local hostname:
Code:
showmount -e $NFSSVR | grep $EXPFS | grep $HOSTNAME
(I don't recall having to do that in my old script but probably should have. Mounts would obviously fail if the NFS was up and exporting the desired filesystem but you were not authorized to mount it. It'd probably be best to find that out with the test of showmount rather than trying to figure out from a mount failure which might not give you a very descriptive error message.)
Once I had this script running, I left the entries in /etc/fstab but commented out and included a comment line noting that NFS filesystems
were in use and that the new script was handling their mounting. (In case another admin was poking around in the fstab and hadn't read the memo about the new script.)
Hope this points you in the right direction...
More questions? Post them here and I'll watch for 'em.
--
Rick