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