]>
Commit | Line | Data |
---|---|---|
042f4ecc JR |
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 | msg_already_running "NFSFS" | |
45 | return | |
46 | fi | |
47 | ||
48 | # Set the ports lockd should listen on | |
49 | if [ -n "$LOCKD_TCPPORT" ]; then | |
50 | /sbin/sysctl -w fs.nfs.nlm_tcpport=$LOCKD_TCPPORT >/dev/null 2>&1 | |
51 | fi | |
52 | if [ -n "$LOCKD_UDPPORT" ]; then | |
53 | /sbin/sysctl -w fs.nfs.nlm_udpport=$LOCKD_UDPPORT >/dev/null 2>&1 | |
54 | fi | |
55 | ||
042f4ecc JR |
56 | run_cmd "Mounting NFS filesystems" mount -a -t nfs,nfs4 |
57 | touch /var/lock/subsys/nfsfs | |
58 | } | |
59 | ||
60 | stop() { | |
61 | if [ -f /proc/mounts ]; then | |
62 | fsfile="/proc/mounts" | |
63 | else | |
64 | fsfile="/etc/mtab" | |
65 | fi | |
66 | ||
67 | show "Unmounting NFS filesystems" | |
68 | busy | |
69 | retry=3 | |
70 | remaining=$(awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ | |
71 | $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile) | |
72 | while [ -n "$remaining" -a $retry -gt 0 ]; do | |
73 | fuser -msk -TERM `awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ | |
74 | $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile` | |
75 | sleep 2 | |
76 | fuser -msk -KILL `awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ | |
77 | $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile` | |
78 | # Sort filesystems to unmount in reverse order | |
79 | rem="" | |
80 | for r in $(awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ | |
81 | $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile) ; do | |
82 | rem="$r $rem" | |
83 | done | |
84 | for fs in $rem ; do | |
85 | umount $fs | |
86 | done | |
87 | remaining=$(awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ | |
88 | $3 ~ /^nfs(4$|$)/ && $2 !~ ig {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 | restart) | |
104 | stop | |
105 | start | |
106 | ;; | |
107 | reload|force-reload) | |
108 | mount -a -t nfs,nfs4 | |
109 | ;; | |
110 | status) | |
111 | if [ -f /proc/mounts ]; then | |
112 | echo "Configured NFS mountpoints:" | |
113 | grep -v '^#' /etc/fstab | \ | |
114 | awk '{ if ($3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) print $2}' | |
115 | echo "Active NFS mountpoints:" | |
116 | grep -v '^#' /proc/mounts | \ | |
117 | awk '{ if ($3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) print $2}' | |
118 | else | |
119 | echo "/proc filesystem unavailable" | |
120 | fi | |
121 | ;; | |
122 | *) | |
123 | msg_usage "$0 {start|stop|restart|reload|force-reload|status}" | |
124 | exit 3 | |
125 | esac | |
126 | ||
127 | exit 0 |