summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2004-01-15 01:58:11 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2004-01-15 01:58:11 (GMT)
commit1e44106d3dc35150ae0f30929ea02bbc0d456794 (patch)
treef9cd2e4d3b991253424f5008d7f162cb14d0aafd
parent165bf809b216591d612ab5a84a106f786d0ef70e (diff)
downloadautofs3-1e44106d3dc35150ae0f30929ea02bbc0d456794.zip
autofs3-1e44106d3dc35150ae0f30929ea02bbc0d456794.tar.gz
autofs3-1e44106d3dc35150ae0f30929ea02bbc0d456794.tar.bz2
autofs3-1e44106d3dc35150ae0f30929ea02bbc0d456794.tar.xz
Port to match what is currently in Fedora. Should now work on
"RedHat-like" systems, too (Slackware, Gentoo?)
-rw-r--r--samples/rc.autofs.in277
1 files changed, 202 insertions, 75 deletions
diff --git a/samples/rc.autofs.in b/samples/rc.autofs.in
index cdf638b..72c4a33 100644
--- a/samples/rc.autofs.in
+++ b/samples/rc.autofs.in
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/bin/bash
#
# $Id$
#
@@ -12,7 +12,9 @@
# For Redhat-ish systems
#
-# chkconfig: 345 15 85
+# chkconfig: 345 28 72
+# processname: /usr/sbin/automount
+# config: /etc/auto.master
# description: Automounts filesystems on demand
# This is used in the Debian distribution to determine the proper
@@ -28,16 +30,16 @@ FLAGS="defaults 21"
# Location of the automount daemon and the init directory
#
DAEMON=@@sbindir@@/automount
+prog=`basename $DAEMON`
initdir=@@initdir@@
#
# Determine which kind of configuration we're using
#
-system=unknown
if [ -f /etc/debian_version ]; then
system=debian
-elif [ -f /etc/redhat-release ]; then
- system=redhat
+elif [ -f $initdir/functions ]; then
+ system=redhat # Or something sufficiently close to it...
else
echo "$0: Unknown system, please port and contact autofs@linux.kernel.org" 1>&2
exit 1
@@ -48,10 +50,13 @@ if [ $system = redhat ]; then
fi
test -e $DAEMON || exit 0
-thisscript="$0"
-if [ ! -f "$thisscript" ]; then
- echo "$0: Cannot find myself" 1>&2
- exit 1
+
+if [ $system = debian ]; then
+ thisscript="$0"
+ if [ ! -f "$thisscript" ]; then
+ echo "$0: Cannot find myself" 1>&2
+ exit 1
+ fi
fi
PATH=/sbin:/usr/sbin:/bin:/usr/bin
@@ -63,6 +68,74 @@ export PATH
#
localoptions=''
+# Daemon options
+# e.g. --timeout 60
+#
+daemonoptions=''
+
+#
+# Check for all maps that are to be loaded
+#
+function getschemes()
+{
+ grep ^automount: /etc/nsswitch.conf | sed -e 's/^.*://' -e 's/\[.*\]/ /g'
+}
+function catnismap()
+{
+ if [ -z "$1" ] ; then
+ map="auto_master"
+ else
+ map="$1"
+ fi
+ /usr/bin/ypcat -k "$map" 2> /dev/null | sed -e '/^#/d' -e '/^$/d'
+}
+function getfilemounts()
+{
+ if [ -f /etc/auto.master ] ; then
+ cat /etc/auto.master | grep -v '^\+' | sed -e '/^#/d' -e '/^$/d'
+ for nismap in `cat /etc/auto.master | grep '^\+' | sed -e '/^#/d' -e '/^$/d'`; do
+ catnismap `echo "$nismap" | sed -e 's/^\+//'`
+ done
+ fi
+}
+function getnismounts()
+{
+ catnismap auto.master
+}
+function getldapmounts()
+{
+ @@autofslibdir@@/autofs-ldap-auto-master 2> /dev/null
+}
+function getrawmounts()
+{
+ for scheme in `getschemes` ; do
+ case "$scheme" in
+ files)
+ if [ -z "$filescheme" ] ; then
+ getfilemounts
+ filescheme=1
+ export filescheme
+ fi
+ ;;
+ nis)
+ if [ -z "$nisscheme" ] ; then
+ getnismounts
+ nisscheme=1
+ export nisscheme
+ fi
+ ;;
+ ldap*)
+ if [ -z "$ldapscheme" ] ; then
+ getldapmounts
+ ldapscheme=1
+ export ldapscheme
+ fi
+ ;;
+ esac
+ done
+}
+
+
#
# 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
@@ -70,55 +143,72 @@ localoptions=''
#
function getmounts()
{
-#
-# Check for local maps to be loaded
-#
-if [ -f /etc/auto.master ]
-then
- cat /etc/auto.master | sed -e '/^#/d' -e '/^$/d'| (
+ knownmaps=" "
+ getrawmounts | (
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//:/:'`
- options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'`
- if [ -x $map ]; then
- echo "$DAEMON $dir program $map $options $localoptions"
- elif [ -f $map ]; then
- echo "$DAEMON $dir file $map $options $localoptions"
- else
- echo "$DAEMON $dir `basename $map` $options $localoptions"
- fi
+ # These checks screen out duplicates and skip over directories
+ # where the map is '-'.
+ # We can't do empty or direct host maps, so don't bother trying.
+ if [ ! -z "$map" -a "$map" = "-hosts" ] ; then
+ continue
fi
- done
- )
-fi
-
-#
-# Check for YellowPage maps to be loaded
-#
-if [ -e /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 x`echo "$map" | cut -c1` != 'x-' ]
+ -a x`echo "$map" | cut -c1` != 'x-' \
+ -a "`echo "$knownmaps" | grep $dir/`" = "" ]
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')"
+ # If the options include a -t or --timeout parameter, then
+ # pull those particular options out.
+ : echo DAEMONOPTIONS OPTIONS $daemonoptions $options
+ startupoptions=
+ if echo $options | grep -q -- '-t' ; then
+ startupoptions="--timeout $(echo $daemonoptions $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 "$DAEMON $dir yp $map $options $localoptions"
+ # Other option flags are intended for maps.
+ mapoptions="$(echo "$daemonoptions $options" |\
+ sed 's/--*t\(imeout\)*[ \t=]*\([0-9][0-9]*\)//g')"
+ # Break up the maptype and map, if the map type is specified
+ maptype=`echo $map | cut -f1 -d:`
+ # Handle degenerate map specifiers
+ if [ "$maptype" = "$map" ] ; then
+ if [ -x "$map" ]; then
+ maptype=program
+ elif [ -x "/etc/$map" ]; then
+ maptype=program
+ map=`echo /etc/$map | sed 's^//^/^g'`
+ elif [ -f "$map" ]; then
+ maptype=file
+ elif [ -f "/etc/$map" ]; then
+ maptype=file
+ map=`echo /etc/$map | sed 's^//^/^g'`
+ elif [ "$map" = "hesiod" -o "$map" = "userhome" ] ; then
+ maptype=$map
+ map=
+ elif [ "$map" = "multi" ] ; then
+ maptype=$map
+ map=
+ else
+ maptype=yp
+ map=`basename $map | sed -e s/^auto_home/auto.home/ -e s/^auto_mnt/auto.mnt/`
+ fi
+ fi
+ map=`echo $map | cut -f2- -d:`
+
+ : echo STARTUPOPTIONS $startupoptions
+ : echo DIR $dir
+ : echo MAPTYPE $maptype
+ : echo MAP $map
+ : echo MAPOPTIONS $mapoptions
+ : echo LOCALOPTIONS $localoptions
+
+ echo "$DAEMON $startupoptions $dir $maptype $map $mapoptions $localoptions" | sed -e 's/ / /g' -e 's/ / /g'
+
+ : echo ------------------------
fi
+ knownmaps=" $dir/ $knownmaps"
done
)
-fi
}
#
@@ -126,13 +216,13 @@ fi
#
function status()
{
- echo "Configured Mount Points:"
- echo "------------------------"
+ echo $"Configured Mount Points:"
+ echo "------------------------"
getmounts
echo ""
- echo "Active Mount Points:"
- echo "--------------------"
- ps ax|grep "[0-9]:[0-9][0-9] automount " | (
+ echo $"Active Mount Points:"
+ echo "--------------------"
+ ps axwww|grep "[0-9]:[0-9][0-9] $DAEMON " | (
while read pid tt stat time command; do echo $command; done
)
}
@@ -149,39 +239,71 @@ function redhat()
#
case "$1" in
start)
- # Check if the automounter is already running?
- if [ ! -f /var/lock/subsys/autofs ]; then
- echo 'Starting automounter: '
- getmounts | sh
- touch /var/lock/subsys/autofs
+ # Make sure the autofs filesystem type is available.
+ (grep -q autofs /proc/filesystems || /sbin/modprobe -k autofs || /sbin/modprobe -k autofs4) 2> /dev/null
+ echo -n $"Starting $prog:"
+ TMP=`mktemp /tmp/autofs.XXXXXX` || { echo $"could not make temp file" >& 2; exit 1; }
+ getmounts | tee $TMP | sh
+ RETVAL=$?
+ if [ -s $TMP ] ; then
+ success "$prog startup" || failure "$prog startup"
+ [ $RETVAL = 0 ] && touch /var/lock/subsys/autofs
+ else
+ echo -n "" $"No Mountpoints Defined"
+ success "$prog startup"
fi
+ rm -f $TMP
+ echo
;;
stop)
- kill -TERM $(/sbin/pidof /usr/sbin/automount)
- rm -f /var/lock/subsys/autofs
+ echo -n $"Stopping $prog:"
+ if [ -z "`pidofproc $prog`" -a -z "`getmounts`" ]; then
+ success $"$prog shutdown"
+ RETVAL=0
+ else
+ killproc $DAEMON -USR2
+ RETVAL=$?
+ fi
+ count=0
+ while [ -n "`/sbin/pidof $DAEMON`" -a $count -lt 8 ] ; do
+ killproc $DAEMON -USR2
+ RETVAL=$?
+ [ $RETVAL = 0 -a -z "`/sbin/pidof $DAEMON`" ] || sleep ${count+1}
+ count=`expr $count + 1`
+ done
+ umount -a -f -t autofs
+ rm -f /var/lock/subsys/autofs
+ echo
+ ;;
+ restart)
+ redhat stop
+ redhat start
;;
- reload|restart)
+ reload)
if [ ! -f /var/lock/subsys/autofs ]; then
- echo "Automounter not running"
- exit 1
+ echo $"$prog not running"
+ RETVAL=1
+ return
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] automount " | (
+ 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 axwww|grep "[0-9]:[0-9][0-9] $DAEMON" | (
while read pid tt stat time command; do
echo "$command" >>$TMP2
- if ! grep -q "^$command" $TMP2; then
+ if ! grep -q "^$command" $TMP1; then
+ if ! echo "$command" | grep -q -e --submount; then
kill -USR2 $pid
- echo "Stop $command"
+ echo $"Stop $command"
+ fi
fi
done
)
cat $TMP1 | ( while read x; do
if ! grep -q "^$x" $TMP2; then
$x
- echo "Start $x"
+ echo $"Start $x"
fi
done )
rm -f $TMP1 $TMP2
@@ -189,9 +311,13 @@ case "$1" in
status)
status
;;
+ condrestart)
+ [ -f /var/lock/subsys/autofs ] && redhat restart
+ RETVAL=0
+ ;;
*)
- echo "Usage: $initdir/autofs {start|stop|restart|reload|status}"
- exit 1
+ echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
+ RETVAL=0
esac
}
@@ -256,10 +382,11 @@ case "$1" in
esac
}
+RETVAL=0
if [ $system = debian ]; then
debian "$@"
elif [ $system = redhat ]; then
redhat "$@"
fi
-exit 0
+exit $RETVAL