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