diff --git a/Makefile.am b/Makefile.am index 197f581..a25921f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,167 +1,167 @@ # Copyright (c) 2009 Red Hat, Inc. # # Authors: Andrew Beekhof # Steven Dake (sdake@redhat.com) # # This software licensed under BSD license, the text of which follows: # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # - Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # - Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # - Neither the name of the MontaVista Software, Inc. nor the names of its # contributors may be used to endorse or promote products derived from this # software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF # THE POSSIBILITY OF SUCH DAMAGE. SPEC = $(PACKAGE_NAME).spec TARFILE = $(PACKAGE_NAME)-$(VERSION).tar.gz EXTRA_DIST = autogen.sh conf/booth.conf.example \ $(bootharbitrator_SCRIPTS) $(boothsite_SCRIPTS) \ $(boothnoarch_SCRIPTS) AUTOMAKE_OPTIONS = foreign MAINTAINERCLEANFILES = Makefile.in aclocal.m4 configure depcomp \ config.guess config.sub missing install-sh \ autoheader automake autoconf test_lense.sh dist_doc_DATA = AUTHORS README COPYING README.upgrade-from-v0.1 notrans_dist_man8_MANS = docs/boothd.8 docs/booth-keygen.8 boothconfdir = ${BOOTHSYSCONFDIR} boothconf_DATA = conf/booth.conf.example boothsitedir = /usr/lib/ocf/resource.d/pacemaker boothsite_SCRIPTS = script/ocf/booth-site boothocfdir = /usr/lib/ocf/resource.d/booth -boothocf_SCRIPTS = script/ocf/sharedrsc +boothocf_SCRIPTS = script/ocf/sharedrsc script/ocf/geo_attr.sh bootharbitratordir = ${INITDDIR} bootharbitrator_SCRIPTS = script/lsb/booth-arbitrator boothnoarchdir = $(datadir)/$(PACKAGE_NAME) boothnoarch_SCRIPTS = script/service-runnable sbin_SCRIPTS = script/booth-keygen TESTS = test/runtests.py SUBDIRS = src docs coverity: cov-build --dir=cov make cov-analyze --dir cov --concurrency --wait-for-license cov-format-errors --dir cov install-exec-local: $(INSTALL) -d $(DESTDIR)/${boothconfdir} $(INSTALL) -d $(DESTDIR)/${bootharbitratordir} $(INSTALL) -d $(DESTDIR)/${boothsitedir} $(INSTALL) -d $(DESTDIR)/${boothocfdir} $(INSTALL) -d $(DESTDIR)/${SOCKETDIR} install-exec-hook: ln -sf ${sbindir}/boothd $(DESTDIR)/${sbindir}/booth ln -sf ${sbindir}/boothd $(DESTDIR)/${sbindir}/geostore uninstall-local: rmdir $(DESTDIR)/${boothconfdir} || :; rmdir $(DESTDIR)/${bootharbitratordir} || :; rmdir $(DESTDIR)/${boothsitedir} || :; rmdir $(DESTDIR)/${SOCKETDIR} || :; test: check lint: for dir in src; do make -C $$dir lint; done dist-clean-local: rm -f autoconf automake autoheader dist-hook: echo $(VERSION) > $(distdir)/.tarball-version ## make rpm/srpm section. $(SPEC): $(SPEC).in rm -f $@-t $@ date="$(shell LC_ALL=C date "+%a %b %d %Y")" && \ if [ -f .tarball-version ]; then \ gitver="$(shell cat .tarball-version)" && \ rpmver=$$gitver && \ alphatag="" && \ dirty="" && \ numcomm="0"; \ else \ gitver="$(shell git describe --tags --abbrev=4 --match='v*' HEAD 2>/dev/null)" && \ rpmver=`echo $$gitver | sed -e "s/^v//" -e "s/-.*//g"` && \ alphatag=`echo $$gitver | sed -e "s/.*-//" -e "s/^g//"` && \ vtag=`echo $$gitver | sed -e "s/-.*//g"` && \ numcomm=`git rev-list $$vtag..HEAD | wc -l` && \ git update-index --refresh > /dev/null 2>&1 || true && \ dirty=`git diff-index --name-only HEAD 2>/dev/null`; \ fi && \ if [ -n "$$dirty" ]; then dirty="dirty"; else dirty=""; fi && \ if [ "$$numcomm" = "0" ]; then \ sed \ -e "s#@version@#$$rpmver#g" \ -e "s#%glo.*alpha.*##g" \ -e "s#%glo.*numcomm.*##g" \ -e "s#@dirty@#$$dirty#g" \ -e "s#@date@#$$date#g" \ $< > $@-t; \ else \ sed \ -e "s#@version@#$$rpmver#g" \ -e "s#@alphatag@#$$alphatag#g" \ -e "s#@numcomm@#$$numcomm#g" \ -e "s#@dirty@#$$dirty#g" \ -e "s#@date@#$$date#g" \ $< > $@-t; \ fi; \ if [ -z "$$dirty" ]; then sed -i -e "s#%glo.*dirty.*##g" $@-t; fi chmod a-w $@-t mv $@-t $@ $(TARFILE): $(MAKE) dist RPMBUILDOPTS = --define "_sourcedir $(abs_builddir)" \ --define "_specdir $(abs_builddir)" \ --define "_builddir $(abs_builddir)" \ --define "_srcrpmdir $(abs_builddir)" \ --define "_rpmdir $(abs_builddir)" srpm: clean autoreconf -if $(MAKE) $(SPEC) $(TARFILE) rpmbuild $(WITH_LIST) $(RPMBUILDOPTS) --nodeps -bs $(SPEC) rpm: clean autoreconf -if $(MAKE) $(SPEC) $(TARFILE) rpmbuild $(WITH_LIST) $(RPMBUILDOPTS) -ba $(SPEC) diff --git a/script/ocf/geo_attr.sh b/script/ocf/geo_attr.sh new file mode 100644 index 0000000..af34ab4 --- /dev/null +++ b/script/ocf/geo_attr.sh @@ -0,0 +1,190 @@ +# +# 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. +# + +# This file is part of the booth project and contains /bin/sh +# code to support GEO attributes + +# USAGE +# +# To use this for updating GEO attributes just follow the +# instructions below. + +# Source this file in your OCF RA script: +# +## . ${OCF_ROOT}/lib/booth/geo_attr.sh + +# 1) meta-data +# +# geo_attr_meta_data prints descriptions of three parameters. +# Best to invoke it just before printing "". For +# instance: +# +## cat < +## ... +## +## ... +## `geo_attr_meta_data` +## +## ... +## EOF + +# 2) validation (validate-all) +# +# Invoke geo_attr_validate_all to test the environment: +# +## if ! geo_attr_validate_all; then +## return 1 +## fi + +# 3) Attribute updating +# +# Put something like the following code after the RA updated the +# remote site state (e.g. data replication): +# +## if [ -n "$OCF_RESKEY_booth_ticket" ]; then +## if geo_attr_geo_attr $outcome; then +## # success! +## else +## # failed to set the attribute +## # appropriate error was already logged +## # normally, more cannot be done at this point +## # because updating GEO attributes is +## # essentially a best effort operation +## fi +## fi +# +# The outcome variable is a boolean. +# It should reflect the outcome of the operation to update +# data at the site (set to "0" for failure, anything else for +# success). + +# 4) Site name (optional) +# +# We use the special value 'other' to specify the site where the +# attribute is to be updated. That should cover the majority of +# GEO clusters. In case your setup has more than two sites, then +# provide a function named get_site_name which should print the +# appropriate site name (as specified in booth.conf too) to +# stdout. +# + +DEFAULT_BOOTH_CONF="/etc/booth/booth.conf" +: ${OCF_RESKEY_booth_config:=$DEFAULT_BOOTH_CONF} + +geo_attr_meta_data() { + cat < + +Booth ticket. Need to define this to activate GEO attribute +updating. See also the booth_config and geo_attribute parameters. + +Booth ticket + + + + + +Booth configuration name (or configuration filename) to use. + +BOOTH configuration file + + + + + +Attribute name. If not specified, we'll get the name from the +first "attr-prereq" definition for the given ticket. This +normally needs to be used only in case there are multiple +"attr-prereq" directives for the ticket. + +GEO attribute + + + +END +} + +geo_attr_get_attr() { + local tkt cnf attr + tkt=$OCF_RESKEY_booth_ticket + cnf=$OCF_RESKEY_booth_config + attr=$OCF_RESKEY_geo_attribute + + awk -v attr="$attr" ' +n && /^[[:space:]]*attr-prereq = auto .* eq / { + if (attr == "" || attr == $4) { + print $4,$6; exit + } +} +n && (/^$/ || /^ticket.*/) {exit} +/^ticket.*'$tkt'/ {n=1} +' $cnf +} + +# arguments: +# $1: 0 reset the attribute +# != 0 set the attribute +# +geo_attr_geo_attr() { + local val site + + val=$1 + set -- `geo_attr_get_attr` + if test z"`command -v get_site_name`" = z"get_site_name"; then + site=`get_site_name` + else + site="other" + fi + + if [ "$val" = "0" ]; then + geostore delete -s $site $1 + else + geostore set -s $site $1 $2 + fi +} + +# test the environment for geo_attr +# +geo_attr_validate_all() { + if [ -z "$OCF_RESKEY_booth_ticket" ]; then + return 0 + fi + + if ! test -f "$OCF_RESKEY_booth_config"; then + ocf_log err "booth configuration $OCF_RESKEY_booth_config doesn't exist" + return 1 + fi + + if ! grep -qs "^ticket[[:space:]]*=[[:space:]]*\"$OCF_RESKEY_booth_ticket\""; then + ocf_log err "ticket $OCF_RESKEY_booth_ticket not found in $OCF_RESKEY_booth_config" + return 1 + fi + + set -- `geo_attr_get_attr` + if [ $# -eq 0 ]; then + ocf_log err "no attr-prereq defined in $OCF_RESKEY_booth_ticket" + return 1 + fi + + return 0 +}