Hello,
I am using autofs version 3.1.1 and I have some problems with
the /etc/rc.d/init.d/autofs script, so I thought I'd contribute
some code, but I need some information:
- Is the autofs script part of the autofs distribution?
- Are you maintaining this script?
- I use RedHat 5.1. Are they using the original script,
or is it `enhanced', hence the problems? RedHat autofs
script attached.
- Is 3.1.1 the latest version?
If I have an `enhanced' or outdated version, please tell me so
that I contact RedHat. Otherwise, problems and proposed
solutions follow...
We have Solaris servers at office. I try to automount user home
directories on my Linux box. But:
- A NIS auto.master map is exported by the NIS server. It contains
entries that are of no interest and cannot be understood by Linux.
I am thinking of
/- auto_direct -ro
I intend to filter out the `/-' directories when reading the NIS
auto.master entries, in the same way maps beginning with `-' are
already filtered out.
- A local /etc/auto.master file exists on my Linux box, along with
the NIS auto.master map. The autofs script reads the local
/etc/auto.home file first, then the NIS auto.home map. These maps
are merged.
This is not the exact Solaris behaviour. Indeed, have a look at
the Solaris automount(1M) page:
# Master map for automounter
#
+automaster
/net -hosts -nosuid
/home auto_home
/xfn -xfn
The +auto_master entry is a reference to an external NIS or NIS+
master map. If one exists, then its entries are read as if they
occured in place of the +auto_master entry.
It seems that a local /etc/auto_master file _must_ exist on Solaris.
The existence of `+automaster' suggest that the NIS map is not read
and merged by default, only if +automaster exists. Shouldn't we do
the same? This involves only small modifications to the getmounts()
function.
- The location of the user home directories will always be described in
the NIS auto.home map. There's no point in maintaining a local copy.
However, I keep a local /etc/auto.master file. The NIS auto.home map is
an entry in the local /etc/auto.master map:
/home auto.home -nobrowse
The current autofs script cannot read the NIS auto.home map, because
getmounts() can read only local maps when handling a local master map.
To correct this, I intend to change from:
if [ -x $map ]; then
echo "/usr/sbin/automount $mountoptions $dir program $map # [...]
elif [ -f $map ]; then
echo "/usr/sbin/automount $mountoptions $dir file $map # [...]
else
echo "/usr/sbin/automount $mountoptions $dir `basename $map` # [...]
fi
to something like this:
if [ -x $map ]; then
echo "/usr/sbin/automount $mountoptions $dir program $map # [...]
elif [ -f $map ]; then
echo "/usr/sbin/automount $mountoptions $dir file $map # [...]
elif [ -x /usr/bin/ypcat ] && ypcat -k $map >/dev/null 2>&1 ; then
echo "/usr/sbin/automount $mountoptions $dir file $map # [...]
else
echo "/usr/sbin/automount $mountoptions $dir `basename $map` # [...]
fi
- By the way, why is an `x' prepended to both sides of the `!=' operator in
line 48? Shouldn't we change from:
-a x`echo "$map" | cut -c1` != 'x-' ]
to:
-a `echo "$map" | cut -c1` != '-' ]
I understand that the intend is to filter out special maps such as -hosts,
-xfn and -null.
#! /bin/bash
#
# $Id: rc.autofs,v 1.3 1998/03/28 03:22:38 hpa Exp $
#
# /etc/rc.d/init.d/autofs
#
# rc file for automount using a Sun-style "master map".
# We first look for a local /etc/auto.master, then a YP
# map with that name
#
# chkconfig: - 72 08
# description: automatically mounts filesystems when you use \
# them, and unmounts them later when you are not using them.
# processname: automount
# Note that there may be multiple processes names automount
# config: /etc/auto.master
# Note that all other config files are automatically reloaded
# and may be different on different systems; we can ignore them
# here
#
# Source function library.
#
. /etc/rc.d/init.d/functions
#
# This is the automount daemon.
#
test -x /usr/sbin/automount || exit 0
#
# We can add local options here
# e.g. localoptions='rsize=8192,wsize=8192'
#
localoptions=''
#
# This function will build a list of automount commands to execute in
# order # to activate all the mount points. It is used to figure out
# the difference of automount points in case of a reload
#
function getmounts()
{
#
# Check for local maps to be loaded
#
if [ -f /etc/auto.master ]
then
cat /etc/auto.master | sed -e '/^#/d' -e '/^$/d'| (
while read dir map options
do
if [ ! -z "$dir" -a ! -z "$map" \
-a x`echo "$map" | cut -c1` != 'x-' ]
then
map=`echo "/etc/$map" | sed -e 's:^/etc//:/:'`
# special: treat -t or --timeout (or any reasonable derivative)
# specially, since it can't be made a normal mount option.
if echo $options | grep -- '-t' >/dev/null 2>&1 ; then
mountoptions="--timeout $(echo $options | \
sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
fi
options=`echo "$options" | sed -e '
s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
s/\(^\|[ \t]\)-/\1/g'`
if [ -x $map ]; then
echo "/usr/sbin/automount $mountoptions $dir program $map $options
$localoptions"
elif [ -f $map ]; then
echo "/usr/sbin/automount $mountoptions $dir file $map $options
$localoptions"
elif [ -x /usr/bin/ypcat ] && ypcat -k $map >/dev/null 2>&1 ; then
echo "/usr/sbin/automount $mountoptions $dir yp $map $options
$localoptions"
else
echo "/usr/sbin/automount $mountoptions $dir `basename $map`
$options $localoptions"
fi
fi
done
)
fi
#
# Check for YellowPage maps to be loaded
#
if [ -x /usr/bin/ypcat ] && [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ]
then
ypcat -k auto.master | (
while read dir map options
do
if [ ! -z "$dir" -a ! -z "$map" \
-a "$dir" != '/-' \
-a `echo "$map" | cut -c1` != '-' ]
then
map=`echo "$map" | sed -e 's/^auto_/auto./'`
if echo $options | grep -- '-t' >/dev/null 2>&1 ; then
mountoptions="--timeout $(echo $options | \
sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
fi
options=`echo "$options" | sed -e '
s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
s/\(^\|[ \t]\)-/\1/g'`
echo "/usr/sbin/automount $mountoptions $dir yp $map $options
$localoptions"
fi
done
)
fi
}
#
# See how we were called.
#
case "$1" in
start)
# Check if the automounter is already running?
if [ ! -f /var/lock/subsys/automount ]; then
echo 'Starting automounter: '
getmounts | sh
touch /var/lock/subsys/automount
fi
;;
stop)
kill -TERM $(/sbin/pidof /usr/sbin/automount)
rm -f /var/lock/subsys/automount
;;
reload|restart)
if [ ! -f /var/lock/subsys/automount ]; then
echo "Automounter not running"
exit 1
fi
echo "Checking for changes to /etc/auto.master ...."
TMP1=`mktemp /tmp/autofs.XXXXXX` || { echo "could not make temp file" >&2;
exit 1 }
TMP2=`mktemp /tmp/autofs.XXXXXX` || { echo "could not make temp file" >&2;
exit 1 }
getmounts >$TMP1
ps ax|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
while read pid tt stat time command; do
echo "$command" >>$TMP2
if ! grep -q "^$command" $TMP2; then
kill -USR2 $pid
echo "Stop $command"
fi
done
)
cat $TMP1 | ( while read x; do
if ! grep -q "^$x" $TMP2; then
$x
echo "Start $x"
fi
done )
rm -f $TMP1 $TMP2
;;
status)
echo "Configured Mount Points:"
getmounts
echo ""
echo "Active Mount Points:"
ps ax|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
while read pid tt stat time command; do echo $command; done
)
;;
*)
echo "Usage: /etc/rc.d/init.d/autofs {start|stop|restart|reload|status}"
exit 1
esac
exit 0