]> git.pld-linux.org Git - packages/nfs-utils.git/blob - nfsfs.init
29e936c78726ee7ca8dc0cd304361881d82edf6d
[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 start() {
39         if [ ! -f /var/lock/subsys/nfsfs ]; then
40                 # Set the ports lockd should listen on
41                 if [ -n "$LOCKD_TCPPORT" ]; then
42                         /sbin/sysctl -w fs.nfs.nlm_tcpport=$LOCKD_TCPPORT >/dev/null 2>&1
43                 fi
44                 if [ -n "$LOCKD_UDPPORT" ]; then
45                         /sbin/sysctl -w fs.nfs.nlm_udpport=$LOCKD_UDPPORT >/dev/null 2>&1
46                 fi
47
48                 # Special case /usr first
49                 if ! awk '{ if ($2 == "/usr" && $3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) exit 1}' /etc/fstab ; then
50                         run_cmd "Mounting /usr filesystem" mount /usr
51                         # In case of /usr over NFS idmapd, gssd and lockd may not start
52                         # check if they're running and try to start them if not
53                         /sbin/service idmapd status >/dev/null || /sbin/service idmapd start
54                         /sbin/service gssd status >/dev/null || /sbin/service gssd start
55                         /sbin/service nfslock status >/dev/null || /sbin/service nfslock start
56                 fi
57                 run_cmd "Mounting NFS filesystems" mount -a -t nfs,nfs4
58                 touch /var/lock/subsys/nfsfs
59
60         else
61             msg_already_running "NFSFS"
62         fi
63 }
64
65 stop() {
66         if [ -f /proc/mounts ]; then
67                 fsfile="/proc/mounts"
68         else
69                 fsfile="/etc/mtab"
70         fi
71
72         show "Unmounting NFS filesystems"
73         busy
74         retry=3
75         remaining=$(awk '$3 ~ /^nfs(4$|$)/ && $2 !~ /^\/(usr$|$)/ {print $2}' $fsfile)
76         while [ -n "$remaining" -a $retry -gt 0 ]; do
77                 fuser -msk -TERM `awk '$3 ~ /^nfs(4$|$)/ && $2 !~ /^\/(usr$|$)/ {print $2}' < $fsfile`
78                 sleep 2
79                 fuser -msk -KILL `awk '$3 ~ /^nfs(4$|$)/ && $2 !~ /^\/(usr$|$)/ {print $2}' < $fsfile`
80                 # Sort filesystems to unmount in reverse order
81                 rem=""
82                 for r in $(awk '$3 ~ /^nfs(4$|$)/ && $2 !~ /^\/(usr$|$)/ {print $2}' $fsfile) ; do
83                         rem="$r $rem"
84                 done
85                 for fs in $rem ; do
86                         umount $fs
87                 done
88                 remaining=$(awk '$3 ~ /^nfs(4$|$)/ && $2 !~ /^\/(usr$|$)/ {print $2}' $fsfile)
89                 retry=$(($retry-1))
90         done
91         ok
92         rm -f /var/lock/subsys/nfsfs
93 }
94
95 # See how we were called.
96 case "$1" in
97   start)
98         start
99         ;;
100   stop)
101         stop
102         ;;
103   status)
104         if [ -f /proc/mounts ]; then
105                 echo "Configured NFS mountpoints:"
106                 grep -v '^#' /etc/fstab | \
107                   awk '{ if ($3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) print $2}'
108                 echo "Active NFS mountpoints:"
109                 grep -v '^#' /proc/mounts | \
110                   awk '{ if ($3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) print $2}'
111         else
112                 echo "/proc filesystem unavailable"
113         fi
114         ;;
115   restart)
116         stop
117         start
118         ;;
119   reload|force-reload)
120         mount -a -t nfs,nfs4
121         ;;
122   *)
123         msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
124         exit 3
125 esac
126
127 exit 0
This page took 0.054677 seconds and 2 git commands to generate.