1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-fs/autofs/files/autofs.rc11,v 1.1 2005/03/15 04:18:38 robbat2 Exp $
# rc file for automount using a Sun-style "master map".
# We first look for a local /etc/autofs/auto.master, then a YP
# map with that name
DAEMON=/usr/sbin/automount
depend() {
need localmount
use ypbind nfs slapd portmap net
}
opts="start stop status stats reload restart"
# this file is used to avoid the subshell-die problem
TMPSRC=/var/run/autofs.tmp
#
# Check for all maps that are to be loaded
#
function getschemes()
{
awk '/^automount:/{ $1="" ; gsub("\\[.*\\]","") ; print $0 }' /etc/nsswitch.conf
}
function getfilemounts()
{
if [ -f /etc/autofs/auto.master ] ; then
sed -e '/^#/d' -e '/^$/d' < /etc/autofs/auto.master
fi
}
function getnismounts()
{
/usr/bin/ypcat -k ${nis_mapname} 2> /dev/null | sed -e '/^#/d' -e '/^$/d'
}
function getldapmounts()
{
autofs_lam=/usr/lib/autofs/autofs-ldap-auto-master
if [ -f $autofs_lam -a -x $autofs_lam ]; then
${autofs_lam} \
-m ${ldap_map_oc} -e ${ldap_entry_oc} \
-n ${ldap_map_key} -k ${ldap_entry_key} \
-v ${ldap_value} 2> /dev/null
fi
}
function getrawmounts()
{
for scheme in `getschemes` ; do
case "$scheme" in
files)
getfilemounts
;;
nis*)
getnismounts
;;
ldap*)
getldapmounts
;;
esac
done
}
#
# This function will build a list of automount commands to execute in
# order to activate all the mount points. It is used to figure out
# the difference of automount points in case of a reload
#
function getmounts()
{
knownmaps=" "
# seperate storage variable to avoid clobbering the other $TMPSRC
TMPSRC_mounts="$TMPSRC.mounts"
getrawmounts >$TMPSRC_mounts
while read dir map options
do
# These checks screen out duplicates and skip over directories
# where the map is '-'.
if [ ! -z "$dir" -a ! -z "$map" \
-a "x${map:0:1}" != "x-" \
-a "`echo "$knownmaps" | grep -w $dir/`" = "" ]; then
# If the options include a -t or --timeout parameter, then
# pull those particular options out.
# echo DAEMONOPTIONS OPTIONS $daemonoptions $options
startupoptions=""
opt_timeout=""
opt_pidfile=""
opt_verbose=""
opt_debug=""
opt_ghost=""
# use getopt to parse all of it
#getopteval="$(getopt -q -o -t:p:vdg --long timeout:,pid-file:,verbose,debug,ghost -- "$daemonoptions $options") "
getopt_input="$daemonoptions $options"
getopt_eval="$(getopt -q -o -t:vdg --long timeout:,verbose,debug,ghost -- $getopt_input) "
eval set -- "${getopt_eval}"
while [ -n "$1" ]; do
#-p|--pid-file) opt_pidfile="$2" ; shift 2 ;;
case $1 in
-t|--timeout) opt_timeout="$2" ; shift 2 ;;
-v|--verbose) opt_verbose="--verbose" ; shift ;;
-d|--debug) opt_debug="--debug" ; shift ;;
-g|--ghost) opt_ghost="--ghost" ; shift ;;
--) shift ; break ;;
*) shift ;; # just ignore other params for now
esac
done
# build the parameters
[ -n "${opt_timeout}" ] && startupoptions="${startupoptions} --timeout ${opt_timeout}"
#[ -n "${opt_pidfile}" ] && startupoptions="${startupoptions} --pid-file ${opt_pidfile}"
startupoptions="${startupoptions} ${opt_ghost} ${opt_verbose} ${opt_debug}"
# Other option flags are intended for maps.
# unfortuntely this can't be integrated with the above getopt(1)
mapoptions="$(echo $daemonoptions $options | sed \
-e '/-t/{s/--*t\(imeout\)*[[:space:]=]*\([0-9][0-9]*\)//g }' \
-e '/-v/{s/--*v\(erbose\)*//g }' \
-e '/-d/{s/--*d\(ebug\)*//g }' \
-e '/-g/{s/--*g\(host\)*//g }' \
-e 's/^[[:space:]]*//g' \
-e 's/[[:space:]]*$//g')"
#-e '/-p/{s/--*p\(id-file\)*[[:space:]=]*\([^[:space:]]*\)//g }' \
# Break up the maptype and map, if the map type is specified
maptype="${map/:*}"
# Handle degenerate map specifiers
if [ "$maptype" = "$map" ] ; then
if [ -x "$map" ]; then
maptype="program"
elif [ -x "/etc/$map" ]; then
maptype="program"
map="/etc/$map"
map="${map//\/\//\/}" # strip doubles
elif [ -f "$map" ]; then
maptype="file"
elif [ -f "/etc/$map" ]; then
maptype="file"
map="/etc/$map"
map="${map//\/\//\/}" # strip doubles
elif [ "$map" = "hesiod" -o "$map" = "userhome" ] ; then
maptype="$map"
map=
elif [ "$map" = "multi" ] ; then
maptype="$map"
map=
else
maptype=yp
map="${map/*\/}" # same as "basename $map"
map="${map/#auto_/auto.}" # echo $map | sed -e 's/^auto_home/auto.home/' -e 's/^auto_mnt/auto.mnt/'
fi
fi
map="${map#*:}"
#echo >>/tmp/debug
#date >>/tmp/debug
#echo STARTUPOPTIONS $startupoptions >> /tmp/debug
#echo DIR $dir >> /tmp/debug
#echo MAPTYPE $maptype >> /tmp/debug
#echo MAP $map >> /tmp/debug
#echo MAPOPTIONS $mapoptions >> /tmp/debug
#echo LOCALOPTIONS $localoptions >> /tmp/debug
#echo OPTIONS $options >>/tmp/debug
#echo GETOPT_INPUT $getopt_input >>/tmp/debug
[ -z "${startupoptions}" ] && startupoptions=" " # to make life easier later
# protect startupoptions with _X_ to use it later
cmdline="$DAEMON ${startupoptions// /_X_} $dir $maptype $map ${mapoptions} ${localoptions}"
# leave out the " so that white space gets compressed
echo ${cmdline}
# echo ------------------------
fi
knownmaps=" $dir/ $knownmaps"
done <$TMPSRC_mounts
rm -f $TMPSRC_mounts
}
start() {
ebegin "Starting automounter"
# ensure autofs support is loaded
grep -q autofs /proc/filesystems || modprobe -q autofs4 || modprobe -q autofs
if [ $? -ne 0 ]; then
eend 1 "No autofs support available"
return 1
fi
getmounts >$TMPSRC
# Check that maps exist
if [ ! -s $TMPSRC ]; then
eend 1 "No automount maps defined"
return 1
fi
while read cmd startupopts mnt rest ; do
pidfile=/var/run/autofs${mnt//\//.}.pid
startupopts="$(echo ${startupopts//_X_/ } --pid-file ${pidfile} )"
bin="/usr/sbin/automount"
params="$(echo $startupopts $mnt $rest)"
echo -n " $mnt"
#echo " $mnt ($params)"
start-stop-daemon --start --pidfile $pidfile --quiet \
--exec ${bin} -- ${params}
#ps ax | grep "[0-9]:[0-9][0-9] ${bin} ${params}" | (
# read pid rest
# echo $pid > $pidfile
# echo "$mnt $rest" >> $pidfile
#)
if [ $? -ne 0 ]; then
eerror "Failure on $mnt"
else
echo "${params}" >> $pidfile
fi
done < $TMPSRC
# clean up
rm -f $TMPSRC
echo
eend $?
}
stop() {
ebegin "Stopping automounter"
start-stop-daemon --stop --quiet --signal USR2 --exec /usr/sbin/automount
eend $?
}
stats() {
echo "Configured Mount Points:"
echo "------------------------"
getmounts >$TMPSRC
while read cmd startupopts mnt rest ; do
pidfile=/var/run/autofs${mnt//\//.}.pid
startupopts="$(echo ${startupopts//_X_/ } --pid-file ${pidfile} )"
params="$(echo $startupopts $mnt $rest)"
echo $cmd $params
done <$TMPSRC
rm -f $TMPSRC
echo ""
echo "Active Mount Points:"
echo "--------------------"
ps ax|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
while read pid tt stat time command; do echo $command; done
)
}
reload() {
echo "Reloading automounter: checking for changes ... "
getmounts >$TMPSRC
for i in /var/run/autofs.*.pid
do
pid=`head -n 1 $i 2>/dev/null`
[ -z "$pid" ] && continue
command=`tail -n +2 $i`
if ! grep -q "^$command" $TMPSRC
then
echo "Stopping automounter: $command"
kill -USR2 $pid
fi
done
rm -f $TMPSRC
svc_start
}
restart() {
svc_stop
svc_start
}
|