]> git.pld-linux.org Git - packages/nfs-utils.git/blob - nfsfs.init
- typo
[packages/nfs-utils.git] / nfsfs.init
1 #!/bin/sh
2 #
3 # nfsfs         Mount NFS filesystems.
4 #
5 # chkconfig:    345 16 80
6 # description:  Mounts and unmounts all Network File System (NFS) \
7 #               mount points.
8
9 # Source networking configuration.
10 if [ ! -f /etc/sysconfig/network ]; then
11         exit 0
12 fi
13
14 # Source function library.
15 . /etc/rc.d/init.d/functions
16
17 # Get network config
18 . /etc/sysconfig/network
19
20 # Get service config
21 [ -f /etc/sysconfig/nfsfs ] && . /etc/sysconfig/nfsfs
22 [ -f /etc/sysconfig/nfslock ] && . /etc/sysconfig/nfslock
23
24 # Check that networking is up.
25 if is_yes "${NETWORKING}"; then
26         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
27                 msg_network_down nfsfs
28                 exit 1
29         fi
30 else
31         exit 0
32 fi
33
34 if [ "$1" != "stop" ]; then
35         check_portmapper || { nls "Error: portmap isn't running" && exit 0; }
36 fi
37
38 if [ -z "$NFSUMOUNT_IGNORE" ]; then
39         NFSUMOUNT_IGNORE="/ /usr"
40 fi
41
42 start() {
43         if [ ! -f /var/lock/subsys/nfsfs ]; then
44                 # Set the ports lockd should listen on
45                 if [ -n "$LOCKD_TCPPORT" ]; then
46                         /sbin/sysctl -w fs.nfs.nlm_tcpport=$LOCKD_TCPPORT >/dev/null 2>&1
47                 fi
48                 if [ -n "$LOCKD_UDPPORT" ]; then
49                         /sbin/sysctl -w fs.nfs.nlm_udpport=$LOCKD_UDPPORT >/dev/null 2>&1
50                 fi
51
52                 # Special case /usr first
53                 if ! awk '{ if ($2 == "/usr" && $3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) exit 1}' /etc/fstab ; then
54                         run_cmd "Mounting /usr filesystem" mount /usr
55                         # In case of /usr over NFS idmapd, gssd and lockd may not start
56                         # check if they're running and try to start them if not
57                         /sbin/service idmapd status >/dev/null || /sbin/service idmapd start
58                         /sbin/service gssd status >/dev/null || /sbin/service gssd start
59                         /sbin/service nfslock status >/dev/null || /sbin/service nfslock start
60                 fi
61                 run_cmd "Mounting NFS filesystems" mount -a -t nfs,nfs4
62                 touch /var/lock/subsys/nfsfs
63
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         show "Unmounting NFS filesystems"
77         busy
78         retry=3
79         remaining=$(awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \
80                         $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile)
81         while [ -n "$remaining" -a $retry -gt 0 ]; do
82                 fuser -msk -TERM `awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \
83                                         $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile`
84                 sleep 2
85                 fuser -msk -KILL `awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \
86                                         $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile`
87                 # Sort filesystems to unmount in reverse order
88                 rem=""
89                 for r in $(awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \
90                                 $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile) ; do
91                         rem="$r $rem"
92                 done
93                 for fs in $rem ; do
94                         umount $fs
95                 done
96                 remaining=$(awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \
97                                 $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile)
98                 retry=$(($retry-1))
99         done
100         ok
101         rm -f /var/lock/subsys/nfsfs
102 }
103
104 # See how we were called.
105 case "$1" in
106   start)
107         start
108         ;;
109   stop)
110         stop
111         ;;
112   status)
113         if [ -f /proc/mounts ]; then
114                 echo "Configured NFS mountpoints:"
115                 grep -v '^#' /etc/fstab | \
116                   awk '{ if ($3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) print $2}'
117                 echo "Active NFS mountpoints:"
118                 grep -v '^#' /proc/mounts | \
119                   awk '{ if ($3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) print $2}'
120         else
121                 echo "/proc filesystem unavailable"
122         fi
123         ;;
124   restart)
125         stop
126         start
127         ;;
128   reload|force-reload)
129         mount -a -t nfs,nfs4
130         ;;
131   *)
132         msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
133         exit 3
134 esac
135
136 exit 0
This page took 0.043658 seconds and 3 git commands to generate.