]>
Commit | Line | Data |
---|---|---|
9fddaaa8 JR |
1 | #!/bin/sh |
2 | # | |
ff100ffc | 3 | # nfsfs Mount NFS filesystems. |
9fddaaa8 | 4 | # |
891a86c9 | 5 | # chkconfig: 345 16 80 |
ff100ffc | 6 | # description: Mounts and unmounts all Network File System (NFS) \ |
7 | # mount points. | |
9fddaaa8 JR |
8 | |
9 | # Source networking configuration. | |
10 | if [ ! -f /etc/sysconfig/network ]; then | |
ff100ffc | 11 | exit 0 |
9fddaaa8 JR |
12 | fi |
13 | ||
14 | # Source function library. | |
15 | . /etc/rc.d/init.d/functions | |
16 | ||
ff100ffc | 17 | # Get network config |
9fddaaa8 JR |
18 | . /etc/sysconfig/network |
19 | ||
2da61068 | 20 | # Get service config |
eed927a9 | 21 | [ -f /etc/sysconfig/nfsfs ] && . /etc/sysconfig/nfsfs |
af75af5c | 22 | [ -f /etc/sysconfig/nfslock ] && . /etc/sysconfig/nfslock |
2da61068 | 23 | |
9fddaaa8 | 24 | # Check that networking is up. |
ff100ffc | 25 | if is_yes "${NETWORKING}"; then |
b69cfb4d | 26 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then |
ff100ffc | 27 | msg_network_down nfsfs |
28 | exit 1 | |
29 | fi | |
30 | else | |
31 | exit 0 | |
9fddaaa8 JR |
32 | fi |
33 | ||
fcdc7f4e JR |
34 | if [ "$1" != "stop" ]; then |
35 | check_portmapper || { nls "Error: portmap isn't running" && exit 0; } | |
af75af5c JR |
36 | fi |
37 | ||
74415e33 JR |
38 | if [ -z "$NFSUMOUNT_IGNORE" ]; then |
39 | NFSUMOUNT_IGNORE="/ /usr" | |
40 | fi | |
41 | ||
ad615b8a | 42 | start() { |
00b12e41 ER |
43 | if [ -f /var/lock/subsys/nfsfs ]; then |
44 | msg_already_running "NFSFS" | |
45 | return | |
46 | fi | |
af75af5c | 47 | |
00b12e41 ER |
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 | |
af75af5c | 55 | |
00b12e41 ER |
56 | # Special case /usr first |
57 | if ! awk '{ if ($2 == "/usr" && $3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) exit 1}' /etc/fstab; then | |
58 | run_cmd "Mounting /usr filesystem" mount /usr | |
59 | # In case of /usr over NFS idmapd, gssd and lockd may not start | |
60 | # check if they're running and try to start them if not | |
61 | /sbin/service idmapd status >/dev/null || /sbin/service idmapd start | |
62 | /sbin/service gssd status >/dev/null || /sbin/service gssd start | |
63 | /sbin/service nfslock status >/dev/null || /sbin/service nfslock start | |
c70958a8 | 64 | fi |
00b12e41 ER |
65 | run_cmd "Mounting NFS filesystems" mount -a -t nfs,nfs4 |
66 | touch /var/lock/subsys/nfsfs | |
ad615b8a ER |
67 | } |
68 | ||
69 | stop() { | |
5da51246 | 70 | if [ -f /proc/mounts ]; then |
eafe4dfc | 71 | fsfile="/proc/mounts" |
72 | else | |
73 | fsfile="/etc/mtab" | |
74 | fi | |
75 | ||
07a92029 JR |
76 | show "Unmounting NFS filesystems" |
77 | busy | |
78 | retry=3 | |
74415e33 JR |
79 | remaining=$(awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ |
80 | $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile) | |
07a92029 | 81 | while [ -n "$remaining" -a $retry -gt 0 ]; do |
74415e33 | 82 | fuser -msk -TERM `awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ |
ab3b4a50 | 83 | $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile` |
07a92029 | 84 | sleep 2 |
74415e33 | 85 | fuser -msk -KILL `awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ |
ab3b4a50 | 86 | $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile` |
894b672d JR |
87 | # Sort filesystems to unmount in reverse order |
88 | rem="" | |
ab3b4a50 | 89 | for r in $(awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ |
74415e33 | 90 | $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile) ; do |
894b672d JR |
91 | rem="$r $rem" |
92 | done | |
93 | for fs in $rem ; do | |
94 | umount $fs | |
95 | done | |
74415e33 JR |
96 | remaining=$(awk -v ig="^($NFSUMOUNT_IGNORE)$" 'BEGIN { gsub(/[\t ]+/, "|", ig); } \ |
97 | $3 ~ /^nfs(4$|$)/ && $2 !~ ig {print $2}' $fsfile) | |
07a92029 JR |
98 | retry=$(($retry-1)) |
99 | done | |
100 | ok | |
9fddaaa8 | 101 | rm -f /var/lock/subsys/nfsfs |
ad615b8a ER |
102 | } |
103 | ||
104 | # See how we were called. | |
105 | case "$1" in | |
106 | start) | |
107 | start | |
108 | ;; | |
109 | stop) | |
110 | stop | |
9fddaaa8 | 111 | ;; |
00b12e41 ER |
112 | restart) |
113 | stop | |
114 | start | |
115 | ;; | |
116 | reload|force-reload) | |
117 | mount -a -t nfs,nfs4 | |
118 | ;; | |
9fddaaa8 | 119 | status) |
5da51246 | 120 | if [ -f /proc/mounts ]; then |
9fddaaa8 | 121 | echo "Configured NFS mountpoints:" |
0c170055 | 122 | grep -v '^#' /etc/fstab | \ |
af75af5c | 123 | awk '{ if ($3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) print $2}' |
9fddaaa8 | 124 | echo "Active NFS mountpoints:" |
0c170055 | 125 | grep -v '^#' /proc/mounts | \ |
af75af5c | 126 | awk '{ if ($3 ~ /^nfs(4$|$)/ && $4 !~ /noauto/) print $2}' |
9fddaaa8 JR |
127 | else |
128 | echo "/proc filesystem unavailable" | |
129 | fi | |
130 | ;; | |
9fddaaa8 | 131 | *) |
5246d326 | 132 | msg_usage "$0 {start|stop|restart|reload|force-reload|status}" |
133 | exit 3 | |
9fddaaa8 JR |
134 | esac |
135 | ||
136 | exit 0 |