Sunday, October 4, 2009

Wake-on-lan (WOL) & NFS Mounts (2)

The mount.nfs.wol script works for mounting but umount.nfs is a symlink to mount.nfs so unmounts don't work. Also if a wol options is missing we shouldn't call etherwake. All in al some minor cleanup is needed.
The new script:

--
#!/bin/sh

# Parameters
ORIG_MOUNT=/sbin/mount.nfs.orig
ORIG_UMOUNT=/sbin/umount.nfs.orig

# No user servicable parts below
progname=`basename $0`

case "$progname" in
        mount.nfs)
                # arg 4 is the NFS options. Parse them
                args=`echo $4 | tr ',' ' '`
                target_args=
                for f in $args
                        do
                                if [ "wol" = "${f:0:3}" ]
                        then
                                wol=`echo ${f} | cut -f 2 -d=`
                        else
                                if [ ! -z "${target_args}" ]
                                then
                                        target_args="${target_args},"
                                fi
                                target_args="${target_args}${f}"
                        fi
                done

                # Only try to wake the target server if a wol is specified.
                if [ ! -z "${wol}" ]
                then
                        etherwake ${wol}
                fi

                exec ${ORIG_MOUNT} $1 $2 $3 ${target_args}
                ;;

        umount.nfs)
                exec ${ORIG_UMOUNT} $@
                ;;
        *)
                echo "Unknown command: ${progname}"
                exit 1
                ;;
esac


--

And we need a new symlink for umount.nfs as well as mount.nfs checks the program name to see if it needs to mount or umount. Luckily for us it just seems to check the first letter and not the whole application name.
So add the symlink: cd /sbin && ln -s mount.nfs.orig umount.nfs.orig.


Next up: testing this with autofs.

No comments:

Post a Comment