Whamcloud - gitweb
8148b75c57d69418dc6c0a588d11ba59328eef34
[fs/lustre-release.git] / lustre / scripts / lustrefs
1 #!/bin/bash
2 #
3 # lustrefs      Mount Lustre filesystems.
4 #
5 # Authors:      Jacob Berkman <jacob@clusterfs.com>
6 #
7 # Based on the netfs script:
8 #
9 # Authors:      Bill Nottingham <notting@redhat.com>
10 #               Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
11 #
12 # chkconfig: 345 26 74
13 # description: Mounts and unmounts all Lustre mount points.
14 #
15 ### BEGIN INIT INFO
16 # Provides: $local_fs $remote_fs
17 ### END INIT INFO
18
19 [ -f /etc/sysconfig/network ] || exit 0
20 . /etc/init.d/functions
21 . /etc/sysconfig/network
22
23 # Check that networking is up.
24 [ "${NETWORKING}" = "no" ] && exit 0
25
26 LUSTREFSTAB=`LC_ALL=C awk '!/^#/ && $3 == "lustre" && $4 !~ /noauto/ { print $2 }' /etc/fstab`
27 LUSTREMTAB=`LC_ALL=C awk '!/^#/ && $3 == "lustre" { print $2 }' /proc/mounts`
28
29 # See how we were called.
30 case "$1" in
31   start)
32         [ -n "$LUSTREFSTAB" ] && action $"Mounting Lustre filesystems: " mount -a -t lustre
33         touch /var/lock/subsys/lustrefs
34         ;;
35   stop)
36         [ -n "$LUSTREMTAB" ] && {
37                 sig=
38                 retry=3
39                 remaining=`LC_ALL=C awk '!/^#/ && $3 ~ /^lustre/ && $2 != "/" {print $2}' /proc/mounts`
40                 while [ -n "$remaining" -a "$retry" -gt 0 ]
41                 do
42                         if [ "$retry" -lt 3 ]; then
43                                 action $"Unmounting Lustre filesystems (retry): " umount -f -a -t lustre
44                         else
45                                 action $"Unmounting Lustre filesystems: " umount -a -t lustre
46                         fi
47                         sleep 2
48                         remaining=`LC_ALL=C awk '!/^#/ && $3 ~ /^lustre/ && $2 != "/" {print $2}' /proc/mounts`
49                         [ -z "$remaining" ] && break
50                         /sbin/fuser -k -m $sig $remaining >/dev/null
51                         sleep 5
52                         retry=$(($retry - 1))
53                         sig=-9
54                 done
55         }
56         rm -f /var/lock/subsys/lustrefs
57         ;;
58   status)
59         if [ -f /proc/mounts ] ; then
60                 [ -n "$LUSTREFSTAB" ] && {
61                       echo $"Configured Lustre mountpoints: "
62                       for fs in $LUSTREFSTAB; do echo $fs ; done
63                 }
64                 [ -n "$LUSTREMTAB" ] && {
65                       echo $"Active Lustre mountpoints: "
66                       for fs in $LUSTREMTAB; do echo $fs ; done
67                 }
68         else
69                 echo $"/proc filesystem unavailable"
70         fi
71         ;;
72   restart)
73         $0 stop
74         $0 start
75         ;;
76   reload)
77         $0 start
78         ;;
79   *)
80         echo $"Usage: $0 {start|stop|restart|reload|status}"
81         exit 1
82 esac
83
84 exit 0