]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/netfs
fd4554a7115432e40fc6a42f3c5628d095d6881f
[projects/rc-scripts.git] / rc.d / init.d / netfs
1 #!/bin/sh
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
13 [ -f /etc/sysconfig/network ] || exit 0
14 . /etc/rc.d/init.d/functions
15 . /etc/rc.d/init.d/cryptsetup
16 . /etc/sysconfig/network
17
18 # nfs uses own script for that
19 if [ ! -f /etc/rc.d/init.d/nfsfs ]; then
20         NFSFSTAB=$(LC_ALL=C awk '!/^#/ && $3 ~ /^nfs/ && $3 != "nfsd" && $4 !~ /noauto/ { print $2 }' /etc/fstab)
21         NFSMTAB=$(LC_ALL=C awk '$3 ~ /^nfs/ && $3 != "nfsd" && $2 != "/" { print $2 }' /proc/mounts)
22 fi
23
24 CIFSFSTAB=$(LC_ALL=C awk '!/^#/ && $3 == "cifs" && $4 !~ /noauto/ { print $2 }' /etc/fstab)
25 NCPFSTAB=$(LC_ALL=C awk '!/^#/ && $3 == "ncpfs" && $4 !~ /noauto/ { print $2 }' /etc/fstab)
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)
31 NETDEVMTAB=$(LC_ALL=C awk '$4 ~ /_netdev/ && $2 != "/" { print $2 }' /etc/mtab)
32
33 start() {
34         [ ! -f /var/lock/subsys/network ] && exit 0
35         [ "$(id -u)" != "0" ] && exit 4
36         [ -n "$NFSFSTAB" ] && 
37           {
38             [ ! -f /var/lock/subsys/rpcbind ] && service rpcbind start
39             run_cmd "Mounting NFS filesystems" mount -a -t nfs,nfs4
40           }
41         [ -n "$CIFSFSTAB" ] && run_cmd "Mounting CIFS filesystems" mount -a -t cifs
42         [ -n "$NCPFSTAB" ] && run_cmd "Mounting NCP filesystems" mount -a -t ncpfs
43         [ -n "$NETDEVFSTAB" ] &&
44           {
45             if [ -f /etc/mdadm.conf ]; then
46                 mdadm -A -s
47             fi
48             if [ -f /etc/multipath.conf ] && [ -x /sbin/multipath ]; then
49                 modprobe dm-multipath >/dev/null 2>&1
50                 /sbin/multipath -v 0
51                 if [ -x /sbin/kpartx ]; then
52                        /sbin/dmsetup ls --target multipath --exec "/sbin/kpartx -a -p p"
53                 fi
54             fi
55             if [ -x /sbin/lvm ]; then
56                 if /sbin/lvm vgscan > /dev/null 2>&1 ; then
57                        run_cmd "Setting up Logical Volume Management" /sbin/lvm vgchange -a y
58                 fi
59             fi
60
61             if [ -f /etc/crypttab ]; then
62                 init_crypto 1
63             fi
64
65             show "Checking network-attached filesystems"; started
66             initlog -c "fsck -A -T -R -a -t opts=_netdev"
67             rc=$?
68             
69             if [ "$rc" -gt 1 ]; then
70                 echo
71                 echo
72                 nls "*** An error occurred during the file system check."
73                 nls "*** Dropping you to a shell; the system will reboot"
74                 nls "*** when you leave the shell."
75                 
76                 PS1="$(nls '(Repair filesystem)# ')"; export PS1
77                 [ "$SELINUX" = "1" ] && disable_selinux
78                 if ! is_no "$RUN_SULOGIN_ON_ERR"; then
79                         /sbin/sulogin
80                 else
81                         /bin/sh
82                 fi
83                 shutdown -r now
84            fi
85           }
86         touch /var/lock/subsys/netfs
87         run_cmd "Mounting other filesystems" mount -a -t nonfs,nfs4,cifs,ncpfs,gfs
88 }
89
90 stop() {
91         # Unmount loopback stuff first
92         [ "$(id -u)" != "0" ] && exit 4
93         __umount_loopback_loop
94         if [ -n "$NETDEVMTAB" ]; then
95                 __umount_loop '$4 ~ /_netdev/ && $2 != "/" {print $2}' \
96                         /etc/mtab \
97                         "$(nls "Unmounting network block filesystems")" \
98                         "$(nls "Unmounting network block filesystems (retry)")"
99         fi
100         if [ -n "$NFSMTAB" ]; then
101                 __umount_loop '$3 ~ /^nfs/ && $3 != "nfsd" && $2 != "/" {print $2}' \
102                         /proc/mounts \
103                         "$(nls "Unmounting NFS filesystems")" \
104                         "$(nls "Unmounting NFS filesystems (retry)")" \
105                         "-f -l"
106         fi
107         [ -n "$CIFSMTAB" ] && run_cmd "Unmounting CIFS filesystems" umount -a -t cifs
108         [ -n "$NCPMTAB" ] && run_cmd "Unmounting NCP filesystems" umount -a -t ncp,ncpfs
109         rm -f /var/lock/subsys/netfs
110 }
111
112 status() {
113         if [ -f /proc/mounts ]; then
114                 [ -n "$NFSFSTAB" ] && {
115                      nls "Configured NFS mountpoints: "
116                      for fs in $NFSFSTAB; do echo $fs ; done
117                 }
118                 [ -n "$CIFSFSTAB" ] && {
119                      nls "Configured CIFS mountpoints: "
120                      for fs in $CIFSFSTAB; do echo $fs ; done
121                 }
122                 [ -n "$NCPFSTAB" ] && {
123                      nls "Configured NCP mountpoints: "
124                      for fs in $NCPFSTAB; do echo $fs ; done
125                 }
126                 [ -n "$NETDEVFSTAB" ] && {
127                       nls "Configured network block devices: "
128                       for fs in $NETDEVFSTAB; do echo $fs ; done
129                 }
130                 [ -n "$NFSMTAB" ] && {
131                       nls "Active NFS mountpoints: "
132                       for fs in $NFSMTAB; do echo $fs ; done
133                 }
134                 [ -n "$CIFSMTAB" ] && {
135                       nls "Active CIFS mountpoints: "
136                       for fs in $CIFSMTAB; do echo $fs ; done
137                 }
138                 [ -n "$NCPMTAB" ] && {
139                       nls "Active NCP mountpoints: "
140                       for fs in $NCPMTAB; do echo $fs ; done
141                 }
142                 [ -n "$NETDEVMTAB" ] && {
143                       nls "Active network block devices: "
144                       for fs in $NETDEVMTAB; do echo $fs ; done
145                 }
146         else
147                 nls "/proc filesystem unavailable"
148         fi
149
150         [ -r /var/lock/subsys/netfs ] || exit 3
151 }
152
153 RETVAL=0
154 # See how we were called.
155 case "$1" in
156   start)
157         start
158         ;;
159   stop)
160         stop
161         ;;
162   status)
163         status
164         ;;
165   restart)
166         stop
167         start
168         ;;
169   reload)
170         start
171         ;;
172   *)
173         msg_usage "$0 {start|stop|restart|reload|status}"
174         exit 2
175 esac
176
177 exit $RETVAL
This page took 0.033687 seconds and 2 git commands to generate.