updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / nfs-utils-ipv6 / nfs-common
blob9902ec4c4a21ba7737e3ef2906bf005172cc72ad
1 #!/bin/bash
3 daemon_name=nfs-common
5 # daemon dependencies
6 DAEMON_DEPENDS=('rpcbind')
8 NEED_STATD=
9 STATD_OPTS=
10 NEED_IDMAPD=
11 IDMAPD_OPTS=
12 NEED_GSSD=
13 GSSD_OPTS=
14 PIPEFS_MOUNTPOINT=
15 PIPEFS_MOUNTOPTS=
17 # rpc.statd daemon & binary location
18 STATD_DAEMON_NAME=rpc.statd
19 STATD="/usr/sbin/rpc.statd"
21 # rpc.idmapd daemon & binary location
22 IDMAPD_DAEMON_NAME=rpc.idmapd
23 IDMAPD="/usr/sbin/rpc.idmapd"
25 # rpc.gssd daemon & binary location
26 GSSD_DAEMON_NAME=rpc.gssd
27 GSSD="/usr/sbin/rpc.gssd"
29 . /etc/rc.conf
30 . /etc/rc.d/functions
31 . /etc/conf.d/$daemon_name.conf
33 # Default mountpoint and options for rpc_pipefs filesystem
34 [ -z "$PIPEFS_MOUNTPOINT" ] && PIPEFS_MOUNTPOINT="/var/lib/nfs/rpc_pipefs"
35 [ -z "$PIPEFS_MOUNTOPTS" ] && PIPEFS_MOUNTOPTS="defaults"
37 # Parse the fstab file, and determine whether we need idmapd and gssd. (The
38 # /etc/conf.d/nfs-common settings, if any, will override our autodetection.)
39 AUTO_NEED_IDMAPD=no
40 AUTO_NEED_GSSD=no
42 if [ -f /etc/fstab ]; then
43 exec 9<&0 </etc/fstab
45 while read DEV MTPT FSTYPE OPTS REST; do
46 if [ "$FSTYPE" = "nfs4" ]; then
47 AUTO_NEED_IDMAPD=yes
49 case "$OPTS" in
50 sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5i,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
51 AUTO_NEED_GSSD=yes
53 esac
54 done
56 exec 0<&9 9<&-
59 # We also need idmapd if we run an NFSv4 server. It's fairly difficult
60 # to autodetect whether there are NFSv4 exports or not, and idmapd is not a
61 # particularily heavy daemon, so we auto-enable it if we find an /etc/exports
62 # file. This does not mean that there are NFSv4 or other mounts active (or
63 # even that nfs-kernel-server is installed), but it matches what the "start"
64 # condition in nfs-kernel-server's init script does, which has a value in
65 # itself.
66 if [ -f /etc/exports ] && grep -q '^[[:space:]]*[^#]*/' /etc/exports; then
67 AUTO_NEED_IDMAPD=yes
70 case "$NEED_STATD" in
71 yes|no)
74 NEED_STATD=yes
76 esac
78 case "$NEED_IDMAPD" in
79 yes|no)
82 NEED_IDMAPD=$AUTO_NEED_IDMAPD
84 esac
86 case "$NEED_GSSD" in
87 yes|no)
90 NEED_GSSD=$AUTO_NEED_GSSD
92 esac
94 do_modprobe() {
95 if [ -x /sbin/modprobe -a -f /proc/modules ]; then
96 modprobe -q "$1" || true
100 do_mount() {
101 if ! grep -E "$1\$" /proc/filesystems &> /dev/null ; then
102 return 1
105 if grep -vw "$1" /proc/mounts &> /dev/null ; then
106 if ! mountpoint -q "$2" ; then
107 mount -t "$1" "$1" "$2" -o "$3"
108 return
111 return 0
114 do_umount() {
115 if mountpoint -q "$1" ; then
116 umount "$1"
118 return 0
121 get_pid() {
122 pidof -o %PPID "$1"
125 case "$1" in
126 start)
127 ck_depends ${DAEMON_DEPENDS[@]}
129 rc=0
130 if [ "$NEED_STATD" = yes ]; then
131 stat_busy "Starting $STATD_DAEMON_NAME daemon"
132 PID=$(get_pid $STATD)
133 if [ -z "$PID" ]; then
134 [ -f /var/run/$STATD_DAEMON_NAME.pid ] && rm -f /var/run/$STATD_DAEMON_NAME.pid
135 # RUN
136 $STATD $STATD_OPTS
138 rc=$(($rc+$?))
139 if [ $rc -gt 0 ]; then
140 stat_fail
141 exit $rc
142 else
143 echo $(get_pid $STATD) > /var/run/$STATD_DAEMON_NAME.pid
144 stat_done
146 else
147 stat_fail
148 exit 1
150 # Run sm-notify
151 /usr/sbin/sm-notify $SMNOTIFY_OPTS
154 if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]; then
155 stat_busy "Mounting pipefs filesystem"
156 do_modprobe sunrpc
157 do_modprobe nfs
158 do_modprobe nfsd
159 do_mount rpc_pipefs "$PIPEFS_MOUNTPOINT" "$PIPEFS_MOUNTOPTS"
160 rc=$(($rc+$?))
161 if [ $rc -gt 0 ]; then
162 stat_fail
163 exit $rc
166 if [ "$NEED_IDMAPD" = yes ]; then
167 stat_busy "Starting $IDMAPD_DAEMON_NAME daemon"
168 PID=$(get_pid $IDMAPD)
169 if [ -z "$PID" ]; then
170 [ -f /var/run/$IDMAPD_DAEMON_NAME.pid ] && rm -f /var/run/$IDMAPD_DAEMON_NAME.pid
171 # RUN
172 $IDMAPD $IDMAPD_OPTS
174 rc=$(($rc+$?))
175 if [ $rc -gt 0 ]; then
176 stat_fail
177 exit $rc
178 else
179 echo $(get_pid $IDMAPD) > /var/run/$IDMAPD_DAEMON_NAME.pid
180 stat_done
182 else
183 stat_fail
184 exit 1
188 if [ "$NEED_GSSD" = yes ]; then
189 do_modprobe rpcsec_gss_krb5
190 stat_busy "Starting $GSSD_DAEMON_NAME daemon"
191 PID=$(get_pid $GSSD)
192 if [ -z "$PID" ]; then
193 [ -f /var/run/$GSSD_DAEMON_NAME.pid ] && rm -f /var/run/$GSSD_DAEMON_NAME.pid
194 # RUN
195 $GSSD $GSSD_OPTS
197 rc=$(($rc+$?))
198 if [ $rc -gt 0 ]; then
199 stat_fail
200 exit $rc
201 else
202 echo $(get_pid $GSSD) > /var/run/$GSSD_DAEMON_NAME.pid
203 stat_done
205 else
206 stat_fail
207 exit 1
212 add_daemon $daemon_name
215 stop)
216 rc=0
217 if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]; then
219 if [ "$NEED_GSSD" = yes ]; then
220 stat_busy "Stopping $GSSD_DAEMON_NAME daemon"
221 PID=$(get_pid $GSSD)
222 # KILL
223 [ ! -z "$PID" ] && kill $PID &> /dev/null
225 rc=$(($rc+$?))
226 if [ $rc -gt 0 ]; then
227 stat_fail
228 exit $rc
229 else
230 rm -f /var/run/$GSSD_DAEMON_NAME.pid &> /dev/null
231 stat_done
235 if [ "$NEED_IDMAPD" = yes ]; then
236 stat_busy "Stopping $IDMAPD_DAEMON_NAME daemon"
237 PID=$(get_pid $IDMAPD)
238 # KILL
239 [ ! -z "$PID" ] && kill $PID &> /dev/null
241 rc=$(($rc+$?))
242 if [ $rc -gt 0 ]; then
243 stat_fail
244 exit $rc
245 else
246 rm -f /var/run/$IDMAPD_DAEMON_NAME.pid &> /dev/null
247 stat_done
250 do_umount "$PIPEFS_MOUNTPOINT" 2>/dev/null || true
253 if [ "$NEED_STATD" = yes ]; then
254 stat_busy "Stopping $STATD_DAEMON_NAME daemon"
255 PID=$(get_pid $STATD)
256 # KILL
257 [ ! -z "$PID" ] && kill $PID &> /dev/null
259 rc=$(($rc+$?))
260 if [ $rc -gt 0 ]; then
261 stat_fail
262 exit $rc
263 else
264 rm -f /var/run/$STATD_DAEMON_NAME.pid &> /dev/null
265 stat_done
269 rm_daemon $daemon_name
272 status)
273 stat_busy "Checking $daemon_name status";
274 ck_status $daemon_name
276 if [ "$NEED_STATD" = yes ]; then
277 stat_busy "Daemon $STATD_DAEMON_NAME running"
278 PID=$(get_pid $STATD)
279 if [ -z "$PID" ]; then
280 stat_fail
281 else
282 stat_done
286 if [ "$NEED_GSSD" = yes ]; then
287 stat_busy "Daemon $GSSD_DAEMON_NAME running"
288 PID=$(get_pid $GSSD)
289 if [ -z "$PID" ]; then
290 stat_fail
291 else
292 stat_done
296 if [ "$NEED_IDMAPD" = yes ]; then
297 stat_busy "Daemon $IDMAPD_DAEMON_NAME running"
298 PID=$(get_pid $IDMAPD)
299 if [ -z "$PID" ]; then
300 stat_fail
301 else
302 stat_done
305 echo
308 restart)
309 $0 stop
310 sleep 3
311 $0 start
314 echo "usage: $0 {start|stop|status|restart}"
315 esac
316 exit 0