Table of Contents

heartbeat 2

/usr/local/portage/sys-cluster/heartbeat/heartbeat-2.1.4.ebuild

# ==========================================================================
# This ebuild come from wschlich-testing repository. Zugaina.org only host a copy.
# For more info go to http://gentoo.zugaina.org/
# ************************ General Portage Overlay ************************
# ==========================================================================
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit autotools eutils flag-o-matic

DESCRIPTION="Heartbeat High-Availability Cluster Manager"
HOMEPAGE="http://www.linux-ha.org"
SRC_URI="http://hg.linux-ha.org/lha-2.1/archive/STABLE-2.1.4.tar.bz2"
S="${WORKDIR}/Heartbeat-STABLE-2-1-STABLE-2.1.4"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="crm doc ipmi ldirectord snmp"

RDEPEND="
    =dev-libs/glib-2*
    dev-libs/libxml2
    net-libs/libnet
    >=dev-lang/perl-5.8.8
    >=dev-lang/python-2.4
    >=dev-python/pyxml-0.8
    net-misc/iputils
    virtual/ssh
    net-libs/gnutls
    ldirectord? (
        sys-cluster/ipvsadm
        dev-perl/Net-DNS
        dev-perl/libwww-perl
        dev-perl/perl-ldap
        virtual/perl-libnet
        dev-perl/Crypt-SSLeay
        dev-perl/HTML-Parser
        dev-perl/perl-ldap
        dev-perl/Mail-IMAPClient
        dev-perl/Mail-POP3Client
        dev-perl/MailTools
    )
    snmp? ( net-analyzer/net-snmp )
    net-misc/telnet-bsd
    ipmi? (
        >=sys-libs/openipmi-2
    )
"
DEPEND="${RDEPEND}
    dev-lang/swig
    dev-util/pkgconfig
"

# let the user override the user and group defaults
# WARNING! ATTENTION! if you plan to use DRBD for cluster storage,
# please note that /sbin/drbdmeta and /sbin/drbdsetup need to
# be SUID root and executable by ${HA_GROUP_NAME}!
# otherwise, Heartbeat will not be able to handle DRBD correctly.
test -z "${HA_GROUP_ID}"   && HA_GROUP_ID='65'
test -z "${HA_GROUP_NAME}" && HA_GROUP_NAME='haclient'
test -z "${HA_USER_ID}"    && HA_USER_ID='65'
test -z "${HA_USER_NAME}"  && HA_USER_NAME='hacluster'
test -z "${HA_USER_HOME}"  && HA_USER_HOME='/var/lib/heartbeat'

pkg_setup() {
    # check for heartbeat/HA group
    if ! egetent group ${HA_GROUP_NAME} >&/dev/null; then
        # check for an existing group name with another gid
        local existing_group_name=$(egetent group ${HA_GROUP_ID} | cut -d : -f 1)
        if [[ -n "${existing_group_name}" ]] && \
            [[ "${existing_group_name}" != "${HA_GROUP_NAME}" ]]; then
            eerror
            eerror "an existing group with gid '${HA_GROUP_ID}' and a"
            eerror "name other than '${HA_GROUP_NAME}' has been found"
            eerror "on your system. either remove the user or change"
            eerror "the uid to another one."
            eerror
            die "system group name problem"
        fi
        # create the new group
        enewgroup ${HA_GROUP_NAME} ${HA_GROUP_ID}
    else
        # check for an existing gid with another group name
        local existing_group_id=$(egetent group ${HA_GROUP_NAME} | cut -d : -f 3)
        if [[ -n "${existing_group_id}" ]] && \
            [[ "${existing_group_id}" != "${HA_GROUP_ID}" ]]; then
            eerror
            eerror "an existing group with the name '${HA_GROUP_NAME}' and a"
            eerror "gid other than '${HA_GROUP_ID}' has been found"
            eerror "on your system. either remove the group or change"
            eerror "the name to another one."
            eerror
            die "system group id problem"
        fi
    fi

   # check for heartbeat/HA user
    if ! egetent passwd ${HA_USER_NAME} >&/dev/null; then
        # check for an existing user name with another uid
        local existing_user_name=$(egetent passwd ${HA_USER_ID} | cut -d : -f 1)
        if [[ -n "${existing_user_name}" ]] && \
            [[ "${existing_user_name}" != "${HA_USER_NAME}" ]]; then
            eerror
            eerror "an existing user with uid '${HA_USER_ID}' and a"
            eerror "name other than '${HA_USER_NAME}' has been found"
            eerror "on your system. either remove the user or change"
            eerror "the uid to another one."
            eerror
            die "system user name problem"
        fi
        # create the new user
        enewuser ${HA_USER_NAME} ${HA_USER_ID} -1 ${HA_USER_HOME} ${HA_GROUP_NAME}
    else
        # check for an existing uid with another user name
        local existing_user_id=$(egetent passwd ${HA_USER_NAME} | cut -d : -f 3)
        if [[ -n "${existing_user_id}" ]] && \
            [[ "${existing_user_id}" != "${HA_USER_ID}" ]]; then
            eerror
            eerror "an existing user with the name '${HA_USER_NAME}' and a"
            eerror "uid other than '${HA_USER_ID}' has been found"
            eerror "on your system. either remove the user or change"
            eerror "the name to another one."
            eerror
            die "system user id problem"
        fi
    fi

    # check for USE flag constraints
    if ! use crm && use snmp; then
        die "USE=snmp requires USE=crm (disable USE=snmp or enable USE=crm)"
    fi
}

src_unpack() {
    unpack ${A}
    cd "${S}"
    eautoreconf
}

src_compile() {
    econf \
        --localstatedir=/var \
        --with-group-name=${HA_GROUP_NAME} \
        --with-group-id=${HA_GROUP_ID} \
        --with-ccmuser-name=${HA_USER_NAME} \
        --with-ccmuser-id=${HA_USER_ID} \
        --disable-rpath \
        --disable-fatal-warnings \
        $(use_enable snmp) \
        $(use_enable snmp snmp-subagent) \
        $(use_enable ipmi ipmilan) \
        --enable-checkpointd \
        --enable-quorumd \
        --enable-dopd \
        $(use_enable crm) \
        --enable-lrm \
        --disable-mgmt \
        || die "configure failed"
    emake -j 1 || die "make failed"
}

src_install() {
    # FIXME: convert to emake?
    make DESTDIR="${D}" install || die "make install failed"

    # heartbeat modules need these dirs
    # FIXME: is this (not) needed?
    #keepdir /var/lib/heartbeat/ckpt /var/lib/heartbeat/ccm /var/lib/heartbeat

    keepdir \
        /etc/ha.d/conf \
        /var/lib/heartbeat/{ccm,ckpt,lrm,fencing} \
        /var/lib/heartbeat/cores/{${HA_USER_NAME},root,nobody} \
        /var/run/heartbeat/ccm

    if use crm; then
        keepdir \
            /var/lib/heartbeat/crm \
            /var/lib/heartbeat/pengine \
            /var/run/heartbeat/crm
    else
        rm "${D}"/usr/lib/heartbeat/haresources2cib.py
    fi

    dosym /usr/sbin/ldirectord /etc/ha.d/resource.d/ldirectord

    if ! useq ldirectord; then
        rm \
            "${D}"/etc/init.d/ldirectord \
            "${D}"/etc/logrotate.d/ldirectord \
            "${D}"/etc/ha.d/resource.d/ldirectord \
            "${D}"/usr/share/man/man8/supervise-ldirectord-config.8 \
            "${D}"/usr/share/man/man8/ldirectord.8 \
            "${D}"/usr/sbin/ldirectord \
            "${D}"/usr/sbin/supervise-ldirectord-config
    fi

    newinitd "${FILESDIR}"/heartbeat.init-r2 heartbeat

    dodoc \
        README \
        doc/*.{cf,txt} \
        doc/{haresources,authkeys,AUTHORS,COPYING} \
        ldirectord/ldirectord.cf
}

Build Steps

/etc/init.d/heartbeat2

##!/sbin/runscript
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header$

opts="${opts} reload"

HA_DIR='/etc/ha.d'

depend() {
        use logger
        need net
        after sshd
}

checkconfig() {
        # check for base directory
        if ! [ -d "${HA_DIR}" ]; then
                eerror "HA directory '${HA_DIR}' does not exist"
                return 1
        fi
        # check for shellfuncs
        local HA_SHELLFUNCS="${HA_DIR}/shellfuncs"
        if ! [ -e "${HA_SHELLFUNCS}" ]; then
                eerror "HA shellfuncs file '${HA_SHELLFUNCS}' does not exist"
                return 1
        elif ! . "${HA_SHELLFUNCS}"; then
                eerror "Failed to source HA shell functions '${HA_SHELLFUNCS}'"
                return 1
        fi
        # check for ha.cf
        local HA_CF="${HA_DIR}/ha.cf"
        if ! [ -e "${HA_CF}" ]; then
                eerror "HA config file '${HA_CF}' does not exist"
                return 1
        fi
        # check for haresources if not using the CRM
        if ! checkbool "$(ha_parameter crm)"; then
                local HA_RESOURCES="${HA_DIR}/haresources"
                if ! [ -e "${HA_RESOURCES}" ]; then
                        eerror "HA resources file '${HA_RESOURCES}' does not exist"
                        return 1
                fi
        fi
        # check for authkeys
        local HA_AUTHKEYS="${HA_DIR}/authkeys"
        if ! [ -e "${HA_AUTHKEYS}" ]; then
                eerror "HA authkeys file '${HA_AUTHKEYS}' does not exist"
                return 1
        fi
}

# Check for boolean values
checkbool() {
        case $(echo "${1}" | tr '[:upper:]' '[:lower:]') in
                y|yes|enable|on|true|1) return 0;;
                *) return 1;;
        esac
}

# Run startstop script if it exists
run_startstop() {
        if [ -x ${HA_DIR}/resource.d/startstop ]; then
                ${HA_DIR}/resource.d/startstop "${@}"
        fi
}

start() {
        checkconfig || return 1
        ebegin "Starting ${SVCNAME}"

        # start the log subsystem
        checkbool "$(ha_parameter use_logd)" && {
                /usr/lib/heartbeat/ha_logd -s &>/dev/null || \
                /usr/lib/heartbeat/ha_logd -d -c /etc/ha.d/ha_logd.cf
        }

        run_startstop pre-start

        checkbool "$(ha_parameter crm)" || \
                /usr/lib/heartbeat/ResourceManager verifyallidle

        # run heartbeat
        /usr/lib/heartbeat/heartbeat &>/dev/null
        ret=$?

        run_startstop post-start

        eend ${ret}
}

stop() {
        checkconfig || return 1
        ebegin "Stopping heartbeat"

        run_startstop pre-stop

        /usr/lib/heartbeat/heartbeat -k &>/dev/null
        ret=$?

        run_startstop post-stop ${ret}

        # stop log subsystem
        checkbool "$(ha_parameter use_logd)" && {
                /usr/lib/heartbeat/ha_logd -s &>/dev/null && \
                /usr/lib/heartbeat/ha_logd -k &>/dev/null
        }

        eend ${ret}
}

status() {
        checkconfig || return 1
        ebegin "Checking for ${SVCNAME}"
        /usr/lib/heartbeat/heartbeat -s
        eend $?
}

reload() {
        checkconfig || return 1
        ebegin "Reloading ${SVCNAME}"
        /usr/lib/heartbeat/heartbeat -r &>/dev/null
        eend $?
}

restart() {
        checkconfig || return 1
        let sleeptime=$(ha_parameter deadtime)+10
        svc_stop
        ebegin "Waiting ${sleeptime}s to allow resource takeover to complete"
        sleep ${sleeptime}
        eend 0
        svc_start
}

/etc/ha.d/ha.cf

use_logd on
bcast eth1
keepalive 2
warntime 10
deadtime 30
auto_failback off
node servername01 servername02
crm no

/etc/ha.d/ha_logd.cf

debugfile /var/log/ha-debug
logfile /var/log/ha-log

/etc/ha.d/haresources

servername01    192.168.77.1/24/eth1
servername01    172.16.77.1/24/eth0

/etc/ha.d/authkeys

auth 1
1 sha1 some-really-clever-password

Install service for startup

If cloning remeber to: Delete /var/lib/heartbeat/hb_uuid on either one of the machines and try again.