]> git.pld-linux.org Git - packages/autofs.git/blob - autofs.init
- outdated (I assume)
[packages/autofs.git] / autofs.init
1 #!/bin/sh
2 #
3 # autofs        automatically mounts filesystems when you use them,
4 #               and unmounts them later when you are not using them.
5 #
6 # chkconfig:    2345 72 08
7 #
8 # description:  Script for automount using a Sun-style "master map". \
9 #               We first look for a local /etc/autofs/auto.master, then a YP \
10 #               map with that name
11 #
12 # processname:  autofs
13 # config:       /etc/autofs/auto.master
14
15
16 # Source function library
17 . /etc/rc.d/init.d/functions
18
19 # Get network config
20 . /etc/sysconfig/network
21
22 # Demon specified configuration.
23 [ -f /etc/sysconfig/autofs ] && . /etc/sysconfig/autofs
24
25 # Check that networking is up.
26 if is_yes "${NETWORKING}"; then
27         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
28                 # nls "ERROR: Networking is down. %s can't be run." <service>
29                 msg_network_down automounter
30                 exit 1
31         fi
32 else
33         exit 0
34 fi
35                         
36 DAEMON=/usr/sbin/automount
37
38 #
39 #       This function will build a list of automount commands to execute in
40 #       order # to activate all the mount points. It is used to figure out
41 #       the difference of automount points in case of a reload
42 #
43 getmounts()
44 {
45 #
46 # Check for local maps to be loaded
47 #
48 if [ -f /etc/autofs/auto.master ]; then
49         cat /etc/autofs/auto.master | sed -e '/^#/d' -e '/^$/d'| (
50         while read dir map options; do
51                 if [ ! -z "$dir" -a ! -z "$map" \
52                    -a x`echo "$map" | cut -c1` != 'x-' ]; then
53                         maptype=`echo $map | cut -f1 -d:`
54                         if [ "$maptype" = "$map" ]; then
55                         map=`echo "/etc/autofs/$map" | sed -e 's:^/etc\/autofs//:/:'`
56                         options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'`
57                         if [ -x $map ]; then
58                                 echo "$DAEMON --timeout $TIMEOUT $dir program $map $options"
59                         elif [ -f $map ]; then
60                                 echo "$DAEMON --timeout $TIMEOUT $dir file $map $options"
61                         else
62                                 echo "$DAEMON --timeout $TIMEOUT $dir `basename $map` $options"
63                         fi
64                         else
65                                 map=`echo $map | cut -f2- -d:`
66                                 if [ ! -z "$map" ]; then
67                                         if [ "$maptype" = "file" ]; then
68                                                 map=`echo "/etc/autofs/$map" | sed -e 's:^/etc\/autofs//:/:'`
69                                         fi
70                                         echo "$DAEMON --timeout $TIMEOUT $dir $maptype $map $options"
71                                 fi
72                         fi
73                 fi
74         done
75         )
76 fi
77
78 #
79 # Check for YellowPage maps to be loaded
80 #
81 if is_yes $USE_YP; then 
82         if [ -e /usr/bin/ypcat ] && \
83            [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ]; then
84                 ypcat -k auto.master | (
85                 while read dir map options; do
86                         if [ ! -z "$dir" -a ! -z "$map" \
87                            -a x`echo "$map" | cut -c1` != 'x-' ]; then
88                                 map=`echo "$map" | sed -e 's/^auto_/auto./'`
89                                 if echo $options | \
90                                    grep -- '-t' >/dev/null 2>&1; then
91                                         mountoptions="--timeout $(echo $options | \
92                                           sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
93                                 fi
94                                 options=`echo "$options" | sed -e '
95                                   s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
96                                   s/\(^\|[ \t]\)-/\1/g'`
97                                 echo "$DAEMON --timeout $TIMEOUT $mountoptions \
98                                   $dir yp $map $options"
99                         fi
100                 done
101                 )
102         fi
103 fi
104 }
105
106 RETVAL=0
107 # See how we were called.
108 case "$1" in
109   start)
110         # Check if the service is already running?
111         if [ ! -f /var/lock/subsys/autofs ]; then
112                 msg_starting automounter
113                 busy
114                 getmounts | sh 
115                 RETVAL=$?
116                 [ $RETVAL -eq 0 ] && ok || fail
117                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/autofs
118         else
119                 msg_already_running automounter
120         fi
121         ;;
122   stop)
123         if [ -f /var/lock/subsys/autofs ]; then
124                 msg_stopping automounter
125                 killproc automount
126                 rm -f /var/lock/subsys/autofs >/dev/null 2>&1
127         else
128                 msg_not_running automounter
129         fi
130         ;;
131   restart|force-reload)
132         $0 stop
133         $0 start
134         exit $?
135         ;;
136   status)
137         nls "Configured Mount Points:"
138         getmounts
139         echo ""
140         nls "Active Mount Points:"
141         ps axw|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
142                 while read pid tt stat time command; do echo $command; done
143         )
144         ;;
145   *)
146         msg_usage "$0 {start|stop|restart|force-reload|status}"
147         exit 3
148 esac
149
150 exit $RETVAL
This page took 0.075694 seconds and 3 git commands to generate.