[Lunar-commits] CVS: moonbase/filesys/autofs/init.d autofs, NONE, 1.1

Auke Kok sofar at lunar-linux.org
Wed Feb 4 15:56:38 GMT 2004


Update of /var/cvs/lunar/moonbase/filesys/autofs/init.d
In directory dbguin.lunar-linux.org:/tmp/cvs-serv30256/autofs/init.d

Added Files:
	autofs 
Log Message:
Adding fully working automount daemon module, which installs the userspace automounter. Works perfectly, in production here in a NIS/nfs environment.


--- NEW FILE: autofs ---
#!/bin/bash                                                                     #
# 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
#

# For Redhat-ish systems - modyfied to fit lunar-linux by sofar
#
# chkconfig: 345 32 68
# processname: /usr/sbin/automount
# config: /etc/auto.master
# description: Automounts filesystems on demand

# This is used in the Debian distribution to determine the proper
# location for the S- and K-links to this init file.
# The following value is extracted by debstd to figure out how to
# generate the postinst script. Edit the field to change the way the
# script is registered through update-rc.d (see the manpage for
# update-rc.d!)

FLAGS="defaults 21"

#
# Location of the automount daemon and the init directory
#
DAEMON=/usr/sbin/automount
prog=`basename $DAEMON`
initdir=/etc/init.d

test -e $DAEMON || exit 0

#
# We can add local options here
# e.g. localoptions='rsize=8192,wsize=8192'
#
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()
{
    /usr/lib/autofs/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
# the difference of automount points in case of a reload
#
function getmounts()
{
        knownmaps=" "
        getrawmounts | (
        while read dir map options
        do
            # 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
            if [ ! -z "$dir" -a ! -z "$map" \
                        -a x`echo "$map" | cut -c1` != 'x-' \
                        -a "`echo "$knownmaps" | grep $dir/`" = "" ]
            then
                # 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
                # 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
    )
}

#
# Status lister.
#
function status()
{
        echo $"Configured Mount Points:"
        echo  "------------------------"
        getmounts
        echo ""
        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
        )
}


        ESC=`echo -en "\033"`
  RESULT_OK="${ESC}[\061;32m${ESC}[70G[\040\040\040OK\040\040\040]${ESC}[m"
RESULT_FAIL="${ESC}[\061;31m${ESC}[70G[\040FAILED\040]${ESC}[m"
RESULT_WARN="${ESC}[\061;33m${ESC}[70G[\040\040WARN\040\040]${ESC}[m"
JUNK="]]]]]]"

success() {
  echo -e "$@$RESULT_OK"
}

failure() {
  echo -e "$@$RESULT_FAIL"
}

#
# See how we were called.
#
case "$1" in
  start)
        # 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/autofs
        else
            echo -n "" $"No Mountpoints Defined"
            success "$prog startup"
        fi
        rm -f $TMP
        ;;
  stop)
        echo -n $"Stopping $prog: "
        if [ -z "`pidof $prog`" -a -z "`getmounts`" ]; then
                success $"$prog shutdown"
                RETVAL=0
        else
                kill -USR2 `pidof $DAEMON`
                RETVAL=$?
        fi
        count=0
        while [ -n "`pidof $DAEMON`" -a $count -lt 8 ] ; do
            kill -USR2 `pidof $DAEMON`
            RETVAL=$?
            [ $RETVAL = 0 -a -z "`pidof $DAEMON`" ] || sleep ${count+1}
            count=`expr $count + 1`
        done
        umount -a -f -t autofs
        rm -f /var/lock/autofs
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  reload)
        if [ ! -f /var/lock/autofs ]; then
                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 axwww|grep "[0-9]:[0-9][0-9] $DAEMON" | (
            while read pid tt stat time command; do
                echo "$command" >>$TMP2
                if ! grep -q "^$command" $TMP1; then
                    if ! echo "$command" | grep -q -e --submount; then
                        kill -USR2 $pid
                        echo $"Stop $command"
                    fi
                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)
        status
        ;;
  condrestart)
        [ -f /var/lock/autofs ] && $0 restart
        RETVAL=0
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
        RETVAL=0
esac

RETVAL=0
exit $RETVAL



More information about the Lunar-commits mailing list