Whamcloud - gitweb
LU-1187 tests: Fixes in test-framework for DNE
[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: - 26 74
13 # description: Mounts and unmounts all Lustre mount points.
14 #
15 ### BEGIN INIT INFO
16 # Provides: lustrefs
17 # Required-Start: $network $remote_fs +sshd +lustre
18 # Required-Stop: $network $remote_fs
19 # Should-Start: 
20 # Should-Stop: 
21 # Default-Start: 3 5
22 # Default-Stop: 0 1 2 6
23 # Short-Description: Mounts and unmounts all Lustre mount points.
24 ### END INIT INFO
25
26 # Source function library.
27 if [ -f /etc/init.d/functions ]; then
28    . /etc/init.d/functions
29 fi
30
31 # Source networking configuration.
32 if [ -f /etc/sysconfig/network ]; then
33    . /etc/sysconfig/network
34 fi
35
36 # Source lsb-functions.
37 if [ -f /lib/lsb/init-functions ]; then
38    . /lib/lsb/init-functions
39 fi
40
41 [ -x /sbin/fuser ] && FUSER=/sbin/fuser
42 [ -x /bin/fuser ] && FUSER=/bin/fuser
43
44 # Check that networking is up.
45 [ "${NETWORKING}" = "no" ] && exit 0
46
47 # Red Hat has it's own "action"-function for RHGB-messages.
48 lustre_action () {
49         STRING=$1
50         shift
51         if [ $(typeset -F action) ]; then
52                 action "$STRING" $*
53                 rc=$?
54         else
55                 $*
56                 rc=$?
57                 if [ $rc = 0 ]; then
58                         log_success_msg "$STRING"
59                 else
60                         log_failure_msg "$STRING"
61                 fi
62         fi
63         return $rc
64 }
65
66 LUSTREFSTAB=`LC_ALL=C awk '!/^#/ && $3 == "lustre" && $4 !~ /noauto/ { print $2 }' /etc/fstab`
67 LUSTREMTAB=`LC_ALL=C awk '!/^#/ && ($3 ~ "lustre") { print $2 }' /proc/mounts`
68
69 # See how we were called.
70 case "$1" in
71   start)
72         [ -n "$LUSTREFSTAB" ] && lustre_action $"Mounting Lustre filesystems: " mount -a -t lustre
73         touch /var/lock/subsys/lustrefs
74         ;;
75   stop)
76         [ -n "$LUSTREMTAB" ] && {
77                 sig=
78                 retry=3
79                 remaining=`LC_ALL=C awk '!/^#/ && $3 ~ /^lustre/ && $2 != "/" {print $2}' /proc/mounts`
80                 while [ -n "$remaining" -a "$retry" -gt 0 ]
81                 do
82                         if [ "$retry" -lt 3 ]; then
83                                 lustre_action $"Unmounting Lustre filesystems (retry): " umount -f -a -t lustre
84                         else
85                                 lustre_action $"Unmounting Lustre filesystems: " umount -a -t lustre
86                         fi
87                         sleep 2
88                         remaining=`LC_ALL=C awk '!/^#/ && $3 ~ /^lustre/ && $2 != "/" {print $2}' /proc/mounts`
89                         [ -z "$remaining" ] && break
90                         $FUSER -k -m $sig $remaining >/dev/null
91                         sleep 5
92                         retry=$(($retry - 1))
93                         sig=-9
94                 done
95         }
96         rm -f /var/lock/subsys/lustrefs
97         ;;
98   status)
99         if [ -f /proc/mounts ] ; then
100                 [ -n "$LUSTREFSTAB" ] && {
101                       echo $"Configured Lustre mountpoints: "
102                       for fs in $LUSTREFSTAB; do echo $fs ; done
103                 }
104                 [ -n "$LUSTREMTAB" ] && {
105                       echo $"Active Lustre mountpoints: "
106                       for fs in $LUSTREMTAB; do echo $fs ; done
107                 }
108         else
109                 echo $"/proc filesystem unavailable"
110         fi
111         ;;
112   restart)
113         $0 stop
114         $0 start
115         ;;
116   reload)
117         $0 start
118         ;;
119   *)
120         echo $"Usage: $0 {start|stop|restart|reload|status}"
121         exit 1
122 esac
123
124 exit 0