-#!/bin/bash
+#!/bin/sh
#
-# $Id$
+# autofs automatically mounts filesystems when you use them,
+# and unmounts them later when you are not using them.
#
-# /etc/rc.d/init.d/autofs
+# chkconfig: 2345 72 08
#
-# 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
+# description: Script for automount using a Sun-style "master map".
+# We first look for a local /etc/autofs/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
+# processname: autofs
+# config: /etc/autofs/auto.master
-# Source function library.
+
+# Source function library
. /etc/rc.d/init.d/functions
-[ -f /usr/sbin/automount ] || exit 0
+# Get network config
+. /etc/sysconfig/network
-#
-# We can add local options here
-# e.g. localoptions='rsize=8192,wsize=8192'
-#
-localoptions=''
+# Demon specified configuration.
+[ -f /etc/sysconfig/autofs ] && . /etc/sysconfig/autofs
+
+# Check that networking is up.
+if is_no "${NETWORKING}"; then
+ # nls "ERROR: Networking is down. %s can't be run." <service>
+ msg_network_down automounter
+ exit 1
+fi
+
+DAEMON=/usr/sbin/automount
#
# 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()
+getmounts()
{
#
-# Check for local maps to be loaded
+# Check for local maps to be loaded
#
if [ -f /etc/autofs/auto.master ]
then
if [ ! -z "$dir" -a ! -z "$map" \
-a x`echo "$map" | cut -c1` != 'x-' ]
then
- map=`echo "/etc/autofs/$map" | sed -e 's:^/etc/autofs/:/:'`
- # 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'`
+ map=`echo "/etc/autofs/$map" | sed -e 's:^/etc\/autofs//:/:'`
+ options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'`
if [ -x $map ]; then
- echo "/usr/sbin/automount $mountoptions $dir program $map $options $localoptions"
+ echo "$DAEMON --timeout $TIMEOUT $dir program $map $options"
elif [ -f $map ]; then
- echo "/usr/sbin/automount $mountoptions $dir file $map $options $localoptions"
+ echo "$DAEMON --timeout $TIMEOUT $dir file $map $options"
else
- echo "/usr/sbin/automount $mountoptions $dir `basename $map` $options $localoptions"
+ echo "$DAEMON --timeout $TIMEOUT $dir `basename $map` $options"
fi
fi
done
fi
#
-# Check for YellowPage maps to be loaded
+# Check for YellowPage maps to be loaded
#
+if is_yes $USE_YP; then
if [ -e /usr/bin/ypcat ] && [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ]
then
ypcat -k auto.master | (
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"
+ options=`echo "$options" | sed -e '
+ s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
+ s/\(^\|[ \t]\)-/\1/g'`
+ echo "$DAEMON --timeout $TIMEOUT $mountoptions $dir yp $map $options"
fi
done
)
fi
+fi
}
#
#
case "$1" in
start)
- # Check if the automounter is already running?
- if [ ! -f /var/lock/subsys/automount ]; then
- show Starting automounter
- busy
- getmounts | sh
- touch /var/lock/subsys/automount
- deltext
- ok
+ # Check if the service is already running?
+ if [ ! -f /var/lock/subsys/autofs ]; then
+ msg_starting automounter
+ busy
+ if getmounts | sh; then
+ deltext;ok
+ else
+ deltext;ok
+ fi
+ RETVAL=$?
+ [ $RETVAL -eq 0 ] && touch /var/lock/subsys/autofs
+ else
+ msg_already_running automounter
+ exit 1
fi
;;
stop)
- show Stopping automounter
- busy
- kill -TERM $(/sbin/pidof /usr/sbin/automount)
- rm -f /var/lock/subsys/automount
- deltext
- ok
+ if [ -f /var/lock/subsys/autofs ]; then
+ msg_stopping automount -TERM
+ killproc automount
+ rm -f /var/lock/subsys/autofs >/dev/null 2>&1
+ else
+ msg_not_running automounter
+ exit 1
+ fi
;;
- 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
+ restart|reload)
+ $0 stop
+ $0 start
;;
status)
echo "Configured Mount Points:"
getmounts
echo ""
echo "Active Mount Points:"
- ps ax|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
+ ps axw|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
while read pid tt stat time command; do echo $command; done
)
;;
*)
- echo "Usage: $0 {start|stop|restart|reload|status}"
+ msg_usage "$0 {start|stop|restart|reload|status}"
exit 1
esac
-exit 0
+exit $RETVAL