[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[plamo:09986] Re: autofsの使い方



From: 立川純 <tachi@mickey.ai.kyutech.ac.jp>
Message-Id: <20010531210750.2c90d833.tachi@mickey.ai.kyutech.ac.jp>

> autofs関連について質問なのですが,NISと組み合わせたときのautomountの
> 使い方がいまいち分かりません.

> 結局,/etc/rc.d/rc.autofs にあたるスクリプトの書き方が分からないとい
> う状況です.
> RedHat系のスクリプトでは,ypcat をつかって automount を起動している
> ようですが,

autofs-4.0.0 のソースに rc.autofs が含まれていますが、RedHatやDebianで
ないと動きませんので、これを Slackware系用に書き換えたものを使っていま
す。添付しておきますので、よろしかったらどうぞ。

/etc/rc.d/rc.autofs start とすると、/etc/auto.master を読んで、適宜
automountを実行します。

私はypcatとの連携法を知りませんが、/etc/auto.master の記法は Solaris
互換のはずなので、おそらくなんとかなるでしょう。
_______________________________
田原 俊一   jado@flowernet.gr.jp, shunichi_tahara@zenrin.co.jp
                                  http://flowernet.gr.jp/jado/
FingerPrint:  16 9E 70 3B 05 86 5D 08  B8 4C 47 3A E7 E9 8E D9
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
#! /bin/bash
#
# $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
#

# For Slackware-ish systems

#
# Location of the automount daemon and the init directory
#
DAEMON=/sbin/automount
initdir=/etc/rc.d

test -e $DAEMON || exit 0
thisscript="$0"
if [ ! -f "$thisscript" ]; then
    echo "$0: Cannot find myself" 1>&2
    exit 1
fi

PATH=/sbin:/usr/sbin:/bin:/usr/bin
export PATH

#
# 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 "$dir program $map $options $localoptions"
		elif [ -f $map ]; then
		    echo "$dir file $map $options $localoptions"
		else
		    echo "$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 "$mountoptions $dir yp $map $options $localoptions"
	    fi
	done
    )
fi
}

#
# Status lister.
#
function status()
{
	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
}

#
# Slackware start/stop function.
#
function slack()
{

#
# See how we were called.
#
case "$1" in
  start)
	# Check if the automounter is already running?
	if [ ! -f /var/lock/autofs ]; then
	    echo -n 'Starting automounter:'
	    getmounts | while read mnt rest
	    do
		echo -n " $mnt"
		echo $DAEMON $daemonoptions $mnt $rest | sh
	    done
	    echo .
	    touch /var/lock/autofs
	fi
	;;
  stop)
	echo -n 'Stopping automounter:'
	pids=$(/sbin/pidof $DAEMON)
	ps h $pids | (
	    while read pid tt stat time command mnt rest; do
		echo -n " $mnt"
		kill -TERM $pid 2> /dev/null && sleep 1
	    done
	)
	count=1
	while alive $pids; do
	    sleep 5
	    count=$(expr $count + 1)
	    if [ $count -gt 5 ]; then
		echo " giving up"
		break;
	    fi
	    echo -n " retrying($count)"
	done
	echo .
	rm -f /var/lock/autofs
	;;
  reload|restart)
	if [ ! -f /var/lock/autofs ]; 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; }
	echo -n 'Stopping automounter:'
	getmounts >$TMP1
	ps ax|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
			while kill -USR2 $pid; do
			    sleep 3
			done
			echo -n "$command"
		fi
	    done
	)
	echo .
	echo -n 'Starting automounter:'
	( while read x; do
		if ! grep -q "$x" $TMP2; then
			$DAEMON $daemonoptions $x
			echo -n " $x"
		fi
	done ) < $TMP1
	echo .
	rm -f $TMP1 $TMP2
	;;
  status)
	status
	;;
  *)
	echo "Usage: $initdir/autofs {start|stop|restart|reload|status}"
	exit 1
esac
}

slack "$@"
exit 0

References
[plamo:09983] autofsの使い方, 立川純

[検索ページ] [メール一覧]
Plamo ML 公開システム