3
# $Id: //depot/autofs-4.0/samples/rc.autofs.in#4 $
5
# rc file for automount using a Sun-style "master map".
6
# We first look for a local /etc/auto.master, then a YP
9
# On most distributions, this file should be called:
10
# /etc/rc.d/init.d/autofs or /etc/init.d/autofs
13
# For Redhat-ish systems
15
# chkconfig: 345 15 85
16
# description: Automounts filesystems on demand
18
# This is used in the Debian distribution to determine the proper
19
# location for the S- and K-links to this init file.
20
# The following value is extracted by debstd to figure out how to
21
# generate the postinst script. Edit the field to change the way the
22
# script is registered through update-rc.d (see the manpage for
28
# Location of the automount daemon and the init directory
30
DAEMON=/usr/sbin/automount
34
# Determine which kind of configuration we're using
37
if [ -f /etc/debian_version ]; then
39
elif [ -f /etc/redhat-release ]; then
42
echo "$0: Unknown system, please port and contact autofs@linux.kernel.org" 1>&2
46
if [ $system = redhat ]; then
50
test -e $DAEMON || exit 0
52
if [ ! -f "$thisscript" ]; then
53
echo "$0: Cannot find myself" 1>&2
57
PATH=/sbin:/usr/sbin:/bin:/usr/bin
61
# We can add local options here
62
# e.g. localoptions='rsize=8192,wsize=8192'
73
# This function will build a list of automount commands to execute in
74
# order to activate all the mount points. It is used to figure out
75
# the difference of automount points in case of a reload
79
if ! getmounts_file /etc/auto.master; then
80
if ! getnismounts auto.master; then
81
echo "no autofs mounts configured!" 1>&2
86
function getmounts_file()
89
# Check for local maps to be loaded
95
cat "$map" | sed -e '/^#/d' -e '/^$/d' | process_master_file "$@"
101
function process_master_file()
103
local line_options="$@" daemon_options
104
while read dir map options
106
options="$line_options $options"
108
+*) getnismounts "${dir/+/}" $map $options
111
if [ ! -z "$dir" -a ! -z "$map" \
112
-a x`echo "$map" | cut -c1` != 'x-' ]
117
elif [ -f $map ]; then
119
elif [ x`echo "$map" | cut -c1` == 'x/' ]; then
120
# Starts with '/', thus a file, but doesn't exist
121
# so leave it out, leaving 'type=""' (hro)
123
elif [ -f /etc/$map ]; then
126
elif [ $map == hesiod ]; then
129
elif [ $map == ldap ]; then
134
!*) type=program map="${map/!/}";;
138
daemon_options=`munge_options daemon $daemonoptions $options`
139
options=`munge_options mount $options`
142
echo "$DAEMON $daemon_options -- $dir $type $map $localoptions $options"
148
function getnismounts()
151
# Check for YellowPage maps to be loaded
155
if [ -e /usr/bin/ypcat ] && [ `ypcat -k "$map" 2>/dev/null | wc -l` -gt 0 ]
157
ypcat -k "$map" | process_master_file "$@"
168
ps ax|grep "[0-9]:[0-9][0-9] $DAEMON " |
169
while read pid tt stat time command
180
echo "Configured Mount Points:"
181
echo "------------------------"
182
getmounts | sed 's/ -- / /'
184
echo "Active Mount Points:"
185
echo "--------------------"
189
function munge_options()
193
echo "$@" | awk -v which="$which" '
197
daemon_opts[ "timeout" ] = "timeout"
198
daemon_opts[ "t" ] = "timeout"
203
if ( $1 in daemon_opts ) {
204
daemon[ daemon_opts[ $1 ] ] = $2
210
if ( which ~ "^daemon$" ) {
211
if ( "timeout" in daemon ) {
212
printf "--timeout=%s\n", daemon["timeout"]
227
# return true if at least one pid is alive
234
if kill -0 $i 2> /dev/null; then
243
# Redhat start/stop function.
249
# See how we were called.
253
# Check if the automounter is already running?
254
if [ ! -f /var/lock/subsys/autofs ]; then
255
echo 'Starting automounter: '
256
getmounts | sed 's/ -- / /' | sh
257
touch /var/lock/subsys/autofs
261
pids=$(/sbin/pidof $DAEMON)
262
kill -TERM $pids 2> /dev/null && sleep 1
264
while alive $pids; do
266
count=$(expr $count + 1)
267
if [ $count -gt 5 ]; then
268
echo "Giving up on automounter"
271
echo "Automounter not stopped yet: retrying... (attempt $count)"
273
if [ $count -gt 1 -a $count -le 5 ]; then
274
echo "Automounter stopped"
276
rm -f /var/lock/subsys/autofs
279
if [ ! -f /var/lock/subsys/autofs ]; then
280
echo "Automounter not running"
283
echo "Checking for changes to /etc/auto.master ...."
284
TMP1=`mktemp /tmp/autofs.XXXXXX` || { echo "could not make temp file" >& 2; exit 1; }
285
TMP2=`mktemp /tmp/autofs.XXXXXX` || { echo "could not make temp file" >& 2; exit 1; }
286
getmounts | sed 's/ -- / /' >$TMP1
287
ps ax|grep "[0-9]:[0-9][0-9] $DAEMON " | (
288
while read pid tt stat time command; do
289
echo "$command" >>$TMP2
290
if ! grep -q "^$command" $TMP2; then
291
while kill -USR2 $pid; do
299
if ! grep -q "^$x" $TMP2; then
317
echo "Usage: $initdir/autofs {start|stop|restart|reload|status|getmounts|active}"
323
# Debian start/stop functions.
328
# See how we were called.
332
echo -n 'Starting automounter: '
333
getmounts | while read cmd args
340
if [ ! -d /var/run/autofs ]; then
341
mkdir /var/run/autofs
343
pidfile=/var/run/autofs/`echo $mnt | sed 's,_,__,g;s,/,_:,g'`.pid
344
start-stop-daemon --start --pidfile $pidfile --quiet \
345
--exec $DAEMON -- $opt $mnt $rest
350
echo -n 'Stopping automounter: '
351
start-stop-daemon --stop --quiet --signal USR2 --exec $DAEMON
352
for file in /var/run/autofs/*.pid
356
pid=`head -n 1 $file`
357
command=`tail -n 1 $file`
358
if [ -z "`ps --no-heading $pid`" ]
360
echo -n "Stopped $pid($command) "
363
echo -n "Couldn't stop $pid($command) "
370
echo -n "Reloading automounter: checking for changes ... "
371
TMP=/var/run/autofs.tmp
372
getmounts | sed 's/ -- / /' >$TMP
373
for i in /var/run/autofs/*.pid
375
pid=`head -n 1 $i 2>/dev/null`
376
[ "$pid" = "" ] && continue
378
if ! grep -q "^$command" $TMP
380
echo -n "Stopping automounter: $command"
389
force-reload|restart)
397
getmounts | sed 's/ -- / /'
403
echo "Usage: $initdir/autofs {start|stop|restart|reload|force-reload|status|getmounts|active}" >&2
409
if [ $system = debian ]; then
411
elif [ $system = redhat ]; then