]> git.pld-linux.org Git - packages/autofs.git/blob - autofs.init
- Added the option for turning on and off the use of YP
[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_no "${NETWORKING}"; then
27         # nls "ERROR: Networking is down. %s can't be run." <service>
28         msg_network_down automounter
29         exit 1
30 fi
31                         
32 DAEMON=/usr/sbin/automount
33
34 #
35 #       This function will build a list of automount commands to execute in
36 #       order # to activate all the mount points. It is used to figure out
37 #       the difference of automount points in case of a reload
38 #
39 getmounts()
40 {
41 #
42 # Check for local maps to be loaded
43 #
44 if [ -f /etc/autofs/auto.master ]
45 then
46     cat /etc/autofs/auto.master | sed -e '/^#/d' -e '/^$/d'| (
47         while read dir map options
48         do
49             if [ ! -z "$dir" -a ! -z "$map" \
50                         -a x`echo "$map" | cut -c1` != 'x-' ]
51             then
52                 map=`echo "/etc/autofs/$map" | sed -e 's:^/etc\/autofs//:/:'`
53                 options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'`
54                 if [ -x $map ]; then
55                     echo "$DAEMON --timeout $TIMEOUT $dir program $map $options"
56                 elif [ -f $map ]; then
57                     echo "$DAEMON --timeout $TIMEOUT $dir file $map $options"
58                 else
59                     echo "$DAEMON --timeout $TIMEOUT $dir `basename $map` $options"
60                 fi
61             fi
62         done
63     )
64 fi
65
66 #
67 # Check for YellowPage maps to be loaded
68 #
69 if is_yes $USE_YP; then 
70 if [ -e /usr/bin/ypcat ] && [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ]
71 then
72     ypcat -k auto.master | (
73         while read dir map options
74         do
75             if [ ! -z "$dir" -a ! -z "$map" \
76                         -a x`echo "$map" | cut -c1` != 'x-' ]
77             then
78                 map=`echo "$map" | sed -e 's/^auto_/auto./'`
79                 if echo $options | grep -- '-t' >/dev/null 2>&1 ; then
80                     mountoptions="--timeout $(echo $options | \
81                       sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
82                 fi
83                 options=`echo "$options" | sed -e '
84                   s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
85                   s/\(^\|[ \t]\)-/\1/g'`
86                 echo "$DAEMON --timeout $TIMEOUT $mountoptions $dir yp $map $options"
87             fi
88         done
89     )
90 fi
91 fi
92 }
93
94 #
95 #       See how we were called.
96 #
97 case "$1" in
98   start)
99         # Check if the service is already running?
100         if [ ! -f /var/lock/subsys/autofs ]; then
101                 msg_starting automounter
102                 busy
103                 if getmounts | sh; then
104                     deltext;ok
105                 else
106                     deltext;ok
107                 fi
108                 RETVAL=$?
109                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/autofs
110         else
111                 msg_already_running automounter
112                 exit 1
113         fi
114         ;;
115   stop)
116         if [ -f /var/lock/subsys/autofs ]; then
117                 msg_stopping automount -TERM
118                 killproc automount
119                 rm -f /var/lock/subsys/autofs >/dev/null 2>&1
120         else
121                 msg_not_running automounter
122                 exit 1
123         fi
124         ;;
125   restart|reload)
126         $0 stop
127         $0 start
128         ;;
129   status)
130         echo "Configured Mount Points:"
131         getmounts
132         echo ""
133         echo "Active Mount Points:"
134         ps axw|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
135                 while read pid tt stat time command; do echo $command; done
136         )
137         ;;
138   *)
139         msg_usage "$0 {start|stop|restart|reload|status}"
140         exit 1
141 esac
142
143 exit $RETVAL
This page took 0.039722 seconds and 3 git commands to generate.