]> git.pld-linux.org Git - packages/autofs.git/blob - autofs.init
Standarized all rc scripts.
[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:  automount
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 # Get service config
23 [ -f /etc/sysconfig/inetd ] && . /etc/sysconfig/inetd
24
25 # Check that networking is up.
26 [ "${NETWORKING}" = "no" ] && echo "Error: Networking is down"; exit 0
27
28
29 #       We can add local options here
30 #       e.g. localoptions='rsize=8192,wsize=8192'
31 #
32 localoptions=''
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                 # special: treat -t or --timeout (or any reasonable derivative)
54                 # specially, since it can't be made a normal mount option.
55                 if echo $options | grep -- '-t' >/dev/null 2>&1 ; then
56                     mountoptions="--timeout $(echo $options | \
57                       sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
58                 fi
59                 options=`echo "$options" | sed -e '
60                   s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
61                   s/\(^\|[ \t]\)-/\1/g'`
62                 if [ -x $map ]; then
63                     echo "/usr/sbin/automount $mountoptions $dir program $map $options $localoptions"
64                 elif [ -f $map ]; then
65                     echo "/usr/sbin/automount $mountoptions $dir file $map $options $localoptions"
66                 else
67                     echo "/usr/sbin/automount $mountoptions $dir `basename $map` $options $localoptions"
68                 fi
69             fi
70         done
71     )
72 fi
73
74 #
75 #       Check for YellowPage maps to be loaded
76 #
77 if [ -e /usr/bin/ypcat ] && [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ]
78 then
79     ypcat -k auto.master | (
80         while read dir map options
81         do
82             if [ ! -z "$dir" -a ! -z "$map" \
83                         -a x`echo "$map" | cut -c1` != 'x-' ]
84             then
85                 map=`echo "$map" | sed -e 's/^auto_/auto./'`
86                 if echo $options | grep -- '-t' >/dev/null 2>&1 ; then
87                     mountoptions="--timeout $(echo $options | \
88                       sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
89                 fi
90                 options=`echo "$options" | sed -e '
91                   s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
92                   s/\(^\|[ \t]\)-/\1/g'`
93                 echo "/usr/sbin/automount $mountoptions $dir yp $map $options $localoptions"
94             fi
95         done
96     )
97 fi
98 }
99
100 #
101 #       See how we were called.
102 #
103 case "$1" in
104   start)
105         # Check if the service is already running?
106         if [ ! -f /var/lock/subsys/automount ]; then
107                 show Starting automounter
108                 busy
109                 getmounts | sh
110                 deltext
111                 ok
112         else
113             echo "automount already is running"
114         fi
115         touch /var/lock/subsys/automount
116         ;;
117   stop)
118         show Stopping automounter
119         killproc automount -TERM
120         rm -f /var/lock/subsys/automount
121         ;;
122   restart|reload)
123         if [ ! -f /var/lock/subsys/automount ]; then
124                 echo "Automounter not running"
125                 exit 1
126         fi
127         $0 stop
128         $0 start
129         ;;
130   status)
131         echo "Configured Mount Points:"
132         getmounts
133         echo ""
134         echo "Active Mount Points:"
135         ps ax|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
136                 while read pid tt stat time command; do echo $command; done
137         )
138         ;;
139   *)
140         echo "Usage: $0 {start|stop|restart|reload|status}"
141         exit 1
142 esac
143
144 exit 0
This page took 0.101209 seconds and 3 git commands to generate.