]> git.pld-linux.org Git - packages/nfs-utils.git/blob - nfsfs.init
- nfs and nfs4 are different filesystems, so mount them separately
[packages/nfs-utils.git] / nfsfs.init
1 #!/bin/sh
2 #
3 # nfsfs         Mount NFS filesystems.
4 #
5 # Version:      @(#) /etc/init.d/skeleton 1.01 26-Oct-1993
6 #
7 # Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
8 #
9 # chkconfig:    345 15 88
10 # description:  Mounts and unmounts all Network File System (NFS) \
11 #               mount points.
12 #
13 # $Id$
14
15 # Source networking configuration.
16 if [ ! -f /etc/sysconfig/network ]; then
17         exit 0
18 fi
19
20 # Source function library.
21 . /etc/rc.d/init.d/functions
22
23 # Get network config
24 . /etc/sysconfig/network
25
26 # Get service config
27 [ -f /etc/sysconfig/nfsfs ] && . /etc/sysconfig/nfsfs
28
29 # Check that networking is up.
30 if is_yes "${NETWORKING}"; then
31         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
32                 msg_network_down nfsfs
33                 exit 1
34         fi
35 else
36         exit 0
37 fi
38
39 start() {
40         if [ ! -f /var/lock/subsys/nfsfs ]; then
41                 run_cmd "Mounting NFS filesystems" mount -a -t nfs
42                 if is_yes "$NFS4" ; then
43                     if grep -q nfs4 /proc/filesystems; then
44                         modprobe -s nfs > /dev/null 2>&1
45                         if [ "$(kernelverser)" -ge "002006" ]; then
46                             grep -q rpc_pipefs /proc/filesystems && \
47                             ! grep -q rpc_pipefs /proc/mounts && \
48                             run_cmd "Mounting /var/lib/nfs/rpc_pipefs filesystem" mount -t rpc_pipefs rpc_pipefs /var/lib/nfs/rpc_pipefs
49                         fi
50                         if [ ! -f /var/lock/subsys/idmapd ]; then
51                             msg_starting "NFS idmapd"
52                             daemon rpc.idmapd $RPCIDMAPOPTIONS
53                             [ $? -eq 0 ] && touch /var/lock/subsys/idmapd
54                         fi
55                         if [ ! -f /var/lock/subsys/gssd ]; then
56                             msg_starting "NFS gssd"
57                             daemon rpc.gssd -m $RPCGSSOPTIONS
58                             [ $? -eq 0 ] && touch /var/lock/subsys/gssd
59                         fi
60                         run_cmd "Mounting NFSv4 filesystems" mount -a -t nfs4
61                     fi
62                 fi
63                 touch /var/lock/subsys/nfsfs
64         else
65             msg_already_running "NFSFS"
66         fi
67 }
68
69 stop() {
70         if [ -f /proc/mounts ]; then
71                 fsfile="/proc/mounts"
72         else
73                 fsfile="/etc/mtab"
74         fi
75
76         if is_yes "$NFS4" ; then
77                 if grep -q nfs4 /proc/filesystems; then
78                     show "Unmounting NFSv4 filesystems"
79                     busy
80                     retry=3
81                     remaining=$(awk '$3 == "nfs4" {print $2}' $fsfile)
82                     while [ -n "$remaining" -a $retry -gt 0 ]; do
83                         fuser -msk -TERM `awk '$3 == "nfs4" {print $2}' < $fsfile`
84                         sleep 2
85                         fuser -msk -KILL `awk '$3 == "nfs4" {print $2}' < $fsfile`
86                         umount -a -f -t nfs4
87                         remaining=$(awk '$3 == "nfs4" {print $2}' $fsfile)
88                         retry=$(($retry-1))
89                     done
90                     ok
91                     if [ -f /var/lock/subsys/gssd ]; then
92                         msg_stopping "NFS gssd"
93                         killproc rpc.gssd
94                         rm -f /var/lock/subsys/gssd
95                     fi
96                     if [ -f /var/lock/subsys/idmapd -a ! -f /var/lock/subsys/nfs ]; then
97                         msg_stopping "NFS idmapd"
98                         killproc rpc.idmapd
99                         rm -f /var/lock/subsys/idmapd
100                     fi
101                 fi
102         fi
103         show "Unmounting NFS filesystems"
104         busy
105         retry=3
106         remaining=$(awk '$3 == "nfs" {print $2}' $fsfile)
107         while [ -n "$remaining" -a $retry -gt 0 ]; do
108                 fuser -msk -TERM `awk '$3 == "nfs" {print $2}' < $fsfile`
109                 sleep 2
110                 fuser -msk -KILL `awk '$3 == "nfs" {print $2}' < $fsfile`
111                 umount -a -f -t nfs
112                 remaining=$(awk '$3 == "nfs" {print $2}' $fsfile)
113                 retry=$(($retry-1))
114         done
115         ok
116         rm -f /var/lock/subsys/nfsfs
117 }
118
119 # See how we were called.
120 case "$1" in
121   start)
122         start
123         ;;
124   stop)
125         stop
126         ;;
127   status)
128         if [ -f /proc/mounts ]; then
129                 echo "Configured NFS mountpoints:"
130                 grep -v '^#' /etc/fstab | \
131                   awk '{ if ($3 ~ /^nfs$/ && $4 !~ /noauto/) print $2}'
132                 echo "Active NFS mountpoints:"
133                 grep -v '^#' /proc/mounts | \
134                   awk '{ if ($3 ~ /^nfs$/ && $4 !~ /noauto/) print $2}'
135         else
136                 echo "/proc filesystem unavailable"
137         fi
138         ;;
139   restart)
140         stop
141         start
142         ;;
143   reload|force-reload)
144         mount -a -t nfs
145         ;;
146   *)
147         msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
148         exit 3
149 esac
150
151 exit 0
This page took 0.054018 seconds and 4 git commands to generate.