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