Subversion Repositories configs

Rev

Rev 8 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 1
#!/bin/bash
2
#
3
# netfs         Mount network filesystems.
4
#
5
# Authors:	Bill Nottingham <notting@redhat.com>
6
#		AJ Lewis <alewis@redhat.com>
7
# 		Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
8
#
9
# chkconfig: 345 25 75
10
# description: Mounts and unmounts all Network File System (NFS), \
11
#	       CIFS (Lan Manager/Windows), and NCP (NetWare) mount points.
12
### BEGIN INIT INFO
13
# Provides: $remote_fs
14
# Short-Description: Mount and unmount network filesystems.
15
# Description: Mount and unmount network filesystems.
16
### END INIT INFO
17
 
18
[ -f /etc/sysconfig/network ] || exit 0
19
. /etc/init.d/functions
20
. /etc/sysconfig/network
21
 
22
NFSFSTAB=$(LC_ALL=C awk '!/^#/ && $3 ~ /^nfs/ && $3 != "nfsd" && $4 !~ /noauto/ { print $2 }' /etc/fstab)
23
CIFSFSTAB=$(LC_ALL=C awk '!/^#/ && $3 == "cifs" && $4 !~ /noauto/ { print $2 }' /etc/fstab)
24
NCPFSTAB=$(LC_ALL=C awk '!/^#/ && $3 == "ncpfs" && $4 !~ /noauto/ { print $2 }' /etc/fstab)
8 - 25
GLUSTERFSFSTAB=$(LC_ALL=C awk '!/^#/ && $3 == "glusterfs" && $4 !~ /noauto/ { print $2 }' /etc/fstab)
3 - 26
NETDEVFSTAB=$(LC_ALL=C awk '!/^#/ && $4 ~/_netdev/ && $4 !~ /noauto/ { print $1 }' /etc/fstab)
27
 
28
NFSMTAB=$(LC_ALL=C awk '$3 ~ /^nfs/ && $3 != "nfsd" && $2 != "/" { print $2 }' /proc/mounts)
29
CIFSMTAB=$(LC_ALL=C awk '$3 == "cifs" { print $2 }' /proc/mounts)
30
NCPMTAB=$(LC_ALL=C awk '$3 == "ncpfs" { print $2 }' /proc/mounts)
8 - 31
GLUSTERFSMTAB=$(LC_ALL=C awk '$3 == "fuse.glusterfs" { print $2 }' /proc/mounts)
3 - 32
NETDEVMTAB=$(LC_ALL=C awk '$4 ~ /_netdev/ && $2 != "/" { print $2 }' /etc/mtab)
33
 
34
# See how we were called.
35
case "$1" in
36
  start)
37
        [ ! -f /var/lock/subsys/network ] && ! nm-online -x >/dev/null 2>&1 && exit 0
38
        [ "$EUID" != "0" ] && exit 4
39
        [ -n "$NFSFSTAB" ] &&
40
	  {
41
	    [ ! -f /var/lock/subsys/rpcbind ] && service rpcbind start
42
	    echo $"NFS filesystems queued to be mounted"
43
	  }
44
        [ -n "$CIFSFSTAB" ] && echo $"CIFS filesystems queued to be mounted"
45
        [ -n "$NCPFSTAB" ] && echo $"NCP filesystems queued to be mounted"
8 - 46
        [ -n "$GLUSTERFSFSTAB" ] && echo $"GLUSTERFS filesystems queued to be mounted"
3 - 47
        [ -n "$NETDEVFSTAB" ] &&
48
	  {
49
	    if [ -f /etc/mdadm.conf ] && [ -x /sbin/mdadm ]; then
50
		/sbin/mdadm -A -s
51
	    fi
52
	    if [ -f /etc/multipath.conf -a -x /sbin/multipath ]; then
53
	    	modprobe dm-multipath >/dev/null 2>&1
54
		/sbin/multipath -v 0
55
		if [ -x /sbin/kpartx ]; then
56
		       /sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -p p"
57
		fi
58
	    fi
59
	    if [ -x /sbin/lvm ]; then
60
		if /sbin/lvm vgscan > /dev/null 2>&1 ; then
8 - 61
		       action $"Setting up Logical Volume Management:" /sbin/lvm vgchange -a ay --ignoreskippedcluster
3 - 62
		fi
63
	    fi
64
 
65
	    if [ -f /etc/crypttab ]; then
66
	        init_crypto 1
67
	    fi
68
 
69
	    STRING=$"Checking network-attached filesystems"
70
 
71
	    echo $STRING
72
	    fsck -A -T -M -a -t opts=_netdev
73
	    rc=$?
74
 
75
	    if [ "$rc" -eq "0" ]; then
76
	    	success "$STRING"
77
		echo
78
	    elif [ "$rc" -eq "1" ]; then
79
	        passed "$STRING"
80
	        echo
81
	    fi
82
 
83
	    if [ "$rc" -gt 1 ]; then
84
		if [ -x /bin/plymouth ] && /bin/plymouth --ping ; then
85
			/bin/plymouth --hide-splash
86
		fi
87
		failure "$STRING"
88
		tty >/dev/null 2>&1 || exit 1
89
		echo
90
		echo
91
		echo $"*** An error occurred during the file system check."
92
		echo $"*** Dropping you to a shell; the system will reboot"
93
		echo $"*** when you leave the shell."
94
 
95
		str=$"(Repair filesystem)"
96
		PS1="$str \# # "; export PS1
97
		[ "$SELINUX" = "1" ] && disable_selinux
98
		sulogin
99
 
100
		shutdown -r now
101
	   fi
102
	  }
103
	touch /var/lock/subsys/netfs
104
	# The 'no' applies to all listed filesystem types. See mount(8).
105
	action $"Mounting filesystems: " mount -a -t nogfs2
106
	;;
107
  stop)
108
        # Unmount loopback stuff first
109
        [ "$EUID" != "0" ] && exit 4
110
	__umount_loopback_loop
111
  	if [ -n "$NETDEVMTAB" ]; then
112
		__umount_loop '$4 ~ /_netdev/ && $2 != "/" {print $2}' \
113
			/etc/mtab \
114
			$"Unmounting network block filesystems: " \
115
			$"Unmounting network block filesystems (retry): "
116
	fi
8 - 117
	if [ -n "$GLUSTERFSMTAB" ]; then
118
		__umount_loop '$3 ~ /^glusterfs/ {print $2}' \
119
			/etc/mtab \
120
			$"Unmounting GLUSTERFS filesystems: " \
121
			$"Unmounting GLUSTERFS filesystems (retry): "
122
	fi
3 - 123
  	if [ -n "$NFSMTAB" ]; then
33 - 124
		STRING=$"Unmounting NFS filesystems:"
125
		echo -n $STRING
126
		nfs_fs=$(LC_ALL=C awk '/^#/ {next} $3 ~ /^nfs/ && $3 != "nfsd" && $2 != "/" {print $2}' /proc/mounts | sort -r)
127
		if [ -n "$nfs_fs" ]; then
128
			# create a device id reference
129
			devs=$(stat -c "%d" $nfs_fs)
130
 
131
			# the lazy umount
132
			for fs in $nfs_fs ; do
133
				umount -l $fs
134
			done
135
 
136
			# find fds that don't start with /, are not sockets or pipes or other.
137
			# these are potentially detached fds
138
			detached_fds=$(find /proc/ -regex '/proc/[0-9]+/fd/.*' -printf "%p %l\n" 2>/dev/null |\
139
					 grep -Ev '/proc/[0-9]+/fd/[0-9]+ (/.*|inotify|\[.+\]|(socket|pipe):\[[0-9]+\])')
140
 
141
			# check each detached fd to see if it has the same device
142
			# as one of our lazy umounted filesystems
143
			kill_list=
144
			[ -n "$detached_fds" ] && while read fdline; do
145
				fd=${fdline%% *}
146
				pid=$(echo $fdline | sed -r 's/\/proc\/([0-9]+).+/\1/')
147
				fd_dev=$(stat -L -c "%d" $fd)
148
				for dev in $devs ; do
149
					[ "$dev" = "$fd_dev" ] && kill_list+="$pid "
150
				done
151
			done <<< "$detached_fds"
152
 
153
			[ -n "$kill_list" ] && kill $kill_list
154
 
155
			# run a little wait/check loop for procs to exit
156
			count=4
157
			while [ "$count" -gt 0 ] ; do
158
				[ -z "$kill_list" ] && break
159
				count=$(($count-1))
160
				usleep 500000
161
				remaining=
162
				for pid in $kill_list ; do
163
					[ -d "/proc/$pid" ] && remaining+="$pid "
164
				done
165
				kill_list=$remaining
166
			done
167
 
168
			# try to finish the job:
169
			if [ -n "$kill_list" ] ; then
170
				kill -9 $kill_list
171
				usleep 500000
172
				# last check
173
				remaining=
174
				for pid in $kill_list ; do
175
					[ -d "/proc/$pid" ] && remaining+="$pid "
176
				done
177
			fi
178
			[ -z "$remaining" ] && success "$STRING" || failure "$STRING"
179
			echo
180
		fi
3 - 181
	fi
182
	[ -n "$CIFSMTAB" ] && action $"Unmounting CIFS filesystems: " umount -a -t cifs
183
	[ -n "$NCPMTAB" ] && action $"Unmounting NCP filesystems: " umount -a -t ncp,ncpfs
184
	rm -f /var/lock/subsys/netfs
185
	;;
186
  status)
187
	if [ -f /proc/mounts ] ; then
188
	        [ -n "$NFSFSTAB" ] && {
189
		     echo $"Configured NFS mountpoints: "
190
		     for fs in $NFSFSTAB; do echo $fs ; done
191
		}
192
	        [ -n "$CIFSFSTAB" ] && {
193
		     echo $"Configured CIFS mountpoints: "
194
		     for fs in $CIFSFSTAB; do echo $fs ; done
195
		}
196
	        [ -n "$NCPFSTAB" ] && {
197
		     echo $"Configured NCP mountpoints: "
198
		     for fs in $NCPFSTAB; do echo $fs ; done
199
		}
200
		[ -n "$NETDEVFSTAB" ] && {
201
		      echo $"Configured network block devices: "
202
		      for fs in $NETDEVFSTAB; do echo $fs ; done
203
		}
204
		[ -n "$NFSMTAB" ] && {
205
                      echo $"Active NFS mountpoints: "
206
		      for fs in $NFSMTAB; do echo $fs ; done
207
		}
208
		[ -n "$CIFSMTAB" ] && {
209
                      echo $"Active CIFS mountpoints: "
210
		      for fs in $CIFSMTAB; do echo $fs ; done
211
		}
212
		[ -n "$NCPMTAB" ] && {
213
                      echo $"Active NCP mountpoints: "
214
		      for fs in $NCPMTAB; do echo $fs ; done
215
		}
8 - 216
		[ -n "$GLUSTERFSMTAB" ] && {
217
                      echo $"Active GLUSTERFS mountpoints: "
218
		      for fs in $GLUSTERFSMTAB; do echo $fs ; done
219
		}
3 - 220
		[ -n "$NETDEVMTAB" ] && {
221
		      echo $"Active network block devices: "
222
		      for fs in $NETDEVMTAB; do echo $fs ; done
223
		}
224
	else
225
		echo $"/proc filesystem unavailable"
226
	fi
227
	[ -r /var/lock/subsys/netfs ] || exit 3
228
	;;
229
  restart)
230
	$0 stop
231
	$0 start
232
	exit $?
233
	;;
234
  reload)
235
        $0 start
236
	exit $?
237
	;;
238
  *)
239
	echo $"Usage: $0 {start|stop|restart|reload|status}"
240
	exit 2
241
esac
242
 
243
exit 0