]> arthur.barton.de Git - ocf-ra.git/blob - OCFS2_DRBD
OCFS2_DRBD: mount ocfs2 filesystems with "noatime" option
[ocf-ra.git] / OCFS2_DRBD
1 #!/bin/sh
2 #
3 # OCF RA for OCFS2 on DRBD
4 #
5 # Copyright (c) 2008,2009 Barton IT-Consulting
6 # Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-BrĂ©e
7 #                    All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of version 2 of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 #
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
27 #
28
29 # Initialization:
30 . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
31
32 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33
34 meta_data() {
35         cat <<END
36 <?xml version="1.0"?>
37 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
38 <resource-agent name="OCFS2_DRBD">
39 <version>1.5</version>
40
41 <longdesc lang="en">
42 This Resource Agent starts and stops OCFS2 file systems located on DRBD devices.
43 </longdesc>
44 <shortdesc lang="en">OCFS2 on DRBD resource agent</shortdesc>
45
46 <parameters>
47 <parameter name="drbd" unique="1">
48 <longdesc lang="en">ID of the DRBD resource</longdesc>
49 <shortdesc lang="en">ID of the DRBD resource</shortdesc>
50 <content type="string" default="" />
51 </parameter>
52 <parameter name="drbd_dev" unique="1">
53 <longdesc lang="en">DRBD device</longdesc>
54 <shortdesc lang="en">DRBD device</shortdesc>
55 <content type="string" default="" />
56 </parameter>
57 <parameter name="mountpoint" unique="1">
58 <longdesc lang="en">Mountpoint for OCFS2 filesystem</longdesc>
59 <shortdesc lang="en">Mountpoint for OCFS2 filesystem</shortdesc>
60 <content type="string" default="" />
61 </parameter>
62 <parameter name="reload_cron" unique="1">
63 <longdesc lang="en">Reload CRON configuration after mounting OCFS2 filesystem</longdesc>
64 <shortdesc lang="en">Reload CRON configuration</shortdesc>
65 <content type="boolean" default="0" />
66 </parameter>
67 </parameters>
68
69 <actions>
70 <action name="start" timeout="90" />
71 <action name="stop" timeout="90" />
72 <action name="monitor" timeout="20" interval="30" depth="0" start-delay="10" />
73 <action name="meta-data" timeout="5" />
74 <action name="validate-all" timeout="30" />
75 </actions>
76 </resource-agent>
77 END
78 }
79
80 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81
82 ClusterFS_usage() {
83         echo "usage: $0 {start|stop|monitor|validate-all|meta-data}"
84 }
85
86 ClusterFS_start() {
87         mkdir -p "$OCF_RESKEY_mountpoint"
88         drbdadm primary "$OCF_RESKEY_drbd"
89         if [ $? -ne 0 ]; then
90                 return $OCF_ERR_GENERIC
91         fi
92         mount -t ocfs2 -o noatime \
93                 "$OCF_RESKEY_drbd_dev" "$OCF_RESKEY_mountpoint"
94         if [ $? -ne 0 ]; then
95                 return $OCF_ERR_GENERIC
96         fi
97         if [ "$OCF_RESKEY_reload_cron" = "1" ]; then
98                 [ -d /etc/cron.d ] && touch /etc/cron.d
99         fi
100         return $OCF_SUCCESS
101 }
102
103 ClusterFS_stop() {
104         mount | grep "$OCF_RESKEY_drbd_dev on " >/dev/null
105         if [ $? -eq 0 ]; then
106                 umount "$OCF_RESKEY_mountpoint"
107                 if [ $? -ne 0 ]; then
108                         # try harder, kill processes on this filesystem
109                         pids=$(ps ax|awk "{print \$1}"|grep -v PID)
110                         for p in $pids; do
111                                 lsof -p $p -n | grep " $OCF_RESKEY_mountpoint" \
112                                  >/dev/null 2>&1
113                                 [ $? -eq 0 ] || continue
114                                 kill $p
115                         done
116                         sleep 3
117                         pids=$(ps ax|awk "{print \$1}"|grep -v PID)
118                         for p in $pids; do
119                                 lsof -p $p -n | grep " $OCF_RESKEY_mountpoint" \
120                                  >/dev/null 2>&1
121                                 [ $? -eq 0 ] || continue
122                                 kill -9 $p
123                         done
124                         sleep 1
125                         umount "$OCF_RESKEY_mountpoint"
126                         if [ $? -ne 0 ]; then
127                                 return $OCF_ERR_GENERIC
128                         fi
129                 fi
130         fi
131         drbdadm secondary "$OCF_RESKEY_drbd"
132         if [ "$OCF_RESKEY_reload_cron" = "1" ]; then
133                 [ -d /etc/cron.d ] && touch /etc/cron.d
134         fi
135         return $OCF_SUCCESS
136 }
137
138 ClusterFS_monitor() {
139         mount | grep "$OCF_RESKEY_drbd_dev on " >/dev/null
140         if [ $? -eq 0 ]; then
141                 return $OCF_SUCCESS
142         fi
143         return $OCF_NOT_RUNNING
144 }
145
146 ClusterFS_validate() {
147         if [ -z "$OCF_RESKEY_drbd" ]; then
148                 return $OCF_ERR_ARGS
149         fi
150         if [ -z "$OCF_RESKEY_drbd_dev" ]; then
151                 return $OCF_ERR_ARGS
152         fi
153         if [ -z "$OCF_RESKEY_mountpoint" ]; then
154                 return $OCF_ERR_ARGS
155         fi
156         return $OCF_SUCCESS
157 }
158
159 case $__OCF_ACTION in
160         meta-data)
161                 meta_data
162                 exit $OCF_SUCCESS
163                 ;;
164         start)
165                 ClusterFS_start
166                 ;;
167         stop)
168                 ClusterFS_stop
169                 ;;
170         monitor)
171                 ClusterFS_monitor
172                 ;;
173         validate-all)
174                 ClusterFS_validate
175                 ;;
176         usage|help)
177                 ClusterFS_usage
178                 exit $OCF_SUCCESS
179                 ;;
180         *)
181                 ClusterFS_usage
182                 exit $OCF_ERR_UNIMPLEMENTED
183                 ;;
184 esac
185
186 rc=$?
187 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
188 exit $rc
189
190 # -eof-