1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # Autofs Boot Script
|
---|
4 | #
|
---|
5 | # Filename: /etc/rc.d/init.d/autofs
|
---|
6 | #
|
---|
7 | # Author: Bryan Mason <bmason@bmason.com>
|
---|
8 | #
|
---|
9 | # Edit History:
|
---|
10 | #
|
---|
11 | # Date Author Action
|
---|
12 | # ----------------------------------------------------------------------
|
---|
13 | # 20 Jan 2004 B. Mason Created by modifying original autofs
|
---|
14 | # script created by Peter Anvin
|
---|
15 | # 20 Mar 2004 B. Mason Modified to create mountpoints if they
|
---|
16 | # don't already exist.
|
---|
17 |
|
---|
18 | source /etc/sysconfig/rc
|
---|
19 | source $rc_functions
|
---|
20 | source /etc/sysconfig/autofs.conf
|
---|
21 |
|
---|
22 | #
|
---|
23 | # This function will build a list of automount commands to execute in
|
---|
24 | # order to activate all the mount points. It is used to figure out
|
---|
25 | # the difference of automount points in case of a reload
|
---|
26 | #
|
---|
27 | function getmounts()
|
---|
28 | {
|
---|
29 | if [ -f /etc/auto.master ]
|
---|
30 | then
|
---|
31 | cat /etc/auto.master | sed -e '/^#/d' -e '/^$/d'|
|
---|
32 | (
|
---|
33 | while read dir map options
|
---|
34 | do
|
---|
35 | if [ ! -z "$dir" -a ! -z "$map" \
|
---|
36 | -a x$(echo "$map" | cut -c1) != 'x-' ]
|
---|
37 | then
|
---|
38 | map=$(echo "/etc/$map" | sed -e 's:^/etc//:/:')
|
---|
39 | options=$(echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g')
|
---|
40 | if [ -x $map ]; then
|
---|
41 | echo " $dir program $map $options"
|
---|
42 | else
|
---|
43 | echo " $dir file $map $options"
|
---|
44 | fi
|
---|
45 | fi
|
---|
46 | done
|
---|
47 | )
|
---|
48 | fi
|
---|
49 | }
|
---|
50 |
|
---|
51 | #
|
---|
52 | # Show the status of configured and active mounts.
|
---|
53 | #
|
---|
54 | function status()
|
---|
55 | {
|
---|
56 | echo "Configured Mount Points:"
|
---|
57 | getmounts |
|
---|
58 | (
|
---|
59 | while read dir type map options
|
---|
60 | do
|
---|
61 | echo $dir $type $map $options
|
---|
62 |
|
---|
63 | if [ $type = 'file' ]
|
---|
64 | then
|
---|
65 | cat $map | sed -e '/^#/d' -e '/^$/d' |
|
---|
66 | (
|
---|
67 | while read key options location
|
---|
68 | do
|
---|
69 | echo " $key $options $location"
|
---|
70 | done
|
---|
71 | )
|
---|
72 | echo ""
|
---|
73 | fi
|
---|
74 | done
|
---|
75 | )
|
---|
76 |
|
---|
77 | echo "Active Automount Daemons:"
|
---|
78 | if [ $(COLUMNS=1024 ps ax | grep "[0-9]:[0-9][0-9] $automount " | wc -w) -gt 0 ]
|
---|
79 | then
|
---|
80 | COLUMNS=1024 ps ax | grep "[0-9]:[0-9][0-9] $automount " |
|
---|
81 | (
|
---|
82 | while read pid tt stat time command; do echo " $command" ; done
|
---|
83 | )
|
---|
84 | else
|
---|
85 | echo " None";
|
---|
86 | fi
|
---|
87 | echo ""
|
---|
88 |
|
---|
89 | echo "Actively Automounted Directories:"
|
---|
90 | getmounts |
|
---|
91 | (
|
---|
92 | while read dir type map options
|
---|
93 | do
|
---|
94 | line=$(mount | grep -v "^automount" | grep "$dir")
|
---|
95 | if [ $(echo $line | wc -w) -ne 0 ]
|
---|
96 | then
|
---|
97 | echo "$line" | sed -e "s/^./ &/"
|
---|
98 | fi
|
---|
99 | done
|
---|
100 | )
|
---|
101 | echo ""
|
---|
102 | }
|
---|
103 |
|
---|
104 | case "$1" in
|
---|
105 | start)
|
---|
106 | getmounts |
|
---|
107 | (
|
---|
108 | while read dir type map options
|
---|
109 | do
|
---|
110 | boot_mesg -n "Automounting $dir..."
|
---|
111 | pidfile=$(echo $dir | sed -e "y/\//-/" | sed -e "s/^-//")
|
---|
112 | pidpath=${piddir}/${pidroot}.${pidfile}.pid
|
---|
113 |
|
---|
114 | if [ ! -d "$dir" ]
|
---|
115 | then
|
---|
116 | boot_mesg -n " Creating mountpoint $dir..."
|
---|
117 | mkdir -p "$dir"
|
---|
118 | fi
|
---|
119 |
|
---|
120 | if [ ! -e "$map" ]
|
---|
121 | then
|
---|
122 | boot_mesg "Map file $map does not exist!" ${FAILURE}
|
---|
123 | echo_failed
|
---|
124 | continue
|
---|
125 | fi
|
---|
126 |
|
---|
127 | if [ ! -x "$map" -a "$type" = "program" ]
|
---|
128 | then
|
---|
129 | boot_mesg "Map file $map is not executable!" ${FAILURE}
|
---|
130 | echo_failed
|
---|
131 | continue
|
---|
132 | fi
|
---|
133 |
|
---|
134 | if [ -e "$pidpath" ]
|
---|
135 | then
|
---|
136 | boot_mesg " already running!" ${WARNING}
|
---|
137 | echo_warning
|
---|
138 | else
|
---|
139 | echo " "
|
---|
140 | $automount -p $pidpath $daemonoptions $dir $type $map $options $localoptions
|
---|
141 | evaluate_retval
|
---|
142 | fi
|
---|
143 | done
|
---|
144 | )
|
---|
145 | ;;
|
---|
146 |
|
---|
147 | stop)
|
---|
148 | # Kill all automounters listed in /run
|
---|
149 | ls ${piddir}/${pidroot}.*.pid 2>/dev/null |
|
---|
150 | (
|
---|
151 | while read pidpath
|
---|
152 | do
|
---|
153 | pid=$(cat $pidpath)
|
---|
154 | pidfile=$(basename $pidpath)
|
---|
155 | mountpoint=$(echo $pidfile | sed -e "s/^autofs\.\(.*\)\.pid$/\1/" | sed -e "y/-/\//")
|
---|
156 | boot_mesg "Stopping automount on /$mountpoint..."
|
---|
157 | kill $pid
|
---|
158 | evaluate_retval
|
---|
159 | done
|
---|
160 | )
|
---|
161 |
|
---|
162 | # Now kill any rogue automounters (automount process w/o pid files)
|
---|
163 | sleep 1
|
---|
164 | COLUMNS=1024 ps ax | grep "[0-9]:[0-9][0-9] $automount " |
|
---|
165 | (
|
---|
166 | while read pid everything_else
|
---|
167 | do
|
---|
168 | boot_mesg "Stopping automount with pid $pid..."
|
---|
169 | kill $pid
|
---|
170 | evaluate_retval
|
---|
171 | done
|
---|
172 | )
|
---|
173 | ;;
|
---|
174 |
|
---|
175 | restart)
|
---|
176 | $0 stop
|
---|
177 | sleep 1
|
---|
178 | $0 start
|
---|
179 | ;;
|
---|
180 |
|
---|
181 | status)
|
---|
182 | status
|
---|
183 | ;;
|
---|
184 |
|
---|
185 | *)
|
---|
186 | echo "usage: $0 {start|stop|restart|status}"
|
---|
187 | exit 1
|
---|
188 | ;;
|
---|
189 | esac
|
---|
190 |
|
---|
191 |
|
---|
192 | # END
|
---|
193 |
|
---|