]>
Commit | Line | Data |
---|---|---|
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 | # 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 [ -e /usr/bin/ypcat ] && [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ] | |
70 | then | |
71 | ypcat -k auto.master | ( | |
72 | while read dir map options | |
73 | do | |
74 | if [ ! -z "$dir" -a ! -z "$map" \ | |
75 | -a x`echo "$map" | cut -c1` != 'x-' ] | |
76 | then | |
77 | map=`echo "$map" | sed -e 's/^auto_/auto./'` | |
78 | if echo $options | grep -- '-t' >/dev/null 2>&1 ; then | |
79 | mountoptions="--timeout $(echo $options | \ | |
80 | sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')" | |
81 | fi | |
82 | options=`echo "$options" | sed -e ' | |
83 | s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g | |
84 | s/\(^\|[ \t]\)-/\1/g'` | |
85 | echo "$DAEMON --timeout $TIMEOUT $mountoptions $dir yp $map $options" | |
86 | fi | |
87 | done | |
88 | ) | |
89 | fi | |
90 | } | |
91 | ||
92 | # | |
93 | # See how we were called. | |
94 | # | |
95 | case "$1" in | |
96 | start) | |
97 | # Check if the service is already running? | |
98 | if [ ! -f /var/lock/subsys/automount ]; then | |
99 | msg_starting automounter | |
100 | busy | |
101 | if getmounts | sh; then | |
102 | deltext;ok | |
103 | else | |
104 | deltext;ok | |
105 | fi | |
106 | RETVAL=$? | |
107 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/automount | |
108 | else | |
109 | msg_Already_Running automounter | |
110 | exit 1 | |
111 | fi | |
112 | ;; | |
113 | stop) | |
114 | if [ -f /var/lock/subsys/automount ]; then | |
115 | msg_stopping automount -TERM | |
116 | killproc automount | |
117 | rm -f /var/lock/subsys/automount >/dev/null 2>&1 | |
118 | else | |
119 | msg_Not_Running automounter | |
120 | exit 1 | |
121 | fi | |
122 | ;; | |
123 | restart) | |
124 | $0 stop | |
125 | $0 start | |
126 | ;; | |
127 | status) | |
128 | echo "Configured Mount Points:" | |
129 | getmounts | |
130 | echo "" | |
131 | echo "Active Mount Points:" | |
132 | ps ax|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | ( | |
133 | while read pid tt stat time command; do echo $command; done | |
134 | ) | |
135 | ;; | |
136 | *) | |
137 | msg_Usage: "$0 {start|stop|restart|status}" | |
138 | exit 1 | |
139 | esac | |
140 | ||
141 | exit $RETVAL |