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