#!/sbin/runscript # # $Id: //depot/autofs-4.0/samples/rc.autofs.in#4 $ # # 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 # # On most distributions, this file should be called: # /etc/rc.d/init.d/autofs or /etc/init.d/autofs # # # Location of the automount daemon and the init directory # DAEMON=/usr/sbin/automount initdir=/etc/init.d depend() { need net localmount use ypbind nfs } opts="start stop status stats reload restart" # # We can add local options here # e.g. localoptions='rsize=8192,wsize=8192' # localoptions='' # # Daemon options # e.g. --timeout 60 # daemonoptions='' # # 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//:/:'` options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'` if [ -x $map ]; then echo "$DAEMON $daemonoptions $dir program $map $options $localoptions" elif [ -f $map ]; then echo "$DAEMON $daemonoptions $dir file $map $options $localoptions" else echo "$DAEMON $daemonoptions $dir `basename $map` $options $localoptions" fi 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-' ] 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 "$DAEMON $daemonoptions $mountoptions $dir yp $map $options $localoptions" fi done ) fi } # # Status lister. # stats() { echo "Configured Mount Points:" echo "------------------------" getmounts echo "" echo "Active Mount Points:" echo "--------------------" ps ax|grep "[0-9]:[0-9][0-9] automount " | ( while read pid tt stat time command; do echo $command; done ) } # return true if at least one pid is alive function alive() { if [ -z "$*" ]; then return 1 fi for i in $*; do if kill -0 $i 2> /dev/null; then return 0 fi done return 1 } start() { # LLA: take from debian ebegin "Starting automounter" getmounts | while read cmd mnt rest do echo -n " $mnt" pidfile=/var/run/autofs`echo $mnt | sed 's/\//./'`.pid # LLA echo "start-stop-daemon --start --pidfile $pidfile --quiet --exec $DAEMON $daemonoptions -- $mnt $rest --timeout=0 " # LLA: timeout hack start-stop-daemon --start --pidfile $pidfile --quiet \ --exec $DAEMON $daemonoptions -- $mnt $rest --timeout=0 done echo eend $? } stop() { ebegin "Stopping automounter" start-stop-daemon --stop --quiet --signal USR2 --exec $DAEMON eend $? } reload() { echo "Reloading automounter: checking for changes ... " TMP=/var/run/autofs.tmp getmounts >$TMP for i in /var/run/autofs.*.pid do pid=`head -n 1 $i 2>/dev/null` [ "$pid" = "" ] && continue command=`tail +2 $i` if ! grep -q "^$command" $TMP then echo "Stopping automounter: $command" kill -USR2 $pid fi done rm -f $TMP svc_start } restart() { svc_stop svc_start }