]> git.pld-linux.org Git - packages/autofs.git/blob - autofs.init
s-/usr/sbin-%{_sbindir}-
[packages/autofs.git] / autofs.init
1 #!/bin/sh
2 #
3 #       $Id$
4 #
5 #       /etc/rc.d/init.d/autofs
6 #
7 #       rc file for automount using a Sun-style "master map".
8 #       We first look for a local /etc/autofs/auto.master, then a YP
9 #       map with that name
10 #
11 # chkconfig: - 72 08
12 # description: automatically mounts filesystems when you use \
13 #   them, and unmounts them later when you are not using them.
14 # processname: automount
15 #   Note that there may be multiple processes names automount
16 # config: /etc/autofs/auto.master
17 #   Note that all other config files are automatically reloaded
18 #   and may be different on different systems; we can ignore them
19 #   here
20
21 # Source function library.
22 . /etc/rc.d/init.d/functions
23
24 [ -f /usr/sbin/automount ] || exit 0
25
26 #
27 #       We can add local options here
28 #       e.g. localoptions='rsize=8192,wsize=8192'
29 #
30 localoptions=''
31
32 #
33 #       This function will build a list of automount commands to execute in
34 #       order # to activate all the mount points. It is used to figure out
35 #       the difference of automount points in case of a reload
36 #
37 function getmounts()
38 {
39 #
40 #       Check for local maps to be loaded
41 #
42 if [ -f /etc/autofs/auto.master ]
43 then
44     cat /etc/autofs/auto.master | sed -e '/^#/d' -e '/^$/d'| (
45         while read dir map options
46         do
47             if [ ! -z "$dir" -a ! -z "$map" \
48                         -a x`echo "$map" | cut -c1` != 'x-' ]
49             then
50                 map=`echo "/etc/autofs/$map" | sed -e 's:^/etc/autofs/:/:'`
51                 # special: treat -t or --timeout (or any reasonable derivative)
52                 # specially, since it can't be made a normal mount option.
53                 if echo $options | grep -- '-t' >/dev/null 2>&1 ; then
54                     mountoptions="--timeout $(echo $options | \
55                       sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
56                 fi
57                 options=`echo "$options" | sed -e '
58                   s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
59                   s/\(^\|[ \t]\)-/\1/g'`
60                 if [ -x $map ]; then
61                     echo "/usr/sbin/automount $mountoptions $dir program $map $options $localoptions"
62                 elif [ -f $map ]; then
63                     echo "/usr/sbin/automount $mountoptions $dir file $map $options $localoptions"
64                 else
65                     echo "/usr/sbin/automount $mountoptions $dir `basename $map` $options $localoptions"
66                 fi
67             fi
68         done
69     )
70 fi
71
72 #
73 #       Check for YellowPage maps to be loaded
74 #
75 if [ -e /usr/bin/ypcat ] && [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ]
76 then
77     ypcat -k auto.master | (
78         while read dir map options
79         do
80             if [ ! -z "$dir" -a ! -z "$map" \
81                         -a x`echo "$map" | cut -c1` != 'x-' ]
82             then
83                 map=`echo "$map" | sed -e 's/^auto_/auto./'`
84                 if echo $options | grep -- '-t' >/dev/null 2>&1 ; then
85                     mountoptions="--timeout $(echo $options | \
86                       sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
87                 fi
88                 options=`echo "$options" | sed -e '
89                   s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
90                   s/\(^\|[ \t]\)-/\1/g'`
91                 echo "/usr/sbin/automount $mountoptions $dir yp $map $options $localoptions"
92             fi
93         done
94     )
95 fi
96 }
97
98 #
99 #       See how we were called.
100 #
101 case "$1" in
102   start)
103         # Check if the automounter is already running?
104         if [ ! -f /var/lock/subsys/automount ]; then
105             show Starting automounter
106             busy
107             getmounts | sh
108             touch /var/lock/subsys/automount
109             deltext
110             ok
111         fi
112         ;;
113   stop)
114         show Stopping automounter
115         busy
116         kill -TERM $(/sbin/pidof /usr/sbin/automount)
117         rm -f /var/lock/subsys/automount
118         deltext
119         ok
120         ;;
121   reload|restart)
122         if [ ! -f /var/lock/subsys/automount ]; then
123                 echo "Automounter not running"
124                 exit 1
125         fi
126         echo "Checking for changes to /etc/autofs/auto.master ...."
127         TMP1=`mktemp /tmp/autofs.XXXXXX` || { echo "could not make temp file" >&2; exit 1; }
128         TMP2=`mktemp /tmp/autofs.XXXXXX` || { echo "could not make temp file" >&2; exit 1; }
129         getmounts >$TMP1
130         ps ax|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
131             while read pid tt stat time command; do
132                 echo "$command" >>$TMP2
133                 if ! grep -q "^$command" $TMP2; then
134                         kill -USR2 $pid
135                         echo "Stop $command"
136                 fi
137             done
138         )
139         cat $TMP1 | ( while read x; do
140                 if ! grep -q "^$x" $TMP2; then
141                         $x
142                         echo "Start $x"
143                 fi
144         done )
145         rm -f $TMP1 $TMP2
146         ;;
147   status)
148         echo "Configured Mount Points:"
149         getmounts
150         echo ""
151         echo "Active Mount Points:"
152         ps ax|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
153                 while read pid tt stat time command; do echo $command; done
154         )
155         ;;
156   *)
157         echo "Usage: $0 {start|stop|restart|reload|status}"
158         exit 1
159 esac
160
161 exit 0
This page took 0.052331 seconds and 3 git commands to generate.