#!/bin/bash
#
#
#		OCF Resource Agent compliant drbd resource script.
#
# Copyright (c) 2009 LINBIT HA-Solutions GmbH,
# Copyright (c) 2009 Florian Haas, Lars Ellenberg
# Based on the Heartbeat drbd OCF Resource Agent by Lars Marowsky-Bree
# (though it turned out to be an almost complete rewrite)
#
#					 All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like.	Any license provided herein, whether implied or
# otherwise, applies only to this software file.  Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
#

# OCF instance parameters
#	OCF_RESKEY_drbd_resource
#	OCF_RESKEY_drbdconf
#	OCF_RESKEY_stop_outdates_secondary
#	OCF_RESKEY_adjust_master_score
#
# meta stuff this agent looks at:
#	OCF_RESKEY_CRM_meta_clone_max
#	OCF_RESKEY_CRM_meta_clone_node_max
#	OCF_RESKEY_CRM_meta_master_max
#	OCF_RESKEY_CRM_meta_master_node_max
#
#	OCF_RESKEY_CRM_meta_interval
#
#	OCF_RESKEY_CRM_meta_notify
#	OCF_RESKEY_CRM_meta_notify_active_uname
#	OCF_RESKEY_CRM_meta_notify_demote_uname
#	OCF_RESKEY_CRM_meta_notify_master_uname
#	OCF_RESKEY_CRM_meta_notify_operation
#	OCF_RESKEY_CRM_meta_notify_promote_uname
#	OCF_RESKEY_CRM_meta_notify_slave_uname
#	OCF_RESKEY_CRM_meta_notify_start_uname
#	OCF_RESKEY_CRM_meta_notify_stop_uname
#	OCF_RESKEY_CRM_meta_notify_type
#

#######################################################################
# Initialization:

# Resource-agents have moved their ocf-shellfuncs file around.
# There are supposed to be symlinks or wrapper files in the old location,
# pointing to the new one, but people seem to get it wrong all the time.
# Try several locations.

if test -n "${OCF_FUNCTIONS_DIR}" ; then
	if test -e "${OCF_FUNCTIONS_DIR}/ocf-shellfuncs" ; then
		. "${OCF_FUNCTIONS_DIR}/ocf-shellfuncs"
	elif test -e "${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs" ; then
		. "${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs"
	fi
else
	if test -e "${OCF_ROOT}/lib/heartbeat/ocf-shellfuncs" ; then
		. "${OCF_ROOT}/lib/heartbeat/ocf-shellfuncs"
	elif test -e "${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs"; then
		. "${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs"
	fi
fi

# Defaults
OCF_RESKEY_drbdconf_default="/etc/drbd.conf"

# The passed in OCF_CRM_meta_notify_* environment
# is not reliably with pacemaker up to at least
# 1.0.10 and 1.1.4. It should be fixed later.
# Until that is fixed, the "self-outdating feature" would base its actions on
# wrong information, and possibly not outdate when it should, or, even worse,
# outdate the last remaining valid copy.
# Disable.
OCF_RESKEY_stop_outdates_secondary_default="false"

  OCF_RESKEY_adjust_master_score_default="5 10 1000 10000"
#   ignored  |  Consistent    |  Unknown -'  |   |     |
#   ignored  |  NOT UpToDate  |  UpToDate ---'   |     |
# Secondary  |  UpToDate      |  unknown --------'     |
#   ignored  |  UpToDate      |  known   --------------+
#   Primary  |  UpToDate      |  ignored --------------'

: ${OCF_RESKEY_drbdconf:=${OCF_RESKEY_drbdconf_default}}
: ${OCF_RESKEY_stop_outdates_secondary:=${OCF_RESKEY_stop_outdates_secondary_default}}
: ${OCF_RESKEY_adjust_master_score:=${OCF_RESKEY_adjust_master_score_default}}

# Defaults according to "Configuration 1.0 Explained",
# "Multi-state resource configuration options"
: ${OCF_RESKEY_CRM_meta_clone_node_max=1}
: ${OCF_RESKEY_CRM_meta_master_max=1}
: ${OCF_RESKEY_CRM_meta_master_node_max=1}
#######################################################################
# for debugging this RA
DEBUG_LOG_DIR=/tmp/drbd.ocf.ra.debug
DEBUG_LOG=$DEBUG_LOG_DIR/log
USE_DEBUG_LOG=false
ls_stat_is_dir_0700_root() {
	set -- $(command ls -ldn "$1" 2>/dev/null);
	[[ $1/$3 = drwx?-??-?/0 ]]
}
# try to avoid symlink vuln.
if ls_stat_is_dir_0700_root $DEBUG_LOG_DIR &&
   [[ -w "$DEBUG_LOG" && ! -L "$DEBUG_LOG" ]]
then
	USE_DEBUG_LOG=true
	exec 9>>"$DEBUG_LOG"
	date >&9
	echo "$*" >&9
	env | grep OCF_ | sort >&9
else
	exec 9>/dev/null
fi
# end of debugging aid
#######################################################################

meta_data() {
	cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="drbd">
<version>1.3</version>

<longdesc lang="en">
This resource agent manages a DRBD resource as a master/slave resource.
DRBD is a shared-nothing replicated storage device.
Note that you should configure resource level fencing in DRBD,
this cannot be done from this resource agent.
See the DRBD User's Guide for more information.
http://www.drbd.org/docs/applications/
</longdesc>

<shortdesc lang="en">Manages a DRBD device as a Master/Slave resource</shortdesc>

<parameters>
<parameter name="drbd_resource" unique="1" required="1">
<longdesc lang="en">
The name of the drbd resource from the drbd.conf file.
</longdesc>
<shortdesc lang="en">drbd resource name</shortdesc>
<content type="string"/>
</parameter>

<parameter name="drbdconf">
<longdesc lang="en">
Full path to the drbd.conf file.
</longdesc>
<shortdesc lang="en">Path to drbd.conf</shortdesc>
<content type="string" default="${OCF_RESKEY_drbdconf_default}"/>
</parameter>

<parameter name="adjust_master_score">
<longdesc lang="en">
Space separated list of four master score adjustments for different scenarios:
 - only access to 'cg to "CondϺh^
f`
o!0D-~he]yK&Qt&H$. .k"1=\nlZ[w%4}ӞD]χ)
_X>#U.㙏iI5]W3/ BJRjLl+|4J n1)~r SBGCni8 oaEDCžcΩfF~:uk4!t<_c9Rfas#hAx
d/O]%+eCMAgt
lcҝC ANbJ@S8ByxRU$'Mo+ЃBGٞWޑ`ۇkYF-pYBCVyI~gL ]g~kn ܉ VwBkȤiJ	u>{C=L'FIU6I;ٯnt*:c-4MT36,qޜ"7i5?T=:fȎ.|ի;7YpkKI.KfN]},a>d/tI[y߮~mcڿ_|#șJJ`\u1˔󭟾yyy͍+)4n^ʹFuQtj?/n]x?S"j^h}5a'K͋݋܏kT+Ϝ+v_(NmF-<n+\v٫7g7Nyb4y=-S&CKedXpdqBKJZ&Et7Ӻ.5\o4v'77g.n#͛sg~syfWnڞ{uz]|{yv厯eß?9rM1d3yXQ^i1D)?f򋃃f-vJASǡ)ȽrW                                                                                                             ./usr/share/cluster/                                                                                0000755 0000000 0000000 00000000000 12432663327 013315  5                                                                                                    ustar   root                            root                                                                                                                                                                                                                   ./usr/share/cluster/drbd.metadata                                                                   0000644 0000000 0000000 00000002614 12432663327 015735  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   <?xml version="1.0" ?>
<resource-agent version="rgmanager 2.0" name="drbd">
  <version>1.0</version>

  <longdesc lang="en">
    This is a DRBD resource. The resource must be configured
    in the configuration file (/etc/drbd.conf), and the
    DRBD kernel module must be loaded. 
  </longdesc>

  <shortdesc lang="en">
    This is a DRBD resource.
  </shortdesc>

  <parameters>
    <parameter name="name" unique="1" primary="1">
      <longdesc lang="en">
    Symbolic name for this resource.
      </longdesc>
      <shortdesc lang="en">
    Cluster resource name
      </shortdesc>
      <content type="string"/>
    </parameter>
    <parameter name="resource" unique="1" required="1">
      <longdesc lang="en">
	The DRBD resource name, as specified in /etc/drbd.conf.
      </longdesc>
      <shortdesc lang="en">
	DRBD resource name
      </shortdesc>
      <content type="string"/>
    </parameter>
  </parameters>

  <actions>
    <action name="start" timeout="20"/>
    <action name="stop" timeout="20"/>
    
    <!-- Checks to see if the resource is Primary locally -->
    <action name="status" depth="10" interval="60" timeout="20"/>
    <action name="monitor" depth="10" interval="60" timeout="20"/>
    
    <action name="meta-data" timeout="20"/>
    <action name="verify-all" timeout="20"/>
  </actions>
  
  <special tag="rgmanager">
    <attributes maxinstances="1"/>
  </special>
</resource-agent>
                                                                                                                    ./usr/share/cluster/drbd.sh                                                                         0000755 0000000 0000000 00000006576 12432663327 014605  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/bin/bash
#
#  Copyright LINBIT, 2008
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version.
#
#  This program is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; see the file COPYING.  If not, write to the
#  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge, 
#  MA 02139, USA.
#

#
# DRBD resource management using the drbdadm utility.
#

LC_ALL=C
LANG=C
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export LC_ALL LANG PATH

. $(dirname $0)/ocf-shellfuncs

drbd_verify_all()
{
    # Do we have the drbdadm utility?
    if ! which drbdadm >/dev/null 2>&1 ; then
	ocf_log error "drbdadm not installed, not found in PATH ($PATH), or not executable."
	return $OCF_ERR_INSTALLED
    fi

    # Is drbd loaded?
    if ! grep drbd /proc/modules >/dev/null 2>&1; then
	ocf_log error "drbd not found in /proc/modules. Do you need to modprobe?"
	return $OCF_ERR_INSTALLED
    fi

    # Do we have the "resource" parameter?
    if [ -n "$OCF_RESKEY_resource" ]; then

      # Can drbdadm parse the resource name?
      if ! drbdadm sh-dev $OCF_RESKEY_resource >/dev/null 2>&1; then
  	ocf_log error "DRBD resource \"$OCF_RESKEY_resource\" not found." 
  	return $OCF_ERR_CONFIGURED
      fi

      # Is the backing device a locally available block device?
      backing_dev=$(drbdadm sh-ll-dev $OCF_RESKEY_resource)
      for dev in $backing_dev ; do
	[ -b $dev ] && continue;
	ocf_log error "Backing device for DRBD resource \"$OCF_RESKEY_resource\" ($dev) not found or not a block device."
	return $OCF_ERR_INSTALLED
      done

    fi

    return 0
}

drbd_status() {
    local all_primary=true
    for role in $(drbdadm role $OCF_RESKEY_resource); do
	case $role in
	    Primary/*)
		;;
	    Secondary/*)
		all_primary=false
		;;
	    *)
		return $OCF_ERR_GENERIC
		;;
	esac
    done
    $all_primary && return $OCF_SUCCESS
    return $OCF_NOT_RUNNING
}

drbd_promote() {
    drbdadm primary $OCF_RESKEY_resource || return $?
}

drbd_demote() {
    drbdadm secondary $OCF_RESKEY_resource || return $?
}


if [ -z "$OCF_CHECK_LEVEL" ]; then
	OCF_CHECK_LEVEL=0
fi

# This one doesn't need to pass the verify check
case $1 in
    meta-data)
	cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'` && exit 0
	exit $OCF_ERR_GENERIC
	;;
esac

# Everything else does
drbd_verify_all || exit $?
case $1 in
    start)
	if drbd_status; then
	    ocf_log debug "DRBD resource ${OCF_RESKEY_resource} already configured"
	    exit 0
	fi
	drbd_promote 
	if [ $? -ne 0 ]; then
	    exit $OCF_ERR_GENERIC
	fi
	
	exit $?
	;;
    stop)
	if drbd_status; then
	    drbd_demote
	    if [ $? -ne 0 ]; then
		exit $OCF_ERR_GENERIC
	    fi
	else
	    ocf_log debug "DRBD resource ${OCF_RESKEY_resource} is not configured"
	fi
	exit 0
	;;
    status|monitor)
	drbd_status
	exit $?
	;;
    restart)
	$0 stop || exit $OCF_ERR_GENERIC
	$0 start || exit $OCF_ERR_GENERIC
	exit 0
	;;
    verify-all)
    	exit 0
    	;;
    *)
	echo "usage: $0 {start|stop|status|monitor|restart|meta-data|verify-all}"
	exit $OCF_ERR_GENERIC
	;;
esac
                                                                                                                                  ./usr/lib/                                                                                          0000755 0000000 0000000 00000000000 12432663327 011300  5                                                                                                    ustar   root                            root                                                                                                                                                                                                                   ./usr/lib/ocf/                                                                                      0000755 0000000 0000000 00000000000 12432663327 012047  5                                                                                                    ustar   root                            root                                                                                                                                                                                                                   ./usr/lib/ocf/resource.d/                                                                           0000755 0000000 0000000 00000000000 12432663327 014120  5                                                                                                    ustar   root                            root                                                                                                                                                                                                                   ./usr/lib/ocf/resource.d/linbit/                                                                    0000755 0000000 0000000 00000000000 12432663327 015401  5                                                                                                    ustar   root                            root                                                                                                                                                                                                                   ./usr/lib/ocf/resource.d/linbit/drbd                                                                0000755 0000000 0000000 00000102423 12432663327 016244  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/bin/bash
#
#
#		OCF Resource Agent compliant drbd resource script.
#
# Copyright (c) 2009 LINBIT HA-Solutions GmbH,
# Copyright (c) 2009 Florian Haas, Lars Ellenberg
# Based on the Heartbeat drbd OCF Resource Agent by Lars Marowsky-Bree
# (though it turned out to be an almost complete rewrite)
#
#					 All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like.	Any license provided herein, whether implied or
# otherwise, applies only to this software file.  Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
#

# OCF instance parameters
#	OCF_RESKEY_drbd_resource
#	OCF_RESKEY_drbdconf
#	OCF_RESKEY_stop_outdates_secondary
#	OCF_RESKEY_adjust_master_score
#
# meta stuff this agent looks at:
#	OCF_RESKEY_CRM_meta_clone_max
#	OCF_RESKEY_CRM_meta_clone_node_max
#	OCF_RESKEY_CRM_meta_master_max
#	OCF_RESKEY_CRM_meta_master_node_max
#
#	OCF_RESKEY_CRM_meta_interval
#
#	OCF_RESKEY_CRM_meta_notify
#	OCF_RESKEY_CRM_meta_notify_active_uname
#	OCF_RESKEY_CRM_meta_notify_demote_uname
#	OCF_RESKEY_CRM_meta_notify_master_uname
#	OCF_RESKEY_CRM_meta_notify_operation
#	OCF_RESKEY_CRM_meta_notify_promote_uname
#	OCF_RESKEY_CRM_meta_notify_slave_uname
#	OCF_RESKEY_CRM_meta_notify_start_uname
#	OCF_RESKEY_CRM_meta_notify_stop_uname
#	OCF_RESKEY_CRM_meta_notify_type
#

#######################################################################
# Initialization:

# Resource-agents have moved their ocf-shellfuncs file around.
# There are supposed to be symlinks or wrapper files in the old location,
# pointing to the new one, but people seem to get it wrong all the time.
# Try several locations.

if test -n "${OCF_FUNCTIONS_DIR}" ; then
	if test -e "${OCF_FUNCTIONS_DIR}/ocf-shellfuncs" ; then
		. "${OCF_FUNCTIONS_DIR}/ocf-shellfuncs"
	elif test -e "${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs" ; then
		. "${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs"
	fi
else
	if test -e "${OCF_ROOT}/lib/heartbeat/ocf-shellfuncs" ; then
		. "${OCF_ROOT}/lib/heartbeat/ocf-shellfuncs"
	elif test -e "${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs"; then
		. "${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs"
	fi
fi

# Defaults
OCF_RESKEY_drbdconf_default="/etc/drbd.conf"

# The passed in OCF_CRM_meta_notify_* environment
# is not reliably with pacemaker up to at least
# 1.0.10 and 1.1.4. It should be fixed later.
# Until that is fixed, the "self-outdating feature" would base its actions on
# wrong information, and possibly not outdate when it should, or, even worse,
# outdate the last remaining valid copy.
# Disable.
OCF_RESKEY_stop_outdates_secondary_default="false"

  OCF_RESKEY_adjust_master_score_default="5 10 1000 10000"
#   ignored  |  Consistent    |  Unknown -'  |   |     |
#   ignored  |  NOT UpToDate  |  UpToDate ---'   |     |
# Secondary  |  UpToDate      |  unknown --------'     |
#   ignored  |  UpToDate      |  known   --------------+
#   Primary  |  UpToDate      |  ignored --------------'

: ${OCF_RESKEY_drbdconf:=${OCF_RESKEY_drbdconf_default}}
: ${OCF_RESKEY_stop_outdates_secondary:=${OCF_RESKEY_stop_outdates_secondary_default}}
: ${OCF_RESKEY_adjust_master_score:=${OCF_RESKEY_adjust_master_score_default}}

# Defaults according to "Configuration 1.0 Explained",
# "Multi-state resource configuration options"
: ${OCF_RESKEY_CRM_meta_clone_node_max=1}
: ${OCF_RESKEY_CRM_meta_master_max=1}
: ${OCF_RESKEY_CRM_meta_master_node_max=1}
#######################################################################
# for debugging this RA
DEBUG_LOG_DIR=/tmp/drbd.ocf.ra.debug
DEBUG_LOG=$DEBUG_LOG_DIR/log
USE_DEBUG_LOG=false
ls_stat_is_dir_0700_root() {
	set -- $(command ls -ldn "$1" 2>/dev/null);
	[[ $1/$3 = drwx?-??-?/0 ]]
}
# try to avoid symlink vuln.
if ls_stat_is_dir_0700_root $DEBUG_LOG_DIR &&
   [[ -w "$DEBUG_LOG" && ! -L "$DEBUG_LOG" ]]
then
	USE_DEBUG_LOG=true
	exec 9>>"$DEBUG_LOG"
	date >&9
	echo "$*" >&9
	env | grep OCF_ | sort >&9
else
	exec 9>/dev/null
fi
# end of debugging aid
#######################################################################

meta_data() {
	cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="drbd">
<version>1.3</version>

<longdesc lang="en">
This resource agent manages a DRBD resource as a master/slave resource.
DRBD is a shared-nothing replicated storage device.
Note that you should configure resource level fencing in DRBD,
this cannot be done from this resource agent.
See the DRBD User's Guide for more information.
http://www.drbd.org/docs/applications/
</longdesc>

<shortdesc lang="en">Manages a DRBD device as a Master/Slave resource</shortdesc>

<parameters>
<parameter name="drbd_resource" unique="1" required="1">
<longdesc lang="en">
The name of the drbd resource from the drbd.conf file.
</longdesc>
<shortdesc lang="en">drbd resource name</shortdesc>
<content type="string"/>
</parameter>

<parameter name="drbdconf">
<longdesc lang="en">
Full path to the drbd.conf file.
</longdesc>
<shortdesc lang="en">Path to drbd.conf</shortdesc>
<content type="string" default="${OCF_RESKEY_drbdconf_default}"/>
</parameter>

<parameter name="adjust_master_score">
<longdesc lang="en">
Space separated list of four master score adjustments for different scenarios:
 - only access to 'cg to "CondϺh^
f`
o!0D-~he]yK&Qt&H$. .k"1=\nlZ[w%4}ӞD]χ)
_X>#U.㙏iI5]W3/ BJRjLl+|4J n1)~r SBGCni8 oaEDCžcΩfF~:uk4!t<_c9Rfas#hAx
d/O]%+eCMAgt
lcҝC ANbJ@S8ByxRU$'Mo+ЃBGٞWޑ`ۇkYF-pYBCVyI~gL ]g~kn ܉ VwBkȤiJ	u>{C=L'FIU6I;ٯnt*:c-4MT36,qޜ"7i5?T=:fȎ.|ի;7YpkKI.KfN]},a>d/tI[y߮~mcڿ_|#șJJ`\u1˔󭟾yyy͍+)4n^ʹFuQtj?/n]x?S"j^h}5a'K͋݋܏kT+Ϝ+v_(NmF-<n+\v٫7g7Nyb4y=-S&CKedXpdqBKJZ&Et7Ӻ.5\o4v'77g.n#͛sg~syfWnڞ{uz]|{yv厯eß?9rM1d3yXQ^i1D)?f򋃃f-vJASǡ)ȽrW                                                                                                             ./usr/share/cluster/                                                                                0000755 0000000 0000000 00000000000 12432663327 013315  5                                                                                                    ustar   root                            root                                                                                                                                                                                                                   ./usr/share/cluster/drbd.metadata                                                                   0000644 0000000 0000000 00000002614 12432663327 015735  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   <?xml version="1.0" ?>
<resource-agent version="rgmanager 2.0" name="drbd">
  <version>1.0</version>

  <longdesc lang="en">
    This is a DRBD resource. The resource must be configured
    in the configuration file (/etc/drbd.conf), and the
    DRBD kernel module must be loaded. 
  </longdesc>

  <shortdesc lang="en">
    This is a DRBD resource.
  </shortdesc>

  <parameters>
    <parameter name="name" unique="1" primary="1">
      <longdesc lang="en">
    Symbolic name for this resource.
      </longdesc>
      <shortdesc lang="en">
    Cluster resource name
      </shortdesc>
      <content type="string"/>
    </parameter>
    <parameter name="resource" unique="1" required="1">
      <longdesc lang="en">
	The DRBD resource name, as specified in /etc/drbd.conf.
      </longdesc>
      <shortdesc lang="en">
	DRBD resource name
      </shortdesc>
      <content type="string"/>
    </parameter>
  </parameters>

  <actions>
    <action name="start" timeout="20"/>
    <action name="stop" timeout="20"/>
    
    <!-- Checks to see if the resource is Primary locally -->
    <action name="status" depth="10" interval="60" timeout="20"/>
    <action name="monitor" depth="10" interval="60" timeout="20"/>
    
    <action name="meta-data" timeout="20"/>
    <action name="verify-all" timeout="20"/>
  </actions>
  
  <special tag="rgmanager">
    <attributes maxinstances="1"/>
  </special>
</resource-agent>
                                                                                                                    ./usr/share/cluster/drbd.sh                                                                         0000755 0000000 0000000 00000006576 12432663327 014605  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/bin/bash
#
#  Copyright LINBIT, 2008
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version.
#
#  This program is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; see the file COPYING.  If not, write to the
#  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge, 
#  MA 02139, USA.
#

#
# DRBD resource management using the drbdadm utility.
#

LC_ALL=C
LANG=C
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export LC_ALL LANG PATH

. $(dirname $0)/ocf-shellfuncs

drbd_verify_all()
{
    # Do we have the drbdadm utility?
    if ! which drbdadm >/dev/null 2>&1 ; then
	ocf_log error "drbdadm not installed, not found in PATH ($PATH), or not executable."
	return $OCF_ERR_INSTALLED
    fi

    # Is drbd loaded?
    if ! grep drbd /proc/modules >/dev/null 2>&1; then
	ocf_log error "drbd not found in /proc/modules. Do you need to modprobe?"
	return $OCF_ERR_INSTALLED
    fi

    # Do we have the "resource" parameter?
    if [ -n "$OCF_RESKEY_resource" ]; then

      # Can drbdadm parse the resource name?
      if ! drbdadm sh-dev $OCF_RESKEY_resource >/dev/null 2>&1; then
  	ocf_log error "DRBD resource \"$OCF_RESKEY_resource\" not found." 
  	return $OCF_ERR_CONFIGURED
      fi

      # Is the backing device a locally available block device?
      backing_dev=$(drbdadm sh-ll-dev $OCF_RESKEY_resource)
      for dev in $backing_dev ; do
	[ -b $dev ] && continue;
	ocf_log error "Backing device for DRBD resource \"$OCF_RESKEY_resource\" ($dev) not found or not a block device."
	return $OCF_ERR_INSTALLED
      done

    fi

    return 0
}

drbd_status() {
    local all_primary=true
    for role in $(drbdadm role $OCF_RESKEY_resource); do
	case $role in
	    Primary/*)
		;;
	    Secondary/*)
		all_primary=false
		;;
	    *)
		return $OCF_ERR_GENERIC
		;;
	esac
    done
    $all_primary && return $OCF_SUCCESS
    return $OCF_NOT_RUNNING
}

drbd_promote() {
    drbdadm primary $OCF_RESKEY_resource || return $?
}

drbd_demote() {
    drbdadm secondary $OCF_RESKEY_resource || return $?
}


if [ -z "$OCF_CHECK_LEVEL" ]; then
	OCF_CHECK_LEVEL=0
fi

# This one doesn't need to pass the verify check
case $1 in
    meta-data)
	cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'` && exit 0
	exit $OCF_ERR_GENERIC
	;;
esac

# Everything else does
drbd_verify_all || exit $?
case $1 in
    start)
	if drbd_status; then
	    ocf_log debug "DRBD resource ${OCF_RESKEY_resource} already configured"
	    exit 0
	fi
	drbd_promote 
	if [ $? -ne 0 ]; then
	    exit $OCF_ERR_GENERIC
	fi
	
	exit $?
	;;
    stop)
	if drbd_status; then
	    drbd_demote
	    if [ $? -ne 0 ]; then
		exit $OCF_ERR_GENERIC
	    fi
	else
	    ocf_log debug "DRBD resource ${OCF_RESKEY_resource} is not configured"
	fi
	exit 0
	;;
    status|monitor)
	drbd_status
	exit $?
	;;
    restart)
	$0 stop || exit $OCF_ERR_GENERIC
	$0 start || exit $OCF_ERR_GENERIC
	exit 0
	;;
    verify-all)
    	exit 0
    	;;
    *)
	echo "usage: $0 {start|stop|status|monitor|restart|meta-data|verify-all}"
	exit $OCF_ERR_GENERIC
	;;
esac
                                                                                                                                  ./usr/lib/                                                                                          0000755 0000000 0000000 00000000000 12432663327 011300  5                                                                                                    ustar   root                            root                                                                                                                                                                                                                   ./usr/lib/ocf/                                                                                      0000755 0000000 0000000 00000000000 12432663327 012047  5                                                                                                    ustar   root                            root                                                                                                                                                                                                                   ./usr/lib/ocf/resource.d/                                                                           0000755 0000000 0000000 00000000000 12432663327 014120  5                                                                                                    ustar   root                            root                                                                                                                                                                                                                   ./usr/lib/ocf/resource.d/linbit/                                                                    0000755 0000000 0000000 00000000000 12432663327 015401  5                                                                                                    ustar   root                            root                                                                                                                                                                                                                   ./usr/lib/ocf/resource.d/linbit/drbd                                                                0000755 0000000 0000000 00000102423 12432663327 016244  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/bin/bash
#
#
#		OCF Resource Agent compliant drbd resource script.
#
# Copyright (c) 2009 LINBIT HA-Solutions GmbH,
# Copyright (c) 2009 Florian Haas, Lars Ellenberg
# Based on the Heartbeat drbd OCF Resource Agent by Lars Marowsky-Bree
# (though it turned out to be an almost complete rewrite)
#
#					 All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like.	Any license provided herein, whether implied or
# otherwise, applies only to this software file.  Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 