]> arthur.barton.de Git - ocf-ra.git/blob - OCFS2_DRBD
495de5a5894ed99f1ff68eb94f505b2c73c093b2
[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.4</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 </parameters>
63
64 <actions>
65 <action name="start" timeout="90" />
66 <action name="stop" timeout="90" />
67 <action name="monitor" timeout="20" interval="30" depth="0" start-delay="10" />
68 <action name="meta-data" timeout="5" />
69 <action name="verify-all" timeout="30" />
70 </actions>
71 </resource-agent>
72 END
73 }
74
75 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
76
77 ClusterFS_usage() {
78         echo "usage: $0 {start|stop|monitor|validate-all|meta-data}"
79 }
80
81 ClusterFS_start() {
82         mkdir -p "$OCF_RESKEY_mountpoint"
83         drbdadm primary "$OCF_RESKEY_drbd"
84         if [ $? -ne 0 ]; then
85                 return $OCF_ERR_GENERIC
86         fi
87         mount -t ocfs2 "$OCF_RESKEY_drbd_dev" "$OCF_RESKEY_mountpoint"
88         if [ $? -ne 0 ]; then
89                 return $OCF_ERR_GENERIC
90         fi
91         return $OCF_SUCCESS
92 }
93
94 ClusterFS_stop() {
95         mount | grep "$OCF_RESKEY_drbd_dev on " >/dev/null
96         if [ $? -eq 0 ]; then
97                 umount "$OCF_RESKEY_mountpoint"
98                 if [ $? -ne 0 ]; then
99                         # try harder, kill processes on this filesystem
100                         pids=$(ps ax|awk "{print \$1}"|grep -v PID)
101                         for p in $pids; do
102                                 lsof -p $p -n | grep " $OCF_RESKEY_mountpoint" \
103                                  >/dev/null 2>&1
104                                 [ $? -eq 0 ] || continue
105                                 kill $p
106                         done
107                         sleep 3
108                         pids=$(ps ax|awk "{print \$1}"|grep -v PID)
109                         for p in $pids; do
110                                 lsof -p $p -n | grep " $OCF_RESKEY_mountpoint" \
111                                  >/dev/null 2>&1
112                                 [ $? -eq 0 ] || continue
113                                 kill -9 $p
114                         done
115                         sleep 1
116                         umount "$OCF_RESKEY_mountpoint"
117                         if [ $? -ne 0 ]; then
118                                 return $OCF_ERR_GENERIC
119                         fi
120                 fi
121         fi
122         drbdadm secondary "$OCF_RESKEY_drbd"
123         return $OCF_SUCCESS
124 }
125
126 ClusterFS_monitor() {
127         mount | grep "$OCF_RESKEY_drbd_dev on " >/dev/null
128         if [ $? -eq 0 ]; then
129                 return $OCF_SUCCESS
130         fi
131         return $OCF_NOT_RUNNING
132 }
133
134 ClusterFS_validate() {
135         if [ -z "$OCF_RESKEY_drbd" ]; then
136                 return $OCF_ERR_ARGS
137         fi
138         if [ -z "$OCF_RESKEY_drbd_dev" ]; then
139                 return $OCF_ERR_ARGS
140         fi
141         if [ -z "$OCF_RESKEY_mountpoint" ]; then
142                 return $OCF_ERR_ARGS
143         fi
144         return $OCF_SUCCESS
145 }
146
147 case $__OCF_ACTION in
148         meta-data)
149                 meta_data
150                 exit $OCF_SUCCESS
151                 ;;
152         start)
153                 ClusterFS_start
154                 ;;
155         stop)
156                 ClusterFS_stop
157                 ;;
158         monitor)
159                 ClusterFS_monitor
160                 ;;
161         validate-all)
162                 ClusterFS_validate
163                 ;;
164         usage|help)
165                 ClusterFS_usage
166                 exit $OCF_SUCCESS
167                 ;;
168         *)
169                 ClusterFS_usage
170                 exit $OCF_ERR_UNIMPLEMENTED
171                 ;;
172 esac
173
174 rc=$?
175 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
176 exit $rc
177
178 # -eof-