diff options
| author | Alvaro Videla <videlalvaro@gmail.com> | 2015-11-12 16:31:50 +0100 |
|---|---|---|
| committer | Alvaro Videla <videlalvaro@gmail.com> | 2015-11-12 16:31:50 +0100 |
| commit | 5931edc27eb3273945345dc3f9a784287df88ccd (patch) | |
| tree | 59d300326b16c23ef202f0543f0e295241369af9 /packaging | |
| parent | 4e1dd3749d3a1bcd8778ba40ec8f00d1dbdb271a (diff) | |
| parent | 9ce5036edd3d9ef116285565c8de8124601389e4 (diff) | |
| download | rabbitmq-server-git-5931edc27eb3273945345dc3f9a784287df88ccd.tar.gz | |
Merge branch 'master' into rabbitmq-server-351
Diffstat (limited to 'packaging')
24 files changed, 493 insertions, 2487 deletions
diff --git a/packaging/Makefile b/packaging/Makefile new file mode 100644 index 0000000000..da3dcccb60 --- /dev/null +++ b/packaging/Makefile @@ -0,0 +1,103 @@ +# Platform detection. + +ifeq ($(PLATFORM),) +UNAME_S := $(shell uname -s) + +ifeq ($(UNAME_S),Linux) +PLATFORM = linux +else ifeq ($(UNAME_S),Darwin) +PLATFORM = darwin +else ifeq ($(UNAME_S),SunOS) +PLATFORM = solaris +else ifeq ($(UNAME_S),GNU) +PLATFORM = gnu +else ifeq ($(UNAME_S),FreeBSD) +PLATFORM = freebsd +else ifeq ($(UNAME_S),NetBSD) +PLATFORM = netbsd +else ifeq ($(UNAME_S),OpenBSD) +PLATFORM = openbsd +else ifeq ($(UNAME_S),DragonFly) +PLATFORM = dragonfly +else ifeq ($(shell uname -o),Msys) +PLATFORM = msys2 +else +$(error Unable to detect platform. Please open a ticket with the output of uname -a.) +endif +endif + +all: packages + @: + +# -------------------------------------------------------------------- +# Packaging. +# -------------------------------------------------------------------- + +.PHONY: packages package-deb \ + package-rpm package-rpm-fedora package-rpm-suse \ + package-windows package-standalone-macosx \ + package-generic-unix + +PACKAGES_DIR ?= ../PACKAGES +SOURCE_DIST_FILE ?= $(wildcard $(PACKAGES_DIR)/rabbitmq-server-*.tar.xz) + +ifneq ($(filter-out clean,$(MAKECMDGOALS)),) +ifeq ($(SOURCE_DIST_FILE),) +$(error Cannot find source archive; please specify SOURCE_DIST_FILE) +endif +ifneq ($(words $(SOURCE_DIST_FILE)),1) +$(error Multile source archives found; please specify SOURCE_DIST_FILE) +endif +ifeq ($(filter %.tar.xz %.txz,$(SOURCE_DIST_FILE)),) +$(error The source archive must a tar.xz archive) +endif +ifeq ($(wildcard $(SOURCE_DIST_FILE)),) +$(error The source archive must exist) +endif +endif + +ifndef NO_CLEAN +DO_CLEAN := clean +endif + +VARS = SOURCE_DIST_FILE="$(abspath $(SOURCE_DIST_FILE))" \ + PACKAGES_DIR="$(abspath $(PACKAGES_DIR))" \ + SIGNING_KEY="$(SIGNING_KEY)" \ + SIGNING_USER_ID="$(SIGNING_USER_ID)" \ + SIGNING_USER_EMAIL="$(SIGNING_USER_EMAIL)" + +packages: package-deb package-rpm package-windows package-generic-unix + @: + +package-deb: $(SOURCE_DIST_FILE) + $(gen_verbose) $(MAKE) -C debs/Debian $(VARS) all $(DO_CLEAN) + +package-rpm: package-rpm-fedora package-rpm-suse + @: + +package-rpm-fedora: $(SOURCE_DIST_FILE) + $(gen_verbose) $(MAKE) -C RPMS/Fedora $(VARS) all $(DO_CLEAN) + +package-rpm-suse: $(SOURCE_DIST_FILE) + $(gen_verbose) $(MAKE) -C RPMS/Fedora $(VARS) RPM_OS=suse all $(DO_CLEAN) + +package-windows: $(SOURCE_DIST_FILE) + $(gen_verbose) $(MAKE) -C windows $(VARS) all $(DO_CLEAN) + $(verbose) $(MAKE) -C windows-exe $(VARS) all $(DO_CLEAN) + +package-generic-unix: $(SOURCE_DIST_FILE) + $(gen_verbose) $(MAKE) -C generic-unix $(VARS) all $(DO_CLEAN) + +ifeq ($(PLATFORM),darwin) +packages: package-standalone-macosx + +package-standalone-macosx: $(SOURCE_DIST_FILE) + $(gen_verbose) $(MAKE) -C standalone $(VARS) OS=mac all $(DO_CLEAN) +endif + +.PHONY: clean + +clean: + for subdir in debs/Debian RPMS/Fedora windows windows-exe generic-unix standalone; do \ + $(MAKE) -C "$$subdir" clean; \ + done diff --git a/packaging/RPMS/Fedora/Makefile b/packaging/RPMS/Fedora/Makefile index 4f5f13278d..5763cadf04 100644 --- a/packaging/RPMS/Fedora/Makefile +++ b/packaging/RPMS/Fedora/Makefile @@ -1,15 +1,27 @@ -TARBALL_DIR=../../../dist -TARBALL=$(notdir $(wildcard $(TARBALL_DIR)/rabbitmq-server-[0-9.]*.tar.gz)) -COMMON_DIR=../../common -VERSION=$(shell echo $(TARBALL) | sed -e 's:rabbitmq-server-\(.*\)\.tar\.gz:\1:g') +SOURCE_DIST_FILE ?= $(wildcard ../../../rabbitmq-server-*.tar.xz) -TOP_DIR=$(shell pwd) -#Under debian we do not want to check build dependencies, since that -#only checks build-dependencies using rpms, not debs -DEFINES=--define '_topdir $(TOP_DIR)' --define '_tmppath $(TOP_DIR)/tmp' --define '_sysconfdir /etc' --define '_localstatedir /var' +ifneq ($(filter-out clean,$(MAKECMDGOALS)),) +ifeq ($(SOURCE_DIST_FILE),) +$(error Cannot find source archive; please specify SOURCE_DIST_FILE) +endif +ifneq ($(words $(SOURCE_DIST_FILE)),1) +$(error Multile source archives found; please specify SOURCE_DIST_FILE) +endif + +VERSION ?= $(patsubst rabbitmq-server-%.tar.xz,%,$(notdir $(SOURCE_DIST_FILE))) +ifeq ($(VERSION),) +$(error Cannot determine version; please specify VERSION) +endif +endif + +TOP_DIR = $(shell pwd) +# Under debian we do not want to check build dependencies, since that +# only checks build-dependencies using rpms, not debs +DEFINES = --define '_topdir $(TOP_DIR)' --define '_tmppath $(TOP_DIR)/tmp' \ + --define '_sysconfdir /etc' --define '_localstatedir /var' ifndef RPM_OS -RPM_OS=fedora +RPM_OS = fedora endif ifeq "$(RPM_OS)" "suse" @@ -26,16 +38,21 @@ SPEC_DEFINES=--define 'group_tag Development/Libraries' START_PROG=daemon endif -rpms: clean server +unexport DEPS_DIR +unexport ERL_LIBS + +.PHONY: all prepare server clean + +all: clean server + @: prepare: mkdir -p BUILD SOURCES SPECS SRPMS RPMS tmp - cp $(TARBALL_DIR)/$(TARBALL) SOURCES + cp $(SOURCE_DIST_FILE) SOURCES cp rabbitmq-server.spec SPECS sed -i 's|%%VERSION%%|$(VERSION)|;s|%%REQUIRES%%|$(REQUIRES)|' \ SPECS/rabbitmq-server.spec - cp ${COMMON_DIR}/* SOURCES/ cp rabbitmq-server.init SOURCES/rabbitmq-server.init sed -i \ -e 's|^START_PROG=.*$$|START_PROG="$(START_PROG)"|' \ @@ -46,13 +63,16 @@ ifeq "$(RPM_OS)" "fedora" sed -i -e '/^# Default-Start:/d;/^# Default-Stop:/d' \ SOURCES/rabbitmq-server.init endif - sed -i -e 's|@SU_RABBITMQ_SH_C@|su rabbitmq -s /bin/sh -c|' \ - -e 's|@STDOUT_STDERR_REDIRECTION@||' \ - SOURCES/rabbitmq-script-wrapper + cp rabbitmq-server.logrotate SOURCES/rabbitmq-server.logrotate server: prepare rpmbuild -ba --nodeps SPECS/rabbitmq-server.spec $(DEFINES) $(OS_DEFINES) $(SPEC_DEFINES) + if test "$(PACKAGES_DIR)"; then \ + mkdir -p "$(PACKAGES_DIR)"; \ + mv SRPMS/*.rpm RPMS/noarch/*.rpm "$(PACKAGES_DIR)"; \ + fi + clean: rm -rf SOURCES SPECS RPMS SRPMS BUILD tmp diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index 75fbcec9c1..a18c3d10a4 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -5,16 +5,12 @@ Version: %%VERSION%% Release: 1%{?dist} License: MPLv1.1 and MIT and ASL 2.0 and BSD Group: %{group_tag} -Source: http://www.rabbitmq.com/releases/rabbitmq-server/v%{version}/%{name}-%{version}.tar.gz +Source: http://www.rabbitmq.com/releases/rabbitmq-server/v%{version}/%{name}-%{version}.tar.xz Source1: rabbitmq-server.init -Source2: rabbitmq-script-wrapper -Source3: rabbitmq-server.logrotate -Source4: rabbitmq-server.ocf -Source5: README -Source6: rabbitmq-server-ha.ocf +Source2: rabbitmq-server.logrotate URL: http://www.rabbitmq.com/ BuildArch: noarch -BuildRequires: erlang >= R16B-03, python-simplejson, xmlto, libxslt, gzip, sed, zip +BuildRequires: erlang >= R16B-03, python-simplejson, xmlto, libxslt, gzip, sed, zip, rsync Requires: erlang >= R16B-03, logrotate BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%{_arch}-root Summary: The RabbitMQ server @@ -29,10 +25,9 @@ scalable implementation of an AMQP broker. # We want to install into /usr/lib, even on 64-bit platforms %define _rabbit_libdir %{_exec_prefix}/lib/rabbitmq %define _rabbit_erllibdir %{_rabbit_libdir}/lib/rabbitmq_server-%{version} -%define _rabbit_wrapper %{_builddir}/`basename %{S:2}` -%define _rabbit_server_ocf %{_builddir}/`basename %{S:4}` +%define _rabbit_server_ocf scripts/rabbitmq-server.ocf %define _plugins_state_dir %{_localstatedir}/lib/rabbitmq/plugins -%define _rabbit_server_ha_ocf %{_builddir}/`basename %{S:6}` +%define _rabbit_server_ha_ocf scripts/rabbitmq-server-ha.ocf %define _maindir %{buildroot}%{_rabbit_erllibdir} @@ -42,34 +37,37 @@ scalable implementation of an AMQP broker. %setup -q %build -cp %{S:2} %{_rabbit_wrapper} -cp %{S:4} %{_rabbit_server_ocf} -cp %{S:5} %{_builddir}/rabbitmq-server-%{version}/README -cp %{S:6} %{_rabbit_server_ha_ocf} -make %{?_smp_mflags} +cp -a docs/README-for-packages %{_builddir}/rabbitmq-server-%{version}/README +make %{?_smp_mflags} dist manpages %install rm -rf %{buildroot} -make install TARGET_DIR=%{_maindir} \ - SBIN_DIR=%{buildroot}%{_rabbit_libdir}/bin \ - MAN_DIR=%{buildroot}%{_mandir} +make install install-bin install-man DESTDIR=%{buildroot} PREFIX=%{_exec_prefix} RMQ_ROOTDIR=%{_rabbit_libdir} MANDIR=%{_mandir} mkdir -p %{buildroot}%{_localstatedir}/lib/rabbitmq/mnesia mkdir -p %{buildroot}%{_localstatedir}/log/rabbitmq #Copy all necessary lib files etc. install -p -D -m 0755 %{S:1} %{buildroot}%{_initrddir}/rabbitmq-server -install -p -D -m 0755 %{_rabbit_wrapper} %{buildroot}%{_sbindir}/rabbitmqctl -install -p -D -m 0755 %{_rabbit_wrapper} %{buildroot}%{_sbindir}/rabbitmq-server -install -p -D -m 0755 %{_rabbit_wrapper} %{buildroot}%{_sbindir}/rabbitmq-plugins install -p -D -m 0755 %{_rabbit_server_ocf} %{buildroot}%{_exec_prefix}/lib/ocf/resource.d/rabbitmq/rabbitmq-server install -p -D -m 0755 %{_rabbit_server_ha_ocf} %{buildroot}%{_exec_prefix}/lib/ocf/resource.d/rabbitmq/rabbitmq-server-ha -install -p -D -m 0644 %{S:3} %{buildroot}%{_sysconfdir}/logrotate.d/rabbitmq-server +install -p -D -m 0644 %{S:2} %{buildroot}%{_sysconfdir}/logrotate.d/rabbitmq-server mkdir -p %{buildroot}%{_sysconfdir}/rabbitmq -rm %{_maindir}/LICENSE %{_maindir}/LICENSE-MPL-RabbitMQ %{_maindir}/INSTALL +mkdir -p %{buildroot}%{_sbindir} +sed -e 's|@SU_RABBITMQ_SH_C@|su rabbitmq -s /bin/sh -c|' \ + -e 's|@STDOUT_STDERR_REDIRECTION@||' \ + < scripts/rabbitmq-script-wrapper \ + > %{buildroot}%{_sbindir}/rabbitmqctl +chmod 0755 %{buildroot}%{_sbindir}/rabbitmqctl +for script in rabbitmq-server rabbitmq-plugins; do \ + cp -a %{buildroot}%{_sbindir}/rabbitmqctl \ + %{buildroot}%{_sbindir}/$script; \ +done + +rm %{_maindir}/LICENSE* %{_maindir}/INSTALL #Build the list of files echo '%defattr(-,root,root, -)' >%{_builddir}/%{name}.files diff --git a/packaging/common/README b/packaging/common/README deleted file mode 100644 index 35a1523ac3..0000000000 --- a/packaging/common/README +++ /dev/null @@ -1,20 +0,0 @@ -This is rabbitmq-server, a message broker implementing AMQP, STOMP and MQTT. - -Most of the documentation for RabbitMQ is provided on the RabbitMQ web -site. You can see documentation for the current version at: - -http://www.rabbitmq.com/documentation.html - -and for previous versions at: - -http://www.rabbitmq.com/previous.html - -Man pages are installed with this package. Of particular interest are -rabbitmqctl(1), to interact with a running RabbitMQ server, and -rabbitmq-plugins(1), to enable and disable plugins. These should be -run as the superuser. - -An example configuration file is provided in the same directory as -this README. Copy it to /etc/rabbitmq/rabbitmq.config to use it. The -RabbitMQ server must be restarted after changing the configuration -file. diff --git a/packaging/common/rabbitmq-script-wrapper b/packaging/common/rabbitmq-script-wrapper deleted file mode 100644 index ed4c276e53..0000000000 --- a/packaging/common/rabbitmq-script-wrapper +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh -## The contents of this file are subject to the Mozilla Public License -## Version 1.1 (the "License"); you may not use this file except in -## compliance with the License. You may obtain a copy of the License -## at http://www.mozilla.org/MPL/ -## -## Software distributed under the License is distributed on an "AS IS" -## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -## the License for the specific language governing rights and -## limitations under the License. -## -## The Original Code is RabbitMQ. -## -## The Initial Developer of the Original Code is GoPivotal, Inc. -## Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved. -## - -SED_OPT="-E" -if [ $(uname -s) = "Linux" ]; then - SED_OPT="-r" -fi - -for arg in "$@" ; do - # Wrap each arg in single quotes and wrap single quotes in double quotes, so that they're passed through cleanly. - arg=`printf %s "$arg" | sed $SED_OPT -e "s/'/'\"'\"'/g"` - CMDLINE="${CMDLINE} '${arg}'" -done - -cd /var/lib/rabbitmq - -SCRIPT=`basename $0` - -if [ `id -u` = `id -u rabbitmq` -a "$SCRIPT" = "rabbitmq-server" ] ; then - RABBITMQ_ENV=/usr/lib/rabbitmq/bin/rabbitmq-env - RABBITMQ_SCRIPTS_DIR=$(dirname "$RABBITMQ_ENV") - . "$RABBITMQ_ENV" - - exec /usr/lib/rabbitmq/bin/rabbitmq-server "$@" @STDOUT_STDERR_REDIRECTION@ -elif [ `id -u` = `id -u rabbitmq` -o "$SCRIPT" = "rabbitmq-plugins" ] ; then - if [ -f $PWD/.erlang.cookie ] ; then - export HOME=. - fi - exec /usr/lib/rabbitmq/bin/${SCRIPT} "$@" -elif [ `id -u` = 0 ] ; then - @SU_RABBITMQ_SH_C@ "/usr/lib/rabbitmq/bin/${SCRIPT} ${CMDLINE}" -else - /usr/lib/rabbitmq/bin/${SCRIPT} - echo - echo "Only root or rabbitmq should run ${SCRIPT}" - echo - exit 1 -fi diff --git a/packaging/common/rabbitmq-server-ha.ocf b/packaging/common/rabbitmq-server-ha.ocf deleted file mode 100755 index 5ccda7b745..0000000000 --- a/packaging/common/rabbitmq-server-ha.ocf +++ /dev/null @@ -1,1863 +0,0 @@ -#!/bin/sh -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# See usage() function below for more details ... -# -####################################################################### -# Initialization: - -: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} -. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs - -####################################################################### - -# Fill in some defaults if no values are specified - -PATH=/sbin:/usr/sbin:/bin:/usr/bin - -OCF_RESKEY_binary_default="/usr/sbin/rabbitmq-server" -OCF_RESKEY_ctl_default="/usr/sbin/rabbitmqctl" -OCF_RESKEY_debug_default=false -OCF_RESKEY_username_default="rabbitmq" -OCF_RESKEY_groupname_default="rabbitmq" -OCF_RESKEY_admin_user_default="guest" -OCF_RESKEY_admin_password_default="guest" -OCF_RESKEY_definitions_dump_file_default="/etc/rabbitmq/definitions" -OCF_RESKEY_pid_file_default="/var/run/rabbitmq/pid" -OCF_RESKEY_log_dir_default="/var/log/rabbitmq" -OCF_RESKEY_mnesia_base_default="/var/lib/rabbitmq/mnesia" -OCF_RESKEY_node_port_default=5672 -OCF_RESKEY_erlang_cookie_default=false -OCF_RESKEY_erlang_cookie_file_default="/var/lib/rabbitmq/.erlang.cookie" -OCF_RESKEY_use_fqdn_default=false -OCF_RESKEY_max_rabbitmqctl_timeouts_default=1 - -: ${HA_LOGTAG="lrmd"} -: ${HA_LOGFACILITY="daemon"} -: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} -: ${OCF_RESKEY_ctl=${OCF_RESKEY_ctl_default}} -: ${OCF_RESKEY_debug=${OCF_RESKEY_debug_default}} -: ${OCF_RESKEY_username=${OCF_RESKEY_username_default}} -: ${OCF_RESKEY_groupname=${OCF_RESKEY_groupname_default}} -: ${OCF_RESKEY_admin_user=${OCF_RESKEY_admin_user_default}} -: ${OCF_RESKEY_admin_password=${OCF_RESKEY_admin_password_default}} -: ${OCF_RESKEY_definitions_dump_file=${OCF_RESKEY_definitions_dump_file_default}} -: ${OCF_RESKEY_log_dir=${OCF_RESKEY_log_dir_default}} -: ${OCF_RESKEY_mnesia_base=${OCF_RESKEY_mnesia_base_default}} -: ${OCF_RESKEY_pid_file=${OCF_RESKEY_pid_file_default}} -: ${OCF_RESKEY_node_port=${OCF_RESKEY_node_port_default}} -: ${OCF_RESKEY_erlang_cookie=${OCF_RESKEY_erlang_cookie_default}} -: ${OCF_RESKEY_erlang_cookie_file=${OCF_RESKEY_erlang_cookie_file_default}} -: ${OCF_RESKEY_use_fqdn=${OCF_RESKEY_use_fqdn_default}} -: ${OCF_RESKEY_max_rabbitmqctl_timeouts=${OCF_RESKEY_max_rabbitmqctl_timeouts_default}} - -####################################################################### - -OCF_RESKEY_start_time_default=$((OCF_RESKEY_CRM_meta_timeout / 6000 + 2)) -: ${OCF_RESKEY_start_time=${OCF_RESKEY_start_time_default}} -OCF_RESKEY_stop_time_default=${OCF_RESKEY_start_time_default} -: ${OCF_RESKEY_stop_time=${OCF_RESKEY_start_time_default}} -OCF_RESKEY_command_timeout_default="" -: ${OCF_RESKEY_command_timeout=${OCF_RESKEY_command_timeout_default}} -TIMEOUT_ARG=$((OCF_RESKEY_CRM_meta_timeout / 6000 + 30)) -COMMAND_TIMEOUT="/usr/bin/timeout ${OCF_RESKEY_command_timeout} ${TIMEOUT_ARG}" - -####################################################################### - -usage() { - cat <<UEND - usage: $0 (start|stop|validate-all|meta-data|status|monitor) - - $0 manages an ${OCF_RESKEY_binary} process as an HA resource - - The 'start' operation starts the networking service. - The 'stop' operation stops the networking service. - The 'validate-all' operation reports whether the parameters are valid - The 'meta-data' operation reports this RA's meta-data information - The 'status' operation reports whether the networking service is running - The 'monitor' operation reports whether the networking service seems to be working - -UEND -} - -meta_data() { - cat <<END -<?xml version="1.0"?> -<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> -<resource-agent name="${OCF_RESKEY_binary}"> -<version>1.0</version> - -<longdesc lang="en"> -Resource agent for ${OCF_RESKEY_binary} -</longdesc> -<shortdesc lang="en">Resource agent for ${OCF_RESKEY_binary}</shortdesc> -<parameters> - -<parameter name="binary" unique="0" required="0"> -<longdesc lang="en"> -RabbitMQ binary -</longdesc> -<shortdesc lang="en">RabbitMQ binary</shortdesc> -<content type="string" default="${OCF_RESKEY_binary_default}" /> -</parameter> - -<parameter name="ctl" unique="0" required="0"> -<longdesc lang="en"> -rabbitctl binary -</longdesc> -<shortdesc lang="en">rabbitctl binary binary</shortdesc> -<content type="string" default="${OCF_RESKEY_ctl_default}" /> -</parameter> - -<parameter name="pid_file" unique="0" required="0"> -<longdesc lang="en"> -RabbitMQ PID file -</longdesc> -<shortdesc lang="en">RabbitMQ PID file</shortdesc> -<content type="string" default="${OCF_RESKEY_pid_file_default}" /> -</parameter> - -<parameter name="log_dir" unique="0" required="0"> -<longdesc lang="en"> -RabbitMQ log directory -</longdesc> -<shortdesc lang="en">RabbitMQ log directory</shortdesc> -<content type="string" default="${OCF_RESKEY_log_dir_default}" /> -</parameter> - -<parameter name="username" unique="0" required="0"> -<longdesc lang="en"> -RabbitMQ user name -</longdesc> -<shortdesc lang="en">RabbitMQ user name</shortdesc> -<content type="string" default="${OCF_RESKEY_username_default}" /> -</parameter> - -<parameter name="groupname" unique="0" required="0"> -<longdesc lang="en"> -RabbitMQ group name -</longdesc> -<shortdesc lang="en">RabbitMQ group name</shortdesc> -<content type="string" default="${OCF_RESKEY_groupname_default}" /> -</parameter> - -<parameter name="admin_user" unique="0" required="0"> -<longdesc lang="en"> -RabbitMQ default admin user for API -</longdesc> -<shortdesc lang="en">RabbitMQ admin user</shortdesc> -<content type="string" default="${OCF_RESKEY_admin_user_default}" /> -</parameter> - -<parameter name="admin_password" unique="0" required="0"> -<longdesc lang="en"> -RabbitMQ default admin user password for API -</longdesc> -<shortdesc lang="en">RabbitMQ admin password</shortdesc> -<content type="string" default="${OCF_RESKEY_admin_password_default}" /> -</parameter> - -<parameter name="definitions_dump_file" unique="0" required="0"> -<longdesc lang="en"> -RabbitMQ default definitions dump file -</longdesc> -<shortdesc lang="en">RabbitMQ definitions dump file</shortdesc> -<content type="string" default="${OCF_RESKEY_definitions_dump_file}" /> -</parameter> - -<parameter name="command_timeout" unique="0" required="0"> -<longdesc lang="en"> -Timeout command arguments for issued commands termination (value is auto evaluated) -</longdesc> -<shortdesc lang="en">Arguments for timeout wrapping command</shortdesc> -<content type="string" default="${OCF_RESKEY_command_timeout_default}" /> -</parameter> - -<parameter name="start_time" unique="0" required="0"> -<longdesc lang="en"> -Timeout for start rabbitmq server -</longdesc> -<shortdesc lang="en">Timeout for start rabbitmq server</shortdesc> -<content type="string" default="${OCF_RESKEY_start_time_default}" /> -</parameter> - -<parameter name="stop_time" unique="0" required="0"> -<longdesc lang="en"> -Timeout for stopping rabbitmq server -</longdesc> -<shortdesc lang="en">Timeout for stopping rabbitmq server</shortdesc> -<content type="string" default="${OCF_RESKEY_stop_time_default}" /> -</parameter> - -<parameter name="debug" unique="0" required="0"> -<longdesc lang="en"> -The debug flag for agent (${OCF_RESKEY_binary}) instance. -In the /tmp/ directory will be created rmq-* files for log -some operations and ENV values inside OCF-script. -</longdesc> -<shortdesc lang="en">AMQP server (${OCF_RESKEY_binary}) debug flag</shortdesc> -<content type="boolean" default="${OCF_RESKEY_debug_default}" /> -</parameter> - -<parameter name="mnesia_base" unique="0" required="0"> -<longdesc lang="en"> -Base directory for storing Mnesia files -</longdesc> -<shortdesc lang="en">Base directory for storing Mnesia files</shortdesc> -<content type="boolean" default="${OCF_RESKEY_mnesia_base_default}" /> -</parameter> - -<parameter name="node_port" unique="0" required="0"> -<longdesc lang="en"> -${OCF_RESKEY_binary} should listen on this port -</longdesc> -<shortdesc lang="en">${OCF_RESKEY_binary} should listen on this port</shortdesc> -<content type="boolean" default="${OCF_RESKEY_node_port_default}" /> -</parameter> - -<parameter name="erlang_cookie" unique="0" required="0"> -<longdesc lang="en"> -Erlang cookie for clustering. If specified, will be updated at the mnesia reset -</longdesc> -<shortdesc lang="en">Erlang cookie</shortdesc> -<content type="boolean" default="${OCF_RESKEY_erlang_cookie_default}" /> -</parameter> - -<parameter name="erlang_cookie_file" unique="0" required="0"> -<longdesc lang="en"> -Erlang cookie file path where the cookie will be put, if requested -</longdesc> -<shortdesc lang="en">Erlang cookie file</shortdesc> -<content type="boolean" default="${OCF_RESKEY_erlang_cookie_file_default}" /> -</parameter> - -<parameter name="use_fqdn" unique="0" required="0"> -<longdesc lang="en"> -Either to use FQDN or a shortname for the rabbitmq node -</longdesc> -<shortdesc lang="en">Use FQDN</shortdesc> -<content type="boolean" default="${OCF_RESKEY_erlang_cookie_file_default}" /> -</parameter> - -<parameter name="max_rabbitmqctl_timeouts" unique="0" required="0"> -<longdesc lang="en"> -If during monitor call rabbitmqctl times out, the timeout is ignored -unless it is Nth timeout in a row. Here N is the value of the current parameter. -If too many timeouts happen in a raw, the monitor call will return with error. -</longdesc> -<shortdesc lang="en">Fail only if that many rabbitmqctl timeouts in a row occurred</shortdesc> -<content type="string" default="${OCF_RESKEY_max_rabbitmqctl_timeouts_default}" /> -</parameter> - -</parameters> - -<actions> -<action name="start" timeout="20" /> -<action name="stop" timeout="20" /> -<action name="status" timeout="20" /> -<action name="monitor" depth="0" timeout="30" interval="5" /> -<action name="monitor" depth="0" timeout="30" interval="3" role="Master"/> -<action name="monitor" depth="30" timeout="60" interval="103" /> -<action name="promote" timeout="30" /> -<action name="demote" timeout="30" /> -<action name="notify" timeout="20" /> -<action name="validate-all" timeout="5" /> -<action name="meta-data" timeout="5" /> -</actions> -</resource-agent> -END -} - -####################################################################### -# Functions invoked by resource manager actions - -# Invokes the given command as a rabbitmq user and wrapped in the -# timeout command. -su_rabbit_cmd() { - local timeout - if [ "$1" = "-t" ]; then - timeout=="/usr/bin/timeout ${OCF_RESKEY_command_timeout} $2" - shift 2 - else - timeout=$COMMAND_TIMEOUT - fi - local cmd="${1:-status}" - local LH="${LL} su_rabbit_cmd():" - local rc=1 - local user=$OCF_RESKEY_username - local mail=/var/spool/mail/rabbitmq - local pwd=/var/lib/rabbitmq - local home=/var/lib/rabbitmq - - ocf_log debug "${LH} invoking a command: ${cmd}" - su $user -s /bin/sh -c "USER=${user} MAIL=${mail} PWD=${pwd} HOME=${home} LOGNAME=${user} \ - ${timeout} ${cmd}" - rc=$? - ocf_log info "${LH} the invoked command exited ${rc}: ${cmd}" - return $rc -} - -now() { - date -u +%s -} - -master_score() { - local score=$1 - if [ -z $score ] ; then - score=0 - fi - ocf_run crm_master -l reboot -v $score || return $OCF_ERR_GENERIC - return $OCF_SUCCESS -} - -# Return either FQDN or shortname, depends on the OCF_RESKEY_use_fqdn. -get_hostname() { - if [ "${OCF_RESKEY_use_fqdn}" = 'false' ] ; then - echo "$(hostname -s)" - else - echo "$(hostname -f)" - fi -} - -# Strip the FQDN to the shortname, if OCF_RESKEY_use_fqdn was set -process_fqdn() { - if [ "${OCF_RESKEY_use_fqdn}" = 'false' ] ; then - echo "$1" | awk -F. '{print $1}' - else - echo "$1" - fi -} - -# Return OCF_SUCCESS, if current host is in the list of given hosts. -# Otherwise, return 10 -my_host() { - local hostlist="$1" - local hostname - local hn - local rc=10 - local LH="${LL} my_host():" - - hostname=$(get_hostname) - ocf_log info "${LH} hostlist is: $hostlist" - for host in $hostlist ; do - hn=$(process_fqdn "${host}") - ocf_log debug "${LH} comparing '$hostname' with '$hn'" - if [ "${hostname}" = "${hn}" ] ; then - rc=$OCF_SUCCESS - break - fi - done - - return $rc -} - -srv_uptime() { - local stime - stime=$( crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit-start-time' --query 2>/dev/null | awk '{print $3}' | awk -F "=" '{print $2}' | sed -e '/(null)/d' ) - - if [ -z "${stime}" -o "${stime}" = "(null)" ] ; then - echo 0 - else - echo $(( $(now) - ${stime} )) - fi - - return $OCF_SUCCESS -} - -# Return either rabbit node name as FQDN or shortname, depends on the OCF_RESKEY_use_fqdn. -rabbit_node_name() { - echo "rabbit@$(process_fqdn $1)" -} - -rmq_setup_env() { - local H - local dir - H="$(get_hostname)" - export RABBITMQ_NODENAME=$(rabbit_node_name $H) - export RABBITMQ_NODE_PORT=$OCF_RESKEY_node_port - export RABBITMQ_PID_FILE=$OCF_RESKEY_pid_file - MNESIA_FILES="${OCF_RESKEY_mnesia_base}/$(rabbit_node_name $H)" - RMQ_START_TIME="${MNESIA_FILES}/ocf_server_start_time.txt" - MASTER_FLAG_FILE="${MNESIA_FILES}/ocf_master_for_${OCF_RESOURCE_INSTANCE}" - THIS_PCMK_NODE=`crm_node -n` - TOTALVMEM=`free -mt | awk '/Total:/ {print $2}'` - # check and make PID file dir - local PID_DIR=$( dirname $OCF_RESKEY_pid_file ) - if [ ! -d ${PID_DIR} ] ; then - mkdir -p ${PID_DIR} - chown -R ${OCF_RESKEY_username}:${OCF_RESKEY_groupname} ${PID_DIR} - chmod 755 ${PID_DIR} - fi - - # Regardless of whether we just created the directory or it - # already existed, check whether it is writable by the configured - # user - for dir in ${PID_DIR} "${OCF_RESKEY_mnesia_base}" "${OCF_RESKEY_log_dir}"; do - if test -e ${dir}; then - local files=$(su -s /bin/sh - $OCF_RESKEY_username -c "find ${dir} ! -writable") - if [ "${files}" ]; then - ocf_log warn "Directory ${dir} is not writable by ${OCF_RESKEY_username}, chowning." - chown -R ${OCF_RESKEY_username}:${OCF_RESKEY_groupname} "${dir}" - fi - fi - done - - export LL="${OCF_RESOURCE_INSTANCE}:" - update_cookie -} - -# Return a RabbitMQ node to its virgin state. -# For reset and force_reset to succeed the RabbitMQ application must have been stopped. -# If the app cannot be stopped, beam will be killed and mnesia files will be removed. -reset_mnesia() { - local LH="${LL} reset_mnesia():" - local make_amnesia=false - local rc=$OCF_ERR_GENERIC - - # check status of a beam process - get_status - rc=$? - if [ $rc -eq 0 ] ; then - # beam is running - # check status of rabbit app and stop it, if it is running - get_status rabbit - rc=$? - if [ $rc -eq 0 ] ; then - # rabbit app is running, have to stop it - ocf_log info "${LH} Stopping RMQ-app prior to reset the mnesia." - stop_rmq_server_app - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log warn "${LH} RMQ-app can't be stopped." - make_amnesia=true - fi - fi - - if ! $make_amnesia ; then - # rabbit app is not running, reset mnesia - ocf_log info "${LH} Execute reset with timeout: ${TIMEOUT_ARG}" - su_rabbit_cmd "${OCF_RESKEY_ctl} reset" - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log info "${LH} Execute force_reset with timeout: ${TIMEOUT_ARG}" - su_rabbit_cmd "${OCF_RESKEY_ctl} force_reset" - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log warn "${LH} Mnesia couldn't cleaned, even by force-reset command." - make_amnesia=true - fi - fi - fi - else - # there is no beam running - make_amnesia=true - ocf_log warn "${LH} There is no Beam process running." - fi - - # remove mnesia files, if required - if $make_amnesia ; then - kill_rmq_and_remove_pid - ocf_run rm -rf "${MNESIA_FILES}/*" - ocf_log warn "${LH} Beam have been killed. Mnesia files appear corrupted and have been removed." - fi - # always return OCF SUCCESS - return $OCF_SUCCESS -} - - -block_client_access() -{ - # do not add temporary RMQ blocking rule, if it is already exist - # otherwise, try to add a blocking rule with max of 5 retries - local tries=5 - until $(iptables -nvL | grep -q 'temporary RMQ block') || [ $tries -eq 0 ]; do - tries=$((tries-1)) - iptables -I INPUT -p tcp -m tcp --dport ${OCF_RESKEY_node_port} -m state --state NEW,RELATED,ESTABLISHED \ - -m comment --comment 'temporary RMQ block' -j REJECT --reject-with tcp-reset - sleep 1 - done - if [ $tries -eq 0 ]; then - return $OCF_ERR_GENERIC - else - return $OCF_SUCCESS - fi -} - -unblock_client_access() -{ - # remove all temporary RMQ blocking rules, if there are more than one exist - for i in $(iptables -nvL --line-numbers | awk '/temporary RMQ block/ {print $1}'); do - iptables -D INPUT -p tcp -m tcp --dport ${OCF_RESKEY_node_port} -m state --state NEW,RELATED,ESTABLISHED \ - -m comment --comment 'temporary RMQ block' -j REJECT --reject-with tcp-reset - done -} - -get_nodes__base(){ - local infotype='' - local rc=$OCF_ERR_GENERIC - local c_status - - if [ "$1" = 'nodes' ] - then - infotype='db_nodes' - elif [ "$1" = 'running' ] - then - infotype='running_db_nodes' - fi - c_status=`${OCF_RESKEY_ctl} eval "mnesia:system_info(${infotype})." 2>/dev/null` - rc=$? - if [ $rc -ne 0 ] ; then - echo '' - return $OCF_ERR_GENERIC - fi - # translate line like '{running_nodes,['rabbit@node-1','rabbit@node-2','rabbit@node-3']},' to node_list - echo $(echo "${c_status}" | awk -F, '{ for (i=1;i<=NF;i++) { if ($i ~ /@/) { gsub(/[\[\]}{]/,"",$i); print $i; } }}' | tr -d "\'") - return $OCF_SUCCESS -} - -get_nodes() { - echo $(get_nodes__base nodes) - return $? -} - -get_running_nodes() { - echo $(get_nodes__base running) - return $? -} - -# Get all known cluster nodes including offline ones -get_all_pacemaker_nodes() -{ - echo `crm_node -l | awk '{print $2}' | grep -v "^$" | sed -e '/(null)/d'` - return $? -} - -# Get alive cluster nodes in visible partition, but the specified one -get_alive_pacemaker_nodes_but() -{ - if [ -z "$1" ]; then - echo `crm_node -l -p | sed -e '/(null)/d'` - else - echo `crm_node -l -p | sed -e "s/${1}//g" | sed -e '/(null)/d'` - fi - return $? -} - -check_need_join_to() { - local join_to - local node - local running_nodes - local rc=$OCF_ERR_GENERIC - - rc=0 - join_to=$(rabbit_node_name $1) - running_nodes=$(get_running_nodes) - for node in $running_nodes ; do - if [ "${join_to}" = "${node}" ] ; then - rc=1 - break - fi - done - - return $rc -} - -# Update erlang cookie, if it has been specified -update_cookie() { - if [ "${OCF_RESKEY_erlang_cookie}" != 'false' ] ; then - echo "${OCF_RESKEY_erlang_cookie}" > "${OCF_RESKEY_erlang_cookie_file}" && \ - chown ${OCF_RESKEY_username}:${OCF_RESKEY_groupname} "${OCF_RESKEY_erlang_cookie_file}" && \ - chmod 600 "${OCF_RESKEY_erlang_cookie_file}" - fi - return $OCF_SUCCESS -} - -kill_rmq_and_remove_pid() { - local pid - local LH="${LL} kill_rmq_and_remove_pid():" - - if [ -f "${OCF_RESKEY_pid_file}" ] ; then - pid=$(cat $OCF_RESKEY_pid_file) - if [ -z "${pid}" ] ; then - pkill -f -TERM "beam.*${RABBITMQ_NODENAME}" - local rc=$? - if [ $rc -eq 0 ] ; then - ocf_log warn "${LH} pidfile is empty! Killed beam processes matched the ${RABBITMQ_NODENAME}" - else - ocf_log err "${LH} pidfile is empty and cannot find any beam processes matching the ${RABBITMQ_NODENAME}!" - fi - fi - if [ -d "/proc/${pid}/" ] ; then - ocf_run kill -TERM $pid - ocf_log warn "${LH} RMQ-runtime (beam) PID=${pid} stopped by 'kill -TERM', sorry..." - fi - ocf_run rm -f $OCF_RESKEY_pid_file - fi -} - -trim_var(){ - local string="$*" - echo ${string%% } -} - -action_validate() { - # todo(sv): validate some incoming parameters - OCF_RESKEY_CRM_meta_notify_post=$(trim_var $OCF_RESKEY_CRM_meta_notify_post) - OCF_RESKEY_CRM_meta_notify_pre=$(trim_var $OCF_RESKEY_CRM_meta_notify_pre) - OCF_RESKEY_CRM_meta_notify_start=$(trim_var $OCF_RESKEY_CRM_meta_notify_start) - OCF_RESKEY_CRM_meta_notify_stop=$(trim_var $OCF_RESKEY_CRM_meta_notify_stop) - OCF_RESKEY_CRM_meta_notify_start_resource=$(trim_var $OCF_RESKEY_CRM_meta_notify_start_resource) - OCF_RESKEY_CRM_meta_notify_stop_resource=$(trim_var $OCF_RESKEY_CRM_meta_notify_stop_resource) - OCF_RESKEY_CRM_meta_notify_active_resource=$(trim_var $OCF_RESKEY_CRM_meta_notify_active_resource) - OCF_RESKEY_CRM_meta_notify_inactive_resource=$(trim_var $OCF_RESKEY_CRM_meta_notify_inactive_resource) - OCF_RESKEY_CRM_meta_notify_start_uname=$(trim_var $OCF_RESKEY_CRM_meta_notify_start_uname) - OCF_RESKEY_CRM_meta_notify_stop_uname=$(trim_var $OCF_RESKEY_CRM_meta_notify_stop_uname) - OCF_RESKEY_CRM_meta_notify_active_uname=$(trim_var $OCF_RESKEY_CRM_meta_notify_active_uname) - OCF_RESKEY_CRM_meta_notify_master_resource=$(trim_var $OCF_RESKEY_CRM_meta_notify_master_resource) - OCF_RESKEY_CRM_meta_notify_master_uname=$(trim_var $OCF_RESKEY_CRM_meta_notify_master_uname) - OCF_RESKEY_CRM_meta_notify_demote_resource=$(trim_var $OCF_RESKEY_CRM_meta_notify_demote_resource) - OCF_RESKEY_CRM_meta_notify_demote_uname=$(trim_var $OCF_RESKEY_CRM_meta_notify_demote_uname) - OCF_RESKEY_CRM_meta_notify_slave_resource=$(trim_var $OCF_RESKEY_CRM_meta_notify_slave_resource) - OCF_RESKEY_CRM_meta_notify_slave_uname=$(trim_var $OCF_RESKEY_CRM_meta_notify_slave_uname) - OCF_RESKEY_CRM_meta_notify_promote_resource=$(trim_var $OCF_RESKEY_CRM_meta_notify_promote_resource) - OCF_RESKEY_CRM_meta_notify_promote_uname=$(trim_var $OCF_RESKEY_CRM_meta_notify_promote_uname) - return $OCF_SUCCESS -} - -join_to_cluster() { - local node="$1" - local rmq_node - local rc=$OCF_ERR_GENERIC - local LH="${LL} join_to_cluster():" - - ocf_log info "${LH} start." - ocf_log info "${LH} Joining to cluster by node '${rmq_node}'." - - rmq_node=$(rabbit_node_name $node) - get_status rabbit - rc=$? - if [ $rc -eq $OCF_SUCCESS ] ; then - ocf_log info "${LH} rabbitmq app will be stopped." - stop_rmq_server_app - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log err "${LH} Can't stop rabbitmq app by stop_app command. Stopping." - action_stop - return $OCF_ERR_GENERIC - fi - fi - ocf_log info "${LH} Execute join_cluster with timeout: ${TIMEOUT_ARG}" - su_rabbit_cmd "${OCF_RESKEY_ctl} join_cluster $rmq_node" - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log err "${LH} Can't join to cluster by node '${rmq_node}'. Stopping." - action_stop - return $OCF_ERR_GENERIC - fi - sleep 2 - try_to_start_rmq_app - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log err "${LH} Can't start RMQ app after join to cluster. Stopping." - action_stop - return $OCF_ERR_GENERIC - else - ocf_log info "${LH} Rabbit app started successfully. Updating start time attribute with $(now)" - ocf_run crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit-start-time' --update $(now) - ocf_log info "${LH} Joined to cluster succesfully." - fi - - ocf_log info "${LH} end." - return $rc -} - -unjoin_nodes_from_cluster() { - # node names of the nodes where the pcs resource is being stopped - local nodelist="$1" - local hostname - local nodename - local rc=$OCF_ERR_GENERIC - local rnode - # nodes in rabbit cluster db - local nodes_in_cluster - local LH="${LL} unjoin_nodes_from_cluster():" - - nodes_in_cluster=$(get_nodes) - rc=$? - if [ $rc -ne 0 ] ; then - # no nodes in node list, nothing to do - return $OCF_SUCCESS - fi - - # unjoin all cluster nodes which are being stopped (i.e. recieved post-stop notify), except *this* node - # before to unjoin the nodes, make sure they were disconnected from *this* node - for hostname in $nodelist ; do - nodename=$(rabbit_node_name $hostname) - if [ "${nodename}" = "${RABBITMQ_NODENAME}" ] ; then - continue - fi - for rnode in $nodes_in_cluster ; do - if [ "${nodename}" = "${rnode}" ] ; then - # disconnect node being unjoined from this node - ocf_run ${OCF_RESKEY_ctl} eval "disconnect_node(list_to_atom(\"${nodename}\"))." 2>&1 - rc=$? - if [ $rc -eq $OCF_SUCCESS ] ; then - ocf_log info "${LH} node '${nodename}' disconnected succesfully." - else - ocf_log info "${LH} disconnecting node '${nodename}' failed." - fi - - # unjoin node - # when the rabbit node went down, its status - # remains 'running' for a while, so few retries are required - local tries=0 - until [ $tries -eq 5 ]; do - tries=$((tries+1)) - if get_running_nodes | grep -q $(rabbit_node_name $nodename) - then - ocf_log info "${LH} the ${nodename} is alive and cannot be kicked from the cluster yet" - fi - sleep 10 - done - ocf_log info "${LH} Execute forget_cluster_node with timeout: ${TIMEOUT_ARG}" - su_rabbit_cmd "${OCF_RESKEY_ctl} forget_cluster_node ${nodename}" - rc=$? - if [ $rc -eq 0 ] ; then - ocf_log info "${LH} node '${nodename}' unjoined succesfully." - else - ocf_log warn "${LH} unjoining node '${nodename}' failed." - fi - fi - done - done - return $OCF_SUCCESS -} - -# Stop RMQ server process. Returns OCS_SUCCESS -stop_server_process() { - local pid - local rc=$OCF_ERR_GENERIC - local LH="${LL} stop_server_process():" - - pid=$(cat ${OCF_RESKEY_pid_file}) - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log err "${LH} RMQ-server process PIDFILE was not found!" - su_rabbit_cmd "${OCF_RESKEY_ctl} stop 2>&1 >> \"${OCF_RESKEY_log_dir}/shutdown_log\"" - rc=$? - if [ $rc -eq 0 ] ; then - ocf_log info "${LH} RMQ-server process stopped succesfully, although there was no PIDFILE found." - return $OCF_SUCCESS - else - ocf_log err "${LH} Cannot stop RMQ-server process, and cannot kill it by unknown PID! Try to stop it manually!" - return $OCF_ERR_GENERIC - fi - fi - - if [ -z "${pid}" ] ; then - kill_rmq_and_remove_pid - return $OCF_ERR_GENERIC - fi - - ocf_log info "${LH} Execute stop with timeout: ${TIMEOUT_ARG}" - su_rabbit_cmd "${OCF_RESKEY_ctl} stop ${OCF_RESKEY_pid_file} 2>&1 >> \"${OCF_RESKEY_log_dir}/shutdown_log\"" - rc=$? - if [ $rc -eq 0 ] ; then - ocf_log info "${LH} RMQ-server process (PID=${pid}) stopped succesfully." - fi - - kill_rmq_and_remove_pid - return $OCF_SUCCESS -} - -# Stop RMQ-app. Return OCF_SUCCESS, if the app was stopped, -# otherwise return OCF_ERR_GENERIC -stop_rmq_server_app() { - local rc=$OCF_ERR_GENERIC - - # if the beam process isn't running, then rabbit app is stopped as well - get_status - rc=$? - if [ $rc -ne 0 ] ; then - return $OCF_SUCCESS - fi - - # stop the app - ocf_log info "${LH} Execute stop_app with timeout: ${TIMEOUT_ARG}" - su_rabbit_cmd "${OCF_RESKEY_ctl} stop_app 2>&1 >> \"${OCF_RESKEY_log_dir}/shutdown_log\"" - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log err "${LH} RMQ-server app cannot be stopped." - return $OCF_ERR_GENERIC - fi - - get_status rabbit - rc=$? - if [ $rc -ne $OCF_SUCCESS ] ; then - ocf_log info "${LH} RMQ-server app stopped succesfully." - rc=$OCF_SUCCESS - else - ocf_log err "${LH} RMQ-server app cannot be stopped." - rc=$OCF_ERR_GENERIC - fi - - return $rc -} - -start_beam_process() { - local command - local rc=$OCF_ERR_GENERIC - local ts_end - local pf_end - local pid - local LH="${LL} start_beam_process():" - - # remove old PID-file if it exists - if [ -f "${OCF_RESKEY_pid_file}" ] ; then - ocf_log warn "${LH} found old PID-file '${OCF_RESKEY_pid_file}'." - pid=$(cat ${OCF_RESKEY_pid_file}) - if [ "${pid}" -a -d "/proc/${pid}" ] ; then - ocf_run cat /proc/${pid}/cmdline | grep -c 'bin/beam' 2>&1 > /dev/null - rc=$? - if [ $rc -eq $OCF_SUCCESS ] ; then - ocf_log warn "${LH} found beam process with PID=${pid}, killing...'." - ocf_run kill -TERM $pid - else - ocf_log err "${LH} found unknown process with PID=${pid} from '${OCF_RESKEY_pid_file}'." - return $OCF_ERR_GENERIC - fi - fi - ocf_run rm -f $OCF_RESKEY_pid_file - fi - - [ -f /etc/default/rabbitmq-server ] && . /etc/default/rabbitmq-server - - # run beam process - command="${OCF_RESKEY_binary} >> \"${OCF_RESKEY_log_dir}/startup_log\" 2>/dev/null" - RABBITMQ_NODE_ONLY=1 su rabbitmq -s /bin/sh -c "${command}"& - ts_end=$(( $(now) + ${OCF_RESKEY_start_time} )) - rc=$OCF_ERR_GENERIC - while [ $(now) -lt ${ts_end} ]; do - # waiting for normal start of beam - pid=0 - pf_end=$(( $(now) + 3 )) - while [ $(now) -lt ${pf_end} ]; do - # waiting for OCF_RESKEY_pid_file of beam process - if [ -f "${OCF_RESKEY_pid_file}" ] ; then - pid=$(cat ${OCF_RESKEY_pid_file}) - break - fi - sleep 1 - done - if [ "${pid}" != "0" -a -d "/proc/${pid}" ] ; then - rc=$OCF_SUCCESS - break - fi - sleep 2 - done - if [ $rc -ne $OCF_SUCCESS ]; then - if [ "${pid}" = "0" ] ; then - ocf_log warn "${LH} PID-file '${OCF_RESKEY_pid_file}' not found" - fi - ocf_log err "${LH} RMQ-runtime (beam) didn't start succesfully (rc=${rc})." - fi - - return $rc -} - -check_plugins() { - # Check if it's safe to load plugins and if we need to do so. Logic is: - # if (EnabledPlugins > 0) and (ActivePlugins == 0) ; then it's safe to load - # If we have at least one active plugin, then it's not safe to re-load them - # because plugins:setup() would remove existing dependency plugins in plugins_expand_dir. - ${OCF_RESKEY_ctl} eval '{ok, EnabledFile} = application:get_env(rabbit, enabled_plugins_file), EnabledPlugins = rabbit_plugins:read_enabled(EnabledFile), ActivePlugins = rabbit_plugins:active(), if length(EnabledPlugins)>0 -> if length(ActivePlugins)==0 -> erlang:error("need_to_load_plugins"); true -> false end; true -> false end.' - return $? -} - -load_plugins() { - check_plugins - local rc=$? - if [ $rc -eq 0 ] ; then - return 0 - else - ${OCF_RESKEY_ctl} eval 'ToBeLoaded = rabbit_plugins:setup(), ok = app_utils:load_applications(ToBeLoaded), StartupApps = app_utils:app_dependency_order(ToBeLoaded,false), app_utils:start_applications(StartupApps).' - return $? - fi -} - -list_active_plugins() { - local list - list=`${OCF_RESKEY_ctl} eval 'rabbit_plugins:active().'` - echo "${list}" -} - -try_to_start_rmq_app() { - local startup_log="${1:-${OCF_RESKEY_log_dir}/startup_log}" - local rc=$OCF_ERR_GENERIC - local LH="${LL} try_to_start_rmq_app():" - - get_status - rc=$? - if [ $rc -ne $OCF_SUCCESS ] ; then - ocf_log info "${LH} RMQ-runtime (beam) not started, starting..." - start_beam_process - rc=$? - if [ $rc -ne $OCF_SUCCESS ]; then - ocf_log err "${LH} Failed to start beam - returning from the function" - return $OCF_ERR_GENERIC - fi - fi - - - if [ -z "${startup_log}" ] ; then - startup_log="${OCF_RESKEY_log_dir}/startup_log" - fi - - ocf_log info "${LH} begin." - ocf_log info "${LH} Execute start_app with timeout: ${TIMEOUT_ARG}" - su_rabbit_cmd "${OCF_RESKEY_ctl} start_app >>${startup_log} 2>&1" - rc=$? - if [ $rc -eq 0 ] ; then - ocf_log info "${LH} start_app was successful." - ocf_log info "${LH} waiting for start to finish with timeout: ${TIMEOUT_ARG}" - su_rabbit_cmd "${OCF_RESKEY_ctl} wait ${OCF_RESKEY_pid_file}" - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log err "${LH} RMQ-server app failed to wait for start." - return $OCF_ERR_GENERIC - fi - rc=$OCF_SUCCESS - # Loading enabled modules - ocf_log info "${LH} start plugins." - load_plugins - local mrc=$? - if [ $mrc -eq 0 ] ; then - local mlist - mlist=`list_active_plugins` - ocf_log info "${LH} Starting plugins: ${mlist}" - else - ocf_log info "${LH} Starting plugins: failed." - fi - else - ocf_log info "${LH} start_app failed." - rc=$OCF_ERR_GENERIC - fi - return $rc -} - -start_rmq_server_app() { - local rc=$OCF_ERR_GENERIC - local startup_log="${OCF_RESKEY_log_dir}/startup_log" - local startup_output - local LH="${LL} start_rmq_server_app():" - local a - - #We are performing initial start check. - #We are not ready to provide service. - #Clients should not have access. - - - ocf_log info "${LH} begin." - # Safe-unblock the rules, if there are any - unblock_client_access - # Apply the blocking rule - block_client_access - rc=$? - if [ $rc -eq $OCF_SUCCESS ]; then - ocf_log info "${LH} blocked access to RMQ port" - else - ocf_log err "${LH} cannot block access to RMQ port!" - return $OCF_ERR_GENERIC - fi - get_status - rc=$? - if [ $rc -ne $OCF_SUCCESS ] ; then - ocf_log info "${LH} RMQ-runtime (beam) not started, starting..." - start_beam_process - rc=$? - if [ $rc -ne $OCF_SUCCESS ]; then - unblock_client_access - ocf_log info "${LH} unblocked access to RMQ port" - return $OCF_ERR_GENERIC - fi - fi - - ocf_log info "${LH} RMQ-server app not started, starting..." - try_to_start_rmq_app "$startup_log" - rc=$? - if [ $rc -eq $OCF_SUCCESS ] ; then - # rabbitmq-server started successfuly as master of cluster - master_score 1 # minimal positive master-score for this node. - stop_rmq_server_app - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log err "${LH} RMQ-server app can't be stopped. Beam will be killed." - kill_rmq_and_remove_pid - unblock_client_access - ocf_log info "${LH} unblocked access to RMQ port" - return $OCF_ERR_GENERIC - fi - else - # error at start RMQ-server - ocf_log warn "${LH} RMQ-server app can't start without Mnesia cleaning." - for a in $(seq 1 10) ; do - rc=$OCF_ERR_GENERIC - reset_mnesia || break - try_to_start_rmq_app "$startup_log" - rc=$? - if [ $rc -eq $OCF_SUCCESS ]; then - stop_rmq_server_app - rc=$? - if [ $rc -eq $OCF_SUCCESS ]; then - ocf_log info "${LH} RMQ-server app Mnesia cleaned successfully." - rc=$OCF_SUCCESS - master_score 1 - break - else - ocf_log err "${LH} RMQ-server app can't be stopped during Mnesia cleaning. Beam will be killed." - kill_rmq_and_remove_pid - unblock_client_access - ocf_log info "${LH} unblocked access to RMQ port" - return $OCF_ERR_GENERIC - fi - fi - done - fi - if [ $rc -eq $OCF_ERR_GENERIC ] ; then - ocf_log err "${LH} RMQ-server can't be started while many tries. Beam will be killed." - kill_rmq_and_remove_pid - fi - ocf_log info "${LH} end." - unblock_client_access - ocf_log info "${LH} unblocked access to RMQ port" - return $rc -} - -# check status of rabbit beam process or a rabbit app, if rabbit arg specified -# by default, test if the kernel app is running, otherwise consider it is "not running" -get_status() { - local what="${1:-kernel}" - local rc=$OCF_ERR_GENERIC - local body - - body=$( ${COMMAND_TIMEOUT} ${OCF_RESKEY_ctl} eval 'rabbit_misc:which_applications().' 2>&1 ) - rc=$? - - if [ $rc -ne 0 ] ; then - ocf_log info "get_status() failed with code ${rc}. Command output: ${body}" - return $OCF_NOT_RUNNING - fi - - if [ "${what}" ] ; then - rc=$OCF_NOT_RUNNING - echo "$body" | grep "\{${what}," 2>&1 > /dev/null && rc=$OCF_SUCCESS - - if [ $rc -ne $OCF_SUCCESS ] ; then - ocf_log info "get_status(): app ${what} was not found in command output: ${body}" - fi - fi - - return $rc -} - -action_status() { - local rc=$OCF_ERR_GENERIC - - get_status - rc=$? - return $rc -} - -# return 0, if given node has a master attribute in CIB, -# otherwise, return 1 -is_master() { - local result - result=`crm_attribute -N "${1}" -l reboot --name 'rabbit-master' --query 2>/dev/null |\ - awk '{print $3}' | awk -F "=" '{print $2}' | sed -e '/(null)/d'` - if [ "${result}" != 'true' ] ; then - return 1 - fi - return 0 -} - -# Verify if su_rabbit_cmd exited by timeout by checking its return code. -# If it did not, return 0. If it did AND it is -# $OCF_RESKEY_max_rabbitmqctl_timeouts'th timeout in a row, -# return 2 to signal get_monitor that it should -# exit with error. Otherwise return 1 to signal that there was a timeout, -# but it should be ignored. Timeouts for different operations are tracked -# separately. The second argument is used to distingush them. -check_timeouts() { - local op_rc=$1 - local crm_attr_name=$2 - local op_name=$3 - - if [ $op_rc -ne 124 -a $op_rc -ne 137 ]; then - ocf_run crm_attribute -N $THIS_PCMK_NODE -l reboot --name $crm_attr_name --update 0 - return 0 - fi - - local count - count=`crm_attribute -N $THIS_PCMK_NODE -l reboot --name $crm_attr_name --query 2>/dev/null | awk '{print $3}' | awk -F "=" '{print $2}' | sed -e '/(null)/d'` - if [ $? -ne 0 ]; then - # the crm_attribute exited with error. In that case most probably it printed garbage - # instead of the number we need. So defensively assume that it is zero. - - count=0 - fi - - count=$((count+1)) - # There is a slight chance that this piece of code will be executed twice simultaneously. - # As a result, $crm_attr_name's value will be one less than it should be. But we don't need - # precise calculation here. - ocf_run crm_attribute -N $THIS_PCMK_NODE -l reboot --name $crm_attr_name --update $count - - if [ $count -lt $OCF_RESKEY_max_rabbitmqctl_timeouts ]; then - ocf_log warn "${LH} 'rabbitmqctl $op_name' timed out $count of max. $OCF_RESKEY_max_rabbitmqctl_timeouts time(s) in a row. Doing nothing for now." - return 1 - else - ocf_log err "${LH} 'rabbitmqctl $op_name' timed out $count of max. $OCF_RESKEY_max_rabbitmqctl_timeouts time(s) in a row and is not responding. The resource is failed." - return 2 - fi -} - -wait_sync() { - wait_time=$1 - - queues="${COMMAND_TIMEOUT} ${OCF_RESKEY_ctl} list_queues name state" - su_rabbit_cmd -t "${wait_time}s" "sh -c \"while $queues | grep -q 'syncing,'; \ - do sleep 1; done\"" - return $? -} - -get_monitor() { - local rc=$OCF_ERR_GENERIC - local LH="${LL} get_monitor():" - local status_master - local rabbit_running - local name - local node - local nodelist - local prev_rc - local max - local our_uptime - local node_uptime - local node_start_time - - ocf_log info "${LH} CHECK LEVEL IS: ${OCF_CHECK_LEVEL}" - get_status - rc=$? - if [ $rc -eq $OCF_NOT_RUNNING ] ; then - ocf_log info "${LH} get_status() returns ${rc}." - ocf_log info "${LH} ensuring this slave does not get promoted." - master_score 0 - return $OCF_NOT_RUNNING - elif [ $rc -eq $OCF_SUCCESS ] ; then - ocf_log info "${LH} get_status() returns ${rc}." - ocf_log info "${LH} also checking if we are master." - get_status rabbit - rabbit_running=$? - is_master $THIS_PCMK_NODE - status_master=$? - ocf_log info "${LH} master attribute is ${status_master}" - if [ $status_master -eq 0 -a $rabbit_running -eq $OCF_SUCCESS ] - then - rc=$OCF_RUNNING_MASTER - fi - fi - get_status rabbit - rabbit_running=$? - ocf_log info "${LH} checking if rabbit app is running" - - if [ $rabbit_running -eq $OCF_SUCCESS ] - then - ocf_log info "${LH} rabbit app is running. checking if we are the part of healthy cluster" - prev_rc=$rc - nodelist=$(get_alive_pacemaker_nodes_but) - for node in $nodelist - do - ocf_log info "${LH} rabbit app is running. looking for master on $node" - is_master $node - status_master=$? - ocf_log info "${LH} fetched master attribute for $node. attr value is ${status_master}" - if [ $status_master -eq 0 ] ; then - rc=$OCF_ERR_GENERIC - ocf_log info "${LH} rabbit app is running. master is $node" - if get_running_nodes | grep -q $(rabbit_node_name $node) - then - ocf_log info "${LH} rabbit app is running and is member of healthy cluster" - rc=$prev_rc - break - fi - fi - done - [ $rc -eq $OCF_ERR_GENERIC ] && ocf_log err "${LH} rabbit node is running out of the cluster" - else - if [ "$OCF_CHECK_LEVEL" -gt 20 ]; then - ocf_log info "${LH} rabbit app is not running. checking if there is a master" - prev_rc=$rc - is_master $THIS_PCMK_NODE - i_am_master=$? - if [ $i_am_master -eq 0 ]; then - ocf_log err "${LH} we are the master and rabbit app is not running. this is a failure" - exit $OCF_FAILED_MASTER - fi - nodelist=$(get_alive_pacemaker_nodes_but) - for node in $nodelist - do - is_master $node - status_master=$? - ocf_log info "${LH} fetched master attribute for $node. attr value is ${status_master}" - if [ $status_master -eq 0 ] ; then - rc=$OCF_ERR_GENERIC - ocf_log info "${LH} rabbit app is not running. master is $node. exiting to be restarted by pacemaker" - fi - done - fi - fi - - if [ $rc -eq $OCF_ERR_GENERIC ]; then - ocf_log err "${LH} get_status() returns generic error ${rc}" - ocf_log info "${LH} ensuring this slave does not get promoted." - master_score 0 - return $OCF_ERR_GENERIC - else - ocf_log info "${LH} preparing to update master score for node" - our_uptime=$(srv_uptime) - nodelist=$(get_alive_pacemaker_nodes_but $THIS_PCMK_NODE) - max=1 - for node in $nodelist - do - node_start_time=`crm_attribute -N $node -l reboot --name 'rabbit-start-time' --query 2>/dev/null | awk '{print $3}' | awk -F "=" '{print $2}' | sed -e '/(null)/d'` - if [ -z "${node_start_time}" -o "${node_start_time}" = "(null)" ] ; then - node_uptime=0 - else - node_uptime=$(( $(now) - ${node_start_time} )) - fi - ocf_log info "${LH} comparing our uptime (${our_uptime}) with $node (${node_uptime})" - if [ ${our_uptime} -lt ${node_uptime} ] - then - max=1 - break - else - # When uptime is equal, accept the existing master - if any - as the oldest node - is_master $node - status_master=$? - if [ $status_master -eq 0 ] ; then - max=1 - ocf_log info "${LH} Found the oldest master node $node with uptime (${node_uptime})" - break - else - max=0 - fi - fi - done - - - if [ $max -eq 0 ] - then - ocf_log info "${LH} we are the oldest node" - master_score 1000 - fi - fi - - # Skip all other checks if rabbit app is not running - if [ $rabbit_running -ne $OCF_SUCCESS ]; then - ocf_log info "${LH} RabbitMQ is not running, get_monitor function ready to return ${rc}" - return $rc - fi - - # Check if the rabbitmqctl control plane is alive. - local rc_alive - local timeout_alive - su_rabbit_cmd "${OCF_RESKEY_ctl} list_channels 2>&1 > /dev/null" - rc_alive=$? - check_timeouts $rc_alive "rabbit_list_channels_timeouts" "list_channels" - timeout_alive=$? - - if [ $timeout_alive -eq 2 ]; then - return $OCF_ERR_GENERIC - elif [ $timeout_alive -eq 0 ]; then - if [ $rc_alive -ne 0 ]; then - ocf_log err "${LH} rabbitmqctl list_channels exited with errors." - rc=$OCF_ERR_GENERIC - fi - fi - - # Check for memory alarms for this Master or Slave node. - # If alert found, reset the alarm - # and restart the resource as it likely means a dead end situation - # when rabbitmq cluster is running with blocked publishing due - # to high memory watermark exceeded. - local alarms - local rc_alarms - local timeout_alarms - alarms=`su_rabbit_cmd "${OCF_RESKEY_ctl} -q eval 'rabbit_alarm:get_alarms().'"` - rc_alarms=$? - check_timeouts $rc_alarms "rabbit_get_alarms_timeouts" "get_alarms" - timeout_alarms=$? - - if [ $timeout_alarms -eq 2 ]; then - return $OCF_ERR_GENERIC - - elif [ $timeout_alarms -eq 0 ]; then - if [ $rc_alarms -ne 0 ]; then - ocf_log err "${LH} rabbitmqctl get_alarms exited with errors." - rc=$OCF_ERR_GENERIC - - elif [ -n "${alarms}" ]; then - for node in "${alarms}"; do - name=`echo ${node} | perl -n -e "m/memory,'(?<n>\S+)+'/ && print \"$+{n}\n\""` - if [ "${name}" = "${RABBITMQ_NODENAME}" ] ; then - ocf_log err "${LH} Found raised memory alarm. Erasing the alarm and restarting." - su_rabbit_cmd "${OCF_RESKEY_ctl} set_vm_memory_high_watermark 10 2>&1 > /dev/null" - rc=$OCF_ERR_GENERIC - break - fi - done - fi - fi - - # Check if the list of all queues is available, - # Also report some queues stats and total virtual memory. - local queues - local rc_queues - local timeout_queues - queues=`su_rabbit_cmd "${OCF_RESKEY_ctl} -q list_queues memory messages consumer_utilisation"` - rc_queues=$? - check_timeouts $rc_queues "rabbit_list_queues_timeouts" "list_queues" - timeout_queues=$? - - if [ $timeout_queues -eq 2 ]; then - return $OCF_ERR_GENERIC - - elif [ $timeout_queues -eq 0 ]; then - if [ $rc_queues -ne 0 ]; then - ocf_log err "${LH} rabbitmqctl list_queues exited with errors." - rc=$OCF_ERR_GENERIC - - elif [ -n "${queues}" ]; then - local q_c - q_c=`printf "%b\n" "${queues}" | wc -l` - local mem - mem=`printf "%b\n" "${queues}" | awk -v sum=0 '{sum+=$1} END {print (sum/1048576)}'` - local mes - mes=`printf "%b\n" "${queues}" | awk -v sum=0 '{sum+=$2} END {print sum}'` - local c_u - c_u=`printf "%b\n" "${queues}" | awk -v sum=0 -v cnt=${q_c} '{sum+=$3} END {print (sum+1)/(cnt+1)}'` - local status - status=`echo $(su_rabbit_cmd "${OCF_RESKEY_ctl} -q status")` - ocf_log info "${LH} RabbitMQ is running ${q_c} queues consuming ${mem}m of ${TOTALVMEM}m total, with ${mes} queued messages, average consumer utilization ${c_u}" - ocf_log info "${LH} RabbitMQ status: ${status}" - fi - fi - - ocf_log info "${LH} get_monitor function ready to return ${rc}" - return $rc -} - - -action_monitor() { - local rc=$OCF_ERR_GENERIC - local LH="${LL} monitor:" - ocf_log debug "${LH} action start." - if [ "${OCF_RESKEY_debug}" = 'true' ] ; then - d=`date '+%Y%m%d %H:%M:%S'` - echo $d >> /tmp/rmq-monitor.log - env >> /tmp/rmq-monitor.log - echo "$d [monitor] start='${OCF_RESKEY_CRM_meta_notify_start_uname}' stop='${OCF_RESKEY_CRM_meta_notify_stop_uname}' active='${OCF_RESKEY_CRM_meta_notify_active_uname}' inactive='${OCF_RESKEY_CRM_meta_notify_inactive_uname}'" >> /tmp/rmq-ocf.log - fi - get_monitor - rc=$? - ocf_log debug "${LH} role: ${OCF_RESKEY_CRM_meta_role}" - ocf_log debug "${LH} result: $rc" - ocf_log debug "${LH} action end." - return $rc -} - - -action_start() { - local rc=$OCF_ERR_GENERIC - local LH="${LL} start:" - - if [ "${OCF_RESKEY_debug}" = 'true' ] ; then - d=`date '+%Y%m%d %H:%M:%S'` - echo $d >> /tmp/rmq-start.log - env >> /tmp/rmq-start.log - echo "$d [start] start='${OCF_RESKEY_CRM_meta_notify_start_uname}' stop='${OCF_RESKEY_CRM_meta_notify_stop_uname}' active='${OCF_RESKEY_CRM_meta_notify_active_uname}' inactive='${OCF_RESKEY_CRM_meta_notify_inactive_uname}'" >> /tmp/rmq-ocf.log - fi - - ocf_log info "${LH} action begin." - - get_status - rc=$? - if [ $rc -eq $OCF_SUCCESS ] ; then - ocf_log warn "${LH} RMQ-runtime (beam) already started." - return $OCF_SUCCESS - fi - - ocf_log info "${LH} RMQ going to start." - start_rmq_server_app - rc=$? - if [ $rc -eq $OCF_SUCCESS ] ; then - ocf_log info "${LH} RMQ prepared for start succesfully." - fi - - ocf_run crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit_list_channels_timeouts' --update '0' - ocf_run crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit_get_alarms_timeouts' --update '0' - ocf_run crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit_list_queues_timeouts' --update '0' - - ocf_log info "${LH} action end." - return $rc -} - - -action_stop() { - local rc=$OCF_ERR_GENERIC - local LH="${LL} stop:" - - if [ "${OCF_RESKEY_debug}" = 'true' ] ; then - d=$(date '+%Y%m%d %H:%M:%S') - echo $d >> /tmp/rmq-stop.log - env >> /tmp/rmq-stop.log - echo "$d [stop] start='${OCF_RESKEY_CRM_meta_notify_start_uname}' stop='${OCF_RESKEY_CRM_meta_notify_stop_uname}' active='${OCF_RESKEY_CRM_meta_notify_active_uname}' inactive='${OCF_RESKEY_CRM_meta_notify_inactive_uname}'" >> /tmp/rmq-ocf.log - fi - - ocf_log info "${LH} action begin." - - # Wait for synced state first - ocf_log info "${LH} waiting $((OCF_RESKEY_stop_time/2)) to sync" - wait_sync $((OCF_RESKEY_stop_time/2)) - - # remove master flag - # remove master score - crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit-master' --delete - master_score 0 - - ocf_log info "${LH} RMQ-runtime (beam) going to down." - stop_server_process - - crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit-start-time' --delete - # remove file with rmq-server start timestamp - - #todo: make this timeout corresponded to the stop timeout for resource - sleep 10 - - ocf_log info "${LH} action end." - get_status - rc=$? - if [ $rc -eq $OCF_NOT_RUNNING ] ; then - ocf_log info "${LH} RMQ-runtime (beam) not running." - return $OCF_SUCCESS - else - return $OCF_ERR_GENERIC - fi - -} - -####################################################################### -# Join the cluster and return OCF_SUCCESS, if joined. -# Return 10, if node is trying to join to itself or empty destination. -# Return OCF_ERR_GENERIC, if cannot join. -jjj_join () { - local join_to="$1" - local rc=$OCF_ERR_GENERIC - local LH="${LL} jjj_join:" - - my_host ${join_to} - rc=$? - ocf_log debug "${LH} node='${join_to}' rc='${rc}'" - - # Check whether we are joining to ourselves - # or master host is not given - if [ $rc -ne 0 -a "${join_to}" ] ; then - ocf_log info "${LH} Joining to cluster by node '${join_to}'" - join_to_cluster "${join_to}" - rc=$? - if [ $rc -ne $OCF_SUCCESS ] ; then - ocf_log err "${LH} Failed to join the cluster. The mnesia will be reset." - reset_mnesia - rc=$OCF_ERR_GENERIC - fi - fi - return $rc -} - -action_notify() { - local rc_join=$OCF_SUCCESS - local rc=$OCF_ERR_GENERIC - local rc2=$OCF_ERR_GENERIC - local LH="${LL} notify:" - local nodelist - - if [ "${OCF_RESKEY_debug}" = 'true' ] ; then - d=`date '+%Y%m%d %H:%M:%S'` - echo $d >> /tmp/rmq-notify.log - env >> /tmp/rmq-notify.log - echo "$d [notify] ${OCF_RESKEY_CRM_meta_notify_type}-${OCF_RESKEY_CRM_meta_notify_operation} promote='${OCF_RESKEY_CRM_meta_notify_promote_uname}' demote='${OCF_RESKEY_CRM_meta_notify_demote_uname}' master='${OCF_RESKEY_CRM_meta_notify_master_uname}' slave='${OCF_RESKEY_CRM_meta_notify_slave_uname}' start='${OCF_RESKEY_CRM_meta_notify_start_uname}' stop='${OCF_RESKEY_CRM_meta_notify_stop_uname}' active='${OCF_RESKEY_CRM_meta_notify_active_uname}' inactive='${OCF_RESKEY_CRM_meta_notify_inactive_uname}'" >> /tmp/rmq-ocf.log - fi - - if [ "${OCF_RESKEY_CRM_meta_notify_type}" = 'pre' ] ; then - # PRE- anything notify section - case "$OCF_RESKEY_CRM_meta_notify_operation" in - promote) - ocf_log info "${LH} pre-promote begin." - my_host "$OCF_RESKEY_CRM_meta_notify_promote_uname" - rc=$? - if [ $rc -eq $OCF_SUCCESS ] ; then - nodelist=$(get_all_pacemaker_nodes) - for i in $nodelist - do - crm_attribute -N $i -l reboot --name 'rabbit-master' --delete - done - ocf_log info "${LH} pre-promote end." - fi - ;; - *) - ;; - esac - fi - - if [ "${OCF_RESKEY_CRM_meta_notify_type}" = 'post' ] ; then - # POST- anything notify section - case "$OCF_RESKEY_CRM_meta_notify_operation" in - promote) - ocf_log info "${LH} post-promote begin." - # Do nothing, if the list of nodes being promoted reported empty. - # Delegate recovery, if needed, to the "running out of the cluster" monitor's logic - if [ -z "${OCF_RESKEY_CRM_meta_notify_promote_uname}" ] ; then - ocf_log warn "${LH} there are no nodes to join to reported on post-promote. Nothing to do." - ocf_log info "${LH} post-promote end." - return $OCF_SUCCESS - fi - # Note, this should fail when the mnesia is inconsistent. - # For example, when the "old" master processing the promition of the new one. - # Later this ex-master node will rejoin the cluster at post-start. - jjj_join "${OCF_RESKEY_CRM_meta_notify_promote_uname}" - rc=$? - ocf_log info "${LH} post-promote end." - if [ $rc -eq $OCF_ERR_GENERIC ] ; then - ocf_log err "${LH} Failed to join the cluster on post-promote. The resource will be restarted." - return $OCF_ERR_GENERIC - fi - ;; - start) - ocf_log info "${LH} post-start begin." - local nodes_list="${OCF_RESKEY_CRM_meta_notify_start_uname} ${OCF_RESKEY_CRM_meta_notify_active_uname}" - # Do nothing, if the list of nodes being started or running reported empty - # Delegate recovery, if needed, to the "running out of the cluster" monitor's logic - if [ -z "${nodes_list}" ] ; then - ocf_log warn "${LH} I'm a last man standing and I must survive!" - ocf_log info "${LH} post-start end." - return $OCF_SUCCESS - fi - # check did this event from this host - my_host "${nodes_list}" - rc=$? - # Do nothing, if there is no master reported - # Delegate recovery, if needed, to the "running out of the cluster" monitor's logic - if [ -z "${OCF_RESKEY_CRM_meta_notify_master_uname}" ] ; then - ocf_log warn "${LH} there are no nodes to join to reported on post-start. Nothing to do." - ocf_log info "${LH} post-start end." - return $OCF_SUCCESS - fi - if [ $rc -eq $OCF_SUCCESS ] ; then - # Now we need to: - # a. join to the cluster if we are not joined yet - # b. start the RabbitMQ application, which is always - # stopped after start action finishes - check_need_join_to ${OCF_RESKEY_CRM_meta_notify_master_uname} - rc_join=$? - if [ $rc_join -eq $OCF_SUCCESS ]; then - ocf_log warn "${LH} Going to join node ${OCF_RESKEY_CRM_meta_notify_master_uname}" - jjj_join "${OCF_RESKEY_CRM_meta_notify_master_uname}" - rc2=$? - else - ocf_log warn "${LH} We are already clustered with node ${OCF_RESKEY_CRM_meta_notify_master_uname}" - if try_to_start_rmq_app; then - rc2=$OCF_SUCCESS - else - rc2=$OCF_ERR_GENERIC - fi - fi - ocf_log info "${LH} post-start end." - if [ -s "${OCF_RESKEY_definitions_dump_file}" ] ; then - ocf_log info "File ${OCF_RESKEY_definitions_dump_file} exists" - ocf_run curl -X POST -u $OCF_RESKEY_admin_user:$OCF_RESKEY_admin_password 127.0.0.1:15672/api/definitions --header "Content-Type:application/json" -d @$OCF_RESKEY_definitions_dump_file - rc=$? - if [ $rc -eq $OCF_SUCCESS ] ; then - ocf_log info "RMQ definitions have imported succesfully." - else - ocf_log err "RMQ definitions have not imported." - fi - fi - if [ $rc2 -eq $OCF_ERR_GENERIC ] ; then - ocf_log warn "${LH} Failed to join the cluster on post-start. The resource will be restarted." - ocf_log info "${LH} post-start end." - return $OCF_ERR_GENERIC - fi - fi - ;; - stop) - # if rabbitmq-server stops on any another node, we should remove it from cluster (as ordinary operation) - ocf_log info "${LH} post-stop begin." - # Report not running, if there are no nodes being stopped reported - if [ -z "${OCF_RESKEY_CRM_meta_notify_stop_uname}" ] ; then - ocf_log warn "${LH} there are no nodes being stopped reported on post-stop. The resource will be restarted." - ocf_log info "${LH} post-stop end." - return $OCF_ERR_GENERIC - fi - my_host "${OCF_RESKEY_CRM_meta_notify_stop_uname}" - rc=$? - if [ $rc -ne $OCF_SUCCESS ] ; then - # Wait for synced state first - ocf_log info "${LH} waiting $((OCF_RESKEY_stop_time/2)) to sync" - wait_sync $((OCF_RESKEY_stop_time/2)) - # On other nodes processing the post-stop, make sure the stopped node will be forgotten - unjoin_nodes_from_cluster "${OCF_RESKEY_CRM_meta_notify_stop_uname}" - else - # On the nodes being stopped, reset the master score - ocf_log info "${LH} resetting the master score." - master_score 0 - fi - # always returns OCF_SUCCESS - ocf_log info "${LH} post-stop end." - ;; - demote) - # if rabbitmq-server stops on any another node, we should remove it from cluster (as ordinary operation) - ocf_log info "${LH} post-demote begin." - # Report not running, if the list of nodes being demoted reported empty - if [ -z "${OCF_RESKEY_CRM_meta_notify_demote_uname}" ] ; then - ocf_log warn "${LH} there are no nodes being demoted reported on post-demote. The resource will be restarted." - ocf_log info "${LH} post-demote end." - return $OCF_ERR_GENERIC - fi - my_host "${OCF_RESKEY_CRM_meta_notify_demote_uname}" - rc=$? - if [ $rc -ne $OCF_SUCCESS ] ; then - # On ohter nodes processing the post-demote, make sure the demoted node will be forgotten - unjoin_nodes_from_cluster "${OCF_RESKEY_CRM_meta_notify_demote_uname}" - else - # Wait for synced state first - ocf_log info "${LH} waiting $((OCF_RESKEY_stop_time/2)) to sync" - wait_sync $((OCF_RESKEY_stop_time/2)) - # On the nodes being demoted, reset the master score - ocf_log info "${LH} resetting the master score." - master_score 0 - ocf_log info "${LH} master was demoted. stopping RabbitMQ app." - stop_rmq_server_app - rc2=$? - crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit-start-time' --delete - if [ $rc2 -ne $OCF_SUCCESS ] ; then - ocf_log err "${LH} RMQ-server app can't be stopped on post-demote. Master resource is failed" - ocf_log info "${LH} post-demote end." - exit $OCF_FAILED_MASTER - fi - fi - ocf_log info "${LH} post-demote end." - ;; - *) ;; - esac - fi - - return $OCF_SUCCESS -} - - -action_promote() { - local rc=$OCF_ERR_GENERIC - local LH="${LL} promote:" - - if [ "${OCF_RESKEY_debug}" = 'true' ] ; then - d=$(date '+%Y%m%d %H:%M:%S') - echo $d >> /tmp/rmq-promote.log - env >> /tmp/rmq-promote.log - echo "$d [promote] start='${OCF_RESKEY_CRM_meta_notify_start_uname}' stop='${OCF_RESKEY_CRM_meta_notify_stop_uname}' active='${OCF_RESKEY_CRM_meta_notify_active_uname}' inactive='${OCF_RESKEY_CRM_meta_notify_inactive_uname}'" >> /tmp/rmq-ocf.log - fi - - ocf_log info "${LH} action begin." - - get_monitor - rc=$? - ocf_log info "${LH} get_monitor returns ${rc}" - case "$rc" in - "$OCF_SUCCESS") - # Running as slave. Normal, expected behavior. - ocf_log info "${LH} Resource is currently running as Slave" - # rabbitmqctl start_app if need - get_status rabbit - rc=$? - ocf_log info "${LH} Updating cluster master attribute" - ocf_run crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit-master' --update 'true' - if [ $rc -ne $OCF_SUCCESS ] ; then - ocf_log info "${LH} RMQ app is not started. Starting..." - start_rmq_server_app - rc=$? - if [ $rc -eq 0 ] ; then - try_to_start_rmq_app - rc=$? - if [ $rc -ne 0 ] ; then - ocf_log err "${LH} Can't start RMQ app. Master resource is failed." - ocf_log info "${LH} action end." - exit $OCF_FAILED_MASTER - fi - ocf_log info "${LH} Setting HA policy for all queues" - ${OCF_RESKEY_ctl} set_policy ha-all "." '{"ha-mode":"all", "ha-sync-mode":"automatic"}' --apply-to all --priority 0 - ${OCF_RESKEY_ctl} set_policy heat_rpc_expire "^heat-engine-listener\\." '{"expires":3600000,"ha-mode":"all","ha-sync-mode":"automatic"}' --apply-to all --priority 1 - ${OCF_RESKEY_ctl} set_policy results_expire "^results\\." '{"expires":3600000,"ha-mode":"all","ha-sync-mode":"automatic"}' --apply-to all --priority 1 - ${OCF_RESKEY_ctl} set_policy tasks_expire "^tasks\\." '{"expires":3600000,"ha-mode":"all","ha-sync-mode":"automatic"}' --apply-to all --priority 1 - # create timestamp file - ocf_log info "${LH} Updating start timestamp" - ocf_run crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit-start-time' --update $(now) - ocf_log info "${LH} Checking master status" - get_monitor - rc=$? - ocf_log info "${LH} Master status is $rc" - if [ $rc = $OCF_RUNNING_MASTER ] - then - rc=$OCF_SUCCESS - else - ocf_log err "${LH} Master resource is failed." - ocf_log info "${LH} action end." - exit $OCF_FAILED_MASTER - fi - else - ocf_log err "${LH} Can't start RMQ-runtime." - rc=$OCF_ERR_GENERIC - fi - fi - return $rc - ;; - "$OCF_RUNNING_MASTER") - # Already a master. Unexpected, but not a problem. - ocf_log warn "${LH} Resource is already running as Master" - rc=$OCF_SUCCESS - ;; - - "$OCF_FAILED_MASTER") - # Master failed. - ocf_log err "${LH} Master resource is failed and not running" - ocf_log info "${LH} action end." - exit $OCF_FAILED_MASTER - ;; - - "$OCF_NOT_RUNNING") - # Currently not running. - ocf_log err "${LH} Resource is currently not running" - rc=$OCF_NOT_RUNNING - ;; - *) - # Failed resource. Let the cluster manager recover. - ocf_log err "${LH} Unexpected error, cannot promote" - ocf_log info "${LH} action end." - exit $rc - ;; - esac - - # transform slave RMQ-server to master - - ocf_log info "${LH} action end." - return $rc -} - - -action_demote() { - local rc=$OCF_ERR_GENERIC - local LH="${LL} demote:" - - if [ "${OCF_RESKEY_debug}" = 'true' ] ; then - d=`date '+%Y%m%d %H:%M:%S'` - echo $d >> /tmp/rmq-demote.log - env >> /tmp/rmq-demote.log - echo "$d [demote] start='${OCF_RESKEY_CRM_meta_notify_start_uname}' stop='${OCF_RESKEY_CRM_meta_notify_stop_uname}' active='${OCF_RESKEY_CRM_meta_notify_active_uname}' inactive='${OCF_RESKEY_CRM_meta_notify_inactive_uname}'" >> /tmp/rmq-ocf.log - - fi - - ocf_log info "${LH} action begin." - - get_monitor - rc=$? - case "$rc" in - "$OCF_RUNNING_MASTER") - # Running as master. Normal, expected behavior. - ocf_log warn "${LH} Resource is currently running as Master" - - # Wait for synced state first - ocf_log info "${LH} waiting $((OCF_RESKEY_stop_time/2)) to sync" - wait_sync $((OCF_RESKEY_stop_time/2)) - - stop_rmq_server_app - rc=$? - crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit-master' --delete - crm_attribute -N $THIS_PCMK_NODE -l reboot --name 'rabbit-start-time' --delete - ;; - "$OCF_SUCCESS") - # Alread running as slave. Nothing to do. - ocf_log warn "${LH} Resource is currently running as Slave" - rc=$OCF_SUCCESS - ;; - "$OCF_FAILED_MASTER") - # Master failed and being demoted. - ocf_log err "${LH} Demoting of a failed Master." - ocf_log info "${LH} action end." - exit $OCF_FAILED_MASTER - ;; - "$OCF_NOT_RUNNING") - ocf_log warn "${LH} Try to demote currently not running resource. Nothing to do." - rc=$OCF_SUCCESS - ;; - "$OCF_ERR_GENERIC") - ocf_log err "${LH} Error while demote. Stopping resource." - action_stop - rc=$? - ;; - *) - # Failed resource. Let the cluster manager recover. - ocf_log err "${LH} Unexpected error, cannot demote" - ocf_log info "${LH} action end." - exit $rc - ;; - esac - - # transform master RMQ-server to slave - ocf_log info "${LH} action end." - return $rc -} -####################################################################### - -rmq_setup_env - -case "$1" in - meta-data) meta_data - exit $OCF_SUCCESS;; - usage|help) usage - exit $OCF_SUCCESS;; -esac - -# Anything except meta-data and help must pass validation -action_validate || exit $? - -# What kind of method was invoked? -case "$1" in - start) action_start;; - stop) action_stop;; - status) action_status;; - monitor) action_monitor;; - validate) action_validate;; - promote) action_promote;; - demote) action_demote;; - notify) action_notify;; - validate-all) action_validate;; - *) usage;; -esac -### diff --git a/packaging/common/rabbitmq-server.ocf b/packaging/common/rabbitmq-server.ocf deleted file mode 100755 index 804e65423d..0000000000 --- a/packaging/common/rabbitmq-server.ocf +++ /dev/null @@ -1,371 +0,0 @@ -#!/bin/sh -## The contents of this file are subject to the Mozilla Public License -## Version 1.1 (the "License"); you may not use this file except in -## compliance with the License. You may obtain a copy of the License -## at http://www.mozilla.org/MPL/ -## -## Software distributed under the License is distributed on an "AS IS" -## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -## the License for the specific language governing rights and -## limitations under the License. -## -## The Original Code is RabbitMQ. -## -## The Initial Developer of the Original Code is GoPivotal, Inc. -## Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved. -## - -## -## OCF Resource Agent compliant rabbitmq-server resource script. -## - -## OCF instance parameters -## OCF_RESKEY_server -## OCF_RESKEY_ctl -## OCF_RESKEY_nodename -## OCF_RESKEY_ip -## OCF_RESKEY_port -## OCF_RESKEY_config_file -## OCF_RESKEY_log_base -## OCF_RESKEY_mnesia_base -## OCF_RESKEY_server_start_args -## OCF_RESKEY_pid_file - -####################################################################### -# Initialization: - -: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat} -. ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs - -####################################################################### - -OCF_RESKEY_server_default="/usr/sbin/rabbitmq-server" -OCF_RESKEY_ctl_default="/usr/sbin/rabbitmqctl" -OCF_RESKEY_nodename_default="rabbit@localhost" -OCF_RESKEY_log_base_default="/var/log/rabbitmq" -OCF_RESKEY_pid_file_default="/var/run/rabbitmq/pid" -: ${OCF_RESKEY_server=${OCF_RESKEY_server_default}} -: ${OCF_RESKEY_ctl=${OCF_RESKEY_ctl_default}} -: ${OCF_RESKEY_nodename=${OCF_RESKEY_nodename_default}} -: ${OCF_RESKEY_log_base=${OCF_RESKEY_log_base_default}} -: ${OCF_RESKEY_pid_file=${OCF_RESKEY_pid_file_default}} - -meta_data() { - cat <<END -<?xml version="1.0"?> -<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> -<resource-agent name="rabbitmq-server"> -<version>1.0</version> - -<longdesc lang="en"> -Resource agent for RabbitMQ-server -</longdesc> - -<shortdesc lang="en">Resource agent for RabbitMQ-server</shortdesc> - -<parameters> -<parameter name="server" unique="0" required="0"> -<longdesc lang="en"> -The path to the rabbitmq-server script -</longdesc> -<shortdesc lang="en">Path to rabbitmq-server</shortdesc> -<content type="string" default="${OCF_RESKEY_server_default}" /> -</parameter> - -<parameter name="ctl" unique="0" required="0"> -<longdesc lang="en"> -The path to the rabbitmqctl script -</longdesc> -<shortdesc lang="en">Path to rabbitmqctl</shortdesc> -<content type="string" default="${OCF_RESKEY_ctl_default}" /> -</parameter> - -<parameter name="nodename" unique="0" required="0"> -<longdesc lang="en"> -The node name for rabbitmq-server -</longdesc> -<shortdesc lang="en">Node name</shortdesc> -<content type="string" default="${OCF_RESKEY_nodename_default}" /> -</parameter> - -<parameter name="ip" unique="0" required="0"> -<longdesc lang="en"> -The IP address for rabbitmq-server to listen on -</longdesc> -<shortdesc lang="en">IP Address</shortdesc> -<content type="string" default="" /> -</parameter> - -<parameter name="port" unique="0" required="0"> -<longdesc lang="en"> -The IP Port for rabbitmq-server to listen on -</longdesc> -<shortdesc lang="en">IP Port</shortdesc> -<content type="integer" default="" /> -</parameter> - -<parameter name="config_file" unique="0" required="0"> -<longdesc lang="en"> -Location of the config file (without the .config suffix) -</longdesc> -<shortdesc lang="en">Config file path (without the .config suffix)</shortdesc> -<content type="string" default="" /> -</parameter> - -<parameter name="log_base" unique="0" required="0"> -<longdesc lang="en"> -Location of the directory under which logs will be created -</longdesc> -<shortdesc lang="en">Log base path</shortdesc> -<content type="string" default="${OCF_RESKEY_log_base_default}" /> -</parameter> - -<parameter name="mnesia_base" unique="0" required="0"> -<longdesc lang="en"> -Location of the directory under which mnesia will store data -</longdesc> -<shortdesc lang="en">Mnesia base path</shortdesc> -<content type="string" default="" /> -</parameter> - -<parameter name="server_start_args" unique="0" required="0"> -<longdesc lang="en"> -Additional arguments provided to the server on startup -</longdesc> -<shortdesc lang="en">Server start arguments</shortdesc> -<content type="string" default="" /> -</parameter> - -<parameter name="pid_file" unique="0" required="0"> -<longdesc lang="en"> -Location of the file in which the pid will be stored -</longdesc> -<shortdesc lang="en">Pid file path</shortdesc> -<content type="string" default="${OCF_RESKEY_pid_file_default}" /> -</parameter> - -</parameters> - -<actions> -<action name="start" timeout="600" /> -<action name="stop" timeout="120" /> -<action name="status" timeout="20" interval="10" /> -<action name="monitor" timeout="20" interval="10" /> -<action name="validate-all" timeout="30" /> -<action name="meta-data" timeout="5" /> -</actions> -</resource-agent> -END -} - -rabbit_usage() { - cat <<END -usage: $0 {start|stop|status|monitor|validate-all|meta-data} - -Expects to have a fully populated OCF RA-compliant environment set. -END -} - -RABBITMQ_SERVER=$OCF_RESKEY_server -RABBITMQ_CTL=$OCF_RESKEY_ctl -RABBITMQ_NODENAME=$OCF_RESKEY_nodename -RABBITMQ_NODE_IP_ADDRESS=$OCF_RESKEY_ip -RABBITMQ_NODE_PORT=$OCF_RESKEY_port -RABBITMQ_CONFIG_FILE=$OCF_RESKEY_config_file -RABBITMQ_LOG_BASE=$OCF_RESKEY_log_base -RABBITMQ_MNESIA_BASE=$OCF_RESKEY_mnesia_base -RABBITMQ_SERVER_START_ARGS=$OCF_RESKEY_server_start_args -RABBITMQ_PID_FILE=$OCF_RESKEY_pid_file -[ ! -z $RABBITMQ_NODENAME ] && NODENAME_ARG="-n $RABBITMQ_NODENAME" -[ ! -z $RABBITMQ_NODENAME ] && export RABBITMQ_NODENAME - -ensure_pid_dir () { - PID_DIR=`dirname ${RABBITMQ_PID_FILE}` - if [ ! -d ${PID_DIR} ] ; then - mkdir -p ${PID_DIR} - chown -R rabbitmq:rabbitmq ${PID_DIR} - chmod 755 ${PID_DIR} - fi - return $OCF_SUCCESS -} - -remove_pid () { - rm -f ${RABBITMQ_PID_FILE} - rmdir `dirname ${RABBITMQ_PID_FILE}` || : -} - -export_vars() { - [ ! -z $RABBITMQ_NODE_IP_ADDRESS ] && export RABBITMQ_NODE_IP_ADDRESS - [ ! -z $RABBITMQ_NODE_PORT ] && export RABBITMQ_NODE_PORT - [ ! -z $RABBITMQ_CONFIG_FILE ] && export RABBITMQ_CONFIG_FILE - [ ! -z $RABBITMQ_LOG_BASE ] && export RABBITMQ_LOG_BASE - [ ! -z $RABBITMQ_MNESIA_BASE ] && export RABBITMQ_MNESIA_BASE - [ ! -z $RABBITMQ_SERVER_START_ARGS ] && export RABBITMQ_SERVER_START_ARGS - [ ! -z $RABBITMQ_PID_FILE ] && ensure_pid_dir && export RABBITMQ_PID_FILE -} - -rabbit_validate_partial() { - if [ ! -x $RABBITMQ_SERVER ]; then - ocf_log err "rabbitmq-server server $RABBITMQ_SERVER does not exist or is not executable"; - exit $OCF_ERR_INSTALLED; - fi - - if [ ! -x $RABBITMQ_CTL ]; then - ocf_log err "rabbitmq-server ctl $RABBITMQ_CTL does not exist or is not executable"; - exit $OCF_ERR_INSTALLED; - fi -} - -rabbit_validate_full() { - if [ ! -z $RABBITMQ_CONFIG_FILE ] && [ ! -e "${RABBITMQ_CONFIG_FILE}.config" ]; then - ocf_log err "rabbitmq-server config_file ${RABBITMQ_CONFIG_FILE}.config does not exist or is not a file"; - exit $OCF_ERR_INSTALLED; - fi - - if [ ! -z $RABBITMQ_LOG_BASE ] && [ ! -d $RABBITMQ_LOG_BASE ]; then - ocf_log err "rabbitmq-server log_base $RABBITMQ_LOG_BASE does not exist or is not a directory"; - exit $OCF_ERR_INSTALLED; - fi - - if [ ! -z $RABBITMQ_MNESIA_BASE ] && [ ! -d $RABBITMQ_MNESIA_BASE ]; then - ocf_log err "rabbitmq-server mnesia_base $RABBITMQ_MNESIA_BASE does not exist or is not a directory"; - exit $OCF_ERR_INSTALLED; - fi - - rabbit_validate_partial - - return $OCF_SUCCESS -} - -rabbit_status() { - rabbitmqctl_action "status" -} - -rabbit_wait() { - rabbitmqctl_action "wait" $1 -} - -rabbitmqctl_action() { - local rc - local action - action=$@ - $RABBITMQ_CTL $NODENAME_ARG $action > /dev/null 2> /dev/null - rc=$? - case "$rc" in - 0) - ocf_log debug "RabbitMQ server is running normally" - return $OCF_SUCCESS - ;; - 2) - ocf_log debug "RabbitMQ server is not running" - return $OCF_NOT_RUNNING - ;; - *) - ocf_log err "Unexpected return from rabbitmqctl $NODENAME_ARG $action: $rc" - exit $OCF_ERR_GENERIC - esac -} - -rabbit_start() { - local rc - - if rabbit_status; then - ocf_log info "Resource already running." - return $OCF_SUCCESS - fi - - export_vars - - setsid sh -c "$RABBITMQ_SERVER > ${RABBITMQ_LOG_BASE}/startup_log 2> ${RABBITMQ_LOG_BASE}/startup_err" & - - # Wait for the server to come up. - # Let the CRM/LRM time us out if required - rabbit_wait $RABBITMQ_PID_FILE - rc=$? - if [ "$rc" != $OCF_SUCCESS ]; then - remove_pid - ocf_log info "rabbitmq-server start failed: $rc" - exit $OCF_ERR_GENERIC - fi - - return $OCF_SUCCESS -} - -rabbit_stop() { - local rc - - if ! rabbit_status; then - ocf_log info "Resource not running." - return $OCF_SUCCESS - fi - - $RABBITMQ_CTL stop ${RABBITMQ_PID_FILE} - rc=$? - - if [ "$rc" != 0 ]; then - ocf_log err "rabbitmq-server stop command failed: $RABBITMQ_CTL stop, $rc" - return $rc - fi - - # Spin waiting for the server to shut down. - # Let the CRM/LRM time us out if required - stop_wait=1 - while [ $stop_wait = 1 ]; do - rabbit_status - rc=$? - if [ "$rc" = $OCF_NOT_RUNNING ]; then - remove_pid - stop_wait=0 - break - elif [ "$rc" != $OCF_SUCCESS ]; then - ocf_log info "rabbitmq-server stop failed: $rc" - exit $OCF_ERR_GENERIC - fi - sleep 1 - done - - return $OCF_SUCCESS -} - -rabbit_monitor() { - rabbit_status - return $? -} - -case $__OCF_ACTION in - meta-data) - meta_data - exit $OCF_SUCCESS - ;; - usage|help) - rabbit_usage - exit $OCF_SUCCESS - ;; -esac - -if ocf_is_probe; then - rabbit_validate_partial -else - rabbit_validate_full -fi - -case $__OCF_ACTION in - start) - rabbit_start - ;; - stop) - rabbit_stop - ;; - status|monitor) - rabbit_monitor - ;; - validate-all) - exit $OCF_SUCCESS - ;; - *) - rabbit_usage - exit $OCF_ERR_UNIMPLEMENTED - ;; -esac - -exit $? diff --git a/packaging/debs/Debian/.gitignore b/packaging/debs/Debian/.gitignore new file mode 100644 index 0000000000..6a4aec11b5 --- /dev/null +++ b/packaging/debs/Debian/.gitignore @@ -0,0 +1,3 @@ +/debian/postrm +/debian/stamp-makefile-build +/rabbitmq-server_* diff --git a/packaging/debs/Debian/Makefile b/packaging/debs/Debian/Makefile index d9064c8729..8a39288b38 100644 --- a/packaging/debs/Debian/Makefile +++ b/packaging/debs/Debian/Makefile @@ -1,38 +1,53 @@ -TARBALL_DIR=../../../dist -TARBALL=$(notdir $(wildcard $(TARBALL_DIR)/rabbitmq-server-[0-9.]*.tar.gz)) -COMMON_DIR=../../common -VERSION=$(shell echo $(TARBALL) | sed -e 's:rabbitmq-server-\(.*\)\.tar\.gz:\1:g') +SOURCE_DIST_FILE ?= $(wildcard ../../../rabbitmq-server-*.tar.xz) -DEBIAN_ORIG_TARBALL=$(shell echo $(TARBALL) | sed -e 's:\(.*\)-\(.*\)\(\.tar\.gz\):\1_\2\.orig\3:g') -UNPACKED_DIR=rabbitmq-server-$(VERSION) -PACKAGENAME=rabbitmq-server -SIGNING_KEY_ID=056E8E56 +ifneq ($(filter-out clean,$(MAKECMDGOALS)),) +ifeq ($(SOURCE_DIST_FILE),) +$(error Cannot find source archive; please specify SOURCE_DIST_FILE) +endif +ifneq ($(words $(SOURCE_DIST_FILE)),1) +$(error Multile source archives found; please specify SOURCE_DIST_FILE) +endif + +VERSION ?= $(patsubst rabbitmq-server-%.tar.xz,%,$(notdir $(SOURCE_DIST_FILE))) +ifeq ($(VERSION),) +$(error Cannot determine version; please specify VERSION) +endif +endif + +DEBIAN_ORIG_TARBALL = rabbitmq-server_$(VERSION).orig.tar.xz +UNPACKED_DIR = rabbitmq-server-$(VERSION) +PACKAGENAME = rabbitmq-server ifneq "$(UNOFFICIAL_RELEASE)" "" SIGNING=-us -uc else - SIGNING=-k$(SIGNING_KEY_ID) + SIGNING=-k$(SIGNING_KEY) endif -all: - @echo 'Please choose a target from the Makefile.' +unexport DEPS_DIR +unexport ERL_LIBS + +all: package + @: package: clean - cp $(TARBALL_DIR)/$(TARBALL) $(DEBIAN_ORIG_TARBALL) - tar -zxf $(DEBIAN_ORIG_TARBALL) - cp -r debian $(UNPACKED_DIR) - cp $(COMMON_DIR)/* $(UNPACKED_DIR)/debian/ - sed -i -e 's|@SU_RABBITMQ_SH_C@|su rabbitmq -s /bin/sh -c|' \ - -e 's|@STDOUT_STDERR_REDIRECTION@|> "$$RABBITMQ_LOG_BASE/startup_log" 2> "$$RABBITMQ_LOG_BASE/startup_err"|' \ - $(UNPACKED_DIR)/debian/rabbitmq-script-wrapper - chmod a+x $(UNPACKED_DIR)/debian/rules - echo "This package was debianized by Tony Garnock-Jones <tonyg@rabbitmq.com> on\nWed, 3 Jan 2007 15:43:44 +0000.\n\nIt was downloaded from http://www.rabbitmq.com/\n\n" > $(UNPACKED_DIR)/debian/copyright - cat $(UNPACKED_DIR)/LICENSE >> $(UNPACKED_DIR)/debian/copyright - echo "\n\nThe Debian packaging is (C) 2007-2013, GoPivotal, Inc. and is licensed\nunder the MPL 1.1, see above.\n" >> $(UNPACKED_DIR)/debian/copyright + cp -a $(SOURCE_DIST_FILE) $(DEBIAN_ORIG_TARBALL) + tar -Jxf $(DEBIAN_ORIG_TARBALL) + cp -a debian $(UNPACKED_DIR) + rsync -a \ + --exclude '.sw?' --exclude '.*.sw?' \ + --exclude '.git*' \ + --delete --delete-excluded \ + debian/ $(UNPACKED_DIR)/debian/ UNOFFICIAL_RELEASE=$(UNOFFICIAL_RELEASE) VERSION=$(VERSION) ./check-changelog.sh rabbitmq-server $(UNPACKED_DIR) - cd $(UNPACKED_DIR); GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -sa -rfakeroot $(SIGNING) + cd $(UNPACKED_DIR); GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -sa $(SIGNING) rm -rf $(UNPACKED_DIR) + if test "$(PACKAGES_DIR)"; then \ + mkdir -p "$(PACKAGES_DIR)"; \ + mv $(PACKAGENAME)_$(VERSION)* "$(PACKAGES_DIR)"; \ + fi + clean: rm -rf $(UNPACKED_DIR) rm -f $(PACKAGENAME)_*.tar.gz diff --git a/packaging/debs/Debian/debian/compat b/packaging/debs/Debian/debian/compat index 7ed6ff82de..ec635144f6 100644 --- a/packaging/debs/Debian/debian/compat +++ b/packaging/debs/Debian/debian/compat @@ -1 +1 @@ -5 +9 diff --git a/packaging/debs/Debian/debian/control b/packaging/debs/Debian/debian/control index 8d018dd46c..56acaa948e 100644 --- a/packaging/debs/Debian/debian/control +++ b/packaging/debs/Debian/debian/control @@ -2,9 +2,19 @@ Source: rabbitmq-server Section: net Priority: extra Maintainer: RabbitMQ Team <info@rabbitmq.com> -Uploaders: RabbitMQ Team <info@rabbitmq.com> -Build-Depends: cdbs, debhelper (>= 5), erlang-dev, python-simplejson, xmlto, xsltproc, erlang-nox (>= 1:16.b.3), erlang-src (>= 1:16.b.3), unzip, zip -Standards-Version: 3.9.2 +Uploaders: Alvaro Videla <alvaro@rabbitmq.com>, + Michael Klishin <michael@rabbitmq.com>, + Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com>, + Giuseppe Privitera <giuseppe@rabbitmq.com> +Build-Depends: debhelper (>= 9), + erlang-dev, + python-simplejson, + xmlto, + xsltproc, + erlang-nox (>= 1:16.b.3), + zip, + rsync +Standards-Version: 3.9.4 Package: rabbitmq-server Architecture: all diff --git a/packaging/debs/Debian/debian/copyright b/packaging/debs/Debian/debian/copyright new file mode 100644 index 0000000000..521b903754 --- /dev/null +++ b/packaging/debs/Debian/debian/copyright @@ -0,0 +1,52 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: rabbitmq-server +Upstream-Contact: Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> +Source: https://github.com/rabbitmq/rabbitmq-server + +Files: * +Copyright: 2007-2015 Pivotal Software, Inc. +License: MPL-1.1 + +Files: src/mochinum.erl deps/rabbit_common/src/mochijson2.erl +Copyright: 2007 Mochi Media, Inc. +License: MIT + +License: MPL-1.1 + The contents of this file are subject to the Mozilla Public License + Version 1.1 (the "License"); you may not use this file except in + compliance with the License. You may obtain a copy of the License at + http://www.mozilla.org/MPL/ + . + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License + . + The Original Code is RabbitMQ + . + The Initial Developer of the Original Code is Pivotal Software, Inc. + Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved. + +License: MIT + This is the MIT license + . + Copyright (c) 2007 Mochi Media, Inc + . + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions + : + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software + . + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packaging/debs/Debian/debian/rabbitmq-server.docs b/packaging/debs/Debian/debian/rabbitmq-server.docs new file mode 100644 index 0000000000..40d4f2dc81 --- /dev/null +++ b/packaging/debs/Debian/debian/rabbitmq-server.docs @@ -0,0 +1 @@ +docs/rabbitmq.config.example diff --git a/packaging/debs/Debian/debian/rabbitmq-server.manpages b/packaging/debs/Debian/debian/rabbitmq-server.manpages new file mode 100644 index 0000000000..e0220b47c3 --- /dev/null +++ b/packaging/debs/Debian/debian/rabbitmq-server.manpages @@ -0,0 +1,4 @@ +docs/rabbitmq-env.conf.5 +docs/rabbitmq-plugins.1 +docs/rabbitmq-server.1 +docs/rabbitmqctl.1 diff --git a/packaging/debs/Debian/debian/rules b/packaging/debs/Debian/debian/rules index 434172defc..053df18115 100644..100755 --- a/packaging/debs/Debian/debian/rules +++ b/packaging/debs/Debian/debian/rules @@ -1,26 +1,57 @@ #!/usr/bin/make -f +# -*- makefile -*- -include /usr/share/cdbs/1/rules/debhelper.mk -include /usr/share/cdbs/1/class/makefile.mk +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 -RABBIT_LIB=$(DEB_DESTDIR)usr/lib/rabbitmq/lib/rabbitmq_server-$(DEB_UPSTREAM_VERSION)/ -RABBIT_BIN=$(DEB_DESTDIR)usr/lib/rabbitmq/bin/ +DEB_DESTDIR = debian/rabbitmq-server +VERSION = $(shell dpkg-parsechangelog | awk '/^Version:/ {version=$$0; sub(/Version: /, "", version); sub(/-.*/, "", version); print version;}') -DOCDIR=$(DEB_DESTDIR)usr/share/doc/rabbitmq-server/ -DEB_MAKE_INSTALL_TARGET := install TARGET_DIR=$(RABBIT_LIB) SBIN_DIR=$(RABBIT_BIN) DOC_INSTALL_DIR=$(DOCDIR) MAN_DIR=$(DEB_DESTDIR)usr/share/man/ -DEB_MAKE_CLEAN_TARGET:= distclean -DEB_INSTALL_DOCS_ALL=debian/README +%: + dh $@ --parallel -install/rabbitmq-server:: - mkdir -p $(DOCDIR) - rm $(RABBIT_LIB)LICENSE* $(RABBIT_LIB)INSTALL* - for script in rabbitmqctl rabbitmq-server rabbitmq-plugins; do \ - install -p -D -m 0755 debian/rabbitmq-script-wrapper $(DEB_DESTDIR)usr/sbin/$$script; \ +override_dh_auto_clean: + $(MAKE) clean distclean-manpages + +override_dh_auto_build: + $(MAKE) dist manpages + +override_dh_auto_test: + @: + +export PREFIX RMQ_ROOTDIR + +override_dh_auto_install: PREFIX = /usr +override_dh_auto_install: RMQ_ROOTDIR = $(PREFIX)/lib/rabbitmq +override_dh_auto_install: RMQ_ERLAPP_DIR = $(RMQ_ROOTDIR)/lib/rabbitmq_server-$(VERSION) +override_dh_auto_install: + dh_auto_install + + $(MAKE) install-bin DESTDIR=$(DEB_DESTDIR) + + sed -e 's|@RABBIT_LIB@|$(RMQ_ERLAPP_DIR)|g' \ + < debian/postrm.in > debian/postrm + + sed -e 's|@SU_RABBITMQ_SH_C@|su rabbitmq -s /bin/sh -c|' \ + -e 's|@STDOUT_STDERR_REDIRECTION@|> "$$RABBITMQ_LOG_BASE/startup_log" 2> "$$RABBITMQ_LOG_BASE/startup_err"|' \ + < scripts/rabbitmq-script-wrapper \ + > $(DEB_DESTDIR)$(PREFIX)/sbin/rabbitmqctl + chmod 0755 $(DEB_DESTDIR)$(PREFIX)/sbin/rabbitmqctl + for script in rabbitmq-server rabbitmq-plugins; do \ + cp -a $(DEB_DESTDIR)$(PREFIX)/sbin/rabbitmqctl \ + $(DEB_DESTDIR)$(PREFIX)/sbin/$$script; \ done - sed -e 's|@RABBIT_LIB@|/usr/lib/rabbitmq/lib/rabbitmq_server-$(DEB_UPSTREAM_VERSION)|g' <debian/postrm.in >debian/postrm - install -p -D -m 0755 debian/rabbitmq-server.ocf $(DEB_DESTDIR)usr/lib/ocf/resource.d/rabbitmq/rabbitmq-server - install -p -D -m 0755 debian/rabbitmq-server-ha.ocf $(DEB_DESTDIR)usr/lib/ocf/resource.d/rabbitmq/rabbitmq-server-ha - install -p -D -m 0644 debian/rabbitmq-server.default $(DEB_DESTDIR)etc/default/rabbitmq-server -clean:: - rm -f plugins-src/rabbitmq-server debian/postrm plugins/README + install -p -D -m 0644 debian/rabbitmq-server.default \ + $(DEB_DESTDIR)/etc/default/rabbitmq-server + + install -p -D -m 0755 scripts/rabbitmq-server.ocf \ + $(DEB_DESTDIR)$(PREFIX)/lib/ocf/resource.d/rabbitmq/rabbitmq-server + install -p -D -m 0755 scripts/rabbitmq-server-ha.ocf \ + $(DEB_DESTDIR)$(PREFIX)/lib/ocf/resource.d/rabbitmq/rabbitmq-server-ha + + rm $(DEB_DESTDIR)$(RMQ_ERLAPP_DIR)/LICENSE* \ + $(DEB_DESTDIR)$(RMQ_ERLAPP_DIR)/INSTALL + + rmdir $(DEB_DESTDIR)$(PREFIX)/lib/erlang/lib \ + $(DEB_DESTDIR)$(PREFIX)/lib/erlang diff --git a/packaging/debs/Debian/debian/source/format b/packaging/debs/Debian/debian/source/format new file mode 100644 index 0000000000..163aaf8d82 --- /dev/null +++ b/packaging/debs/Debian/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/packaging/debs/apt-repository/Makefile b/packaging/debs/apt-repository/Makefile index ce4347bcb4..bbddc15a4e 100644 --- a/packaging/debs/apt-repository/Makefile +++ b/packaging/debs/apt-repository/Makefile @@ -1,27 +1,30 @@ -SIGNING_USER_EMAIL=info@rabbitmq.com +PACKAGES_DIR ?= ../../../PACKAGES +REPO_DIR ?= debian + +SIGNING_USER_EMAIL ?= info@rabbitmq.com ifeq "$(UNOFFICIAL_RELEASE)" "" -HOME_ARG=HOME=$(GNUPG_PATH) +HOME_ARG = HOME=$(GNUPG_PATH) endif all: debian_apt_repository clean: - rm -rf debian + rm -rf $(REPO_DIR) CAN_HAS_REPREPRO=$(shell [ -f /usr/bin/reprepro ] && echo true) ifeq ($(CAN_HAS_REPREPRO), true) debian_apt_repository: clean - mkdir -p debian/conf - cp -a distributions debian/conf + mkdir -p $(REPO_DIR)/conf + cp -a distributions $(REPO_DIR)/conf ifeq "$(UNOFFICIAL_RELEASE)" "" - echo SignWith: $(SIGNING_USER_EMAIL) >> debian/conf/distributions + echo SignWith: $(SIGNING_USER_EMAIL) >> $(REPO_DIR)/conf/distributions endif - for FILE in ../Debian/*.changes ; do \ + for FILE in $(PACKAGES_DIR)/*.changes ; do \ $(HOME_ARG) reprepro --ignore=wrongdistribution \ - -Vb debian include kitten $${FILE} ; \ + -Vb $(REPO_DIR) include kitten $${FILE} ; \ done - reprepro -Vb debian createsymlinks + reprepro -Vb $(REPO_DIR) createsymlinks else debian_apt_repository: @echo Not building APT repository as reprepro could not be found diff --git a/packaging/generic-unix/Makefile b/packaging/generic-unix/Makefile index ddad8c09fa..fb8b3a9e68 100644 --- a/packaging/generic-unix/Makefile +++ b/packaging/generic-unix/Makefile @@ -1,17 +1,37 @@ -VERSION=0.0.0 -SOURCE_DIR=rabbitmq-server-$(VERSION) -TARGET_DIR=rabbitmq_server-$(VERSION) -TARGET_TARBALL=rabbitmq-server-generic-unix-$(VERSION) +SOURCE_DIST_FILE ?= $(wildcard ../../../rabbitmq-server-*.tar.xz) + +ifneq ($(filter-out clean,$(MAKECMDGOALS)),) +ifeq ($(SOURCE_DIST_FILE),) +$(error Cannot find source archive; please specify SOURCE_DIST_FILE) +endif +ifneq ($(words $(SOURCE_DIST_FILE)),1) +$(error Multile source archives found; please specify SOURCE_DIST_FILE) +endif + +VERSION ?= $(patsubst rabbitmq-server-%.tar.xz,%,$(notdir $(SOURCE_DIST_FILE))) +ifeq ($(VERSION),) +$(error Cannot determine version; please specify VERSION) +endif +endif + +SOURCE_DIR = rabbitmq-server-$(VERSION) +TARGET_DIR = rabbitmq_server-$(VERSION) +TARGET_TARBALL = rabbitmq-server-generic-unix-$(VERSION) + +unexport DEPS_DIR +unexport ERL_LIBS + +all: dist + @: dist: - tar -zxf ../../dist/$(SOURCE_DIR).tar.gz + tar -Jxf $(SOURCE_DIST_FILE) $(MAKE) -C $(SOURCE_DIR) \ - TARGET_DIR=`pwd`/$(TARGET_DIR) \ - SBIN_DIR=`pwd`/$(TARGET_DIR)/sbin \ - MAN_DIR=`pwd`/$(TARGET_DIR)/share/man \ - DOC_INSTALL_DIR=`pwd`/$(TARGET_DIR)/etc/rabbitmq \ - install + PREFIX= RMQ_ROOTDIR= \ + RMQ_ERLAPP_DIR=`pwd`/$(TARGET_DIR) \ + MANDIR=`pwd`/$(TARGET_DIR)/share/man \ + manpages install install-man sed -e 's:^SYS_PREFIX=$$:SYS_PREFIX=\$${RABBITMQ_HOME}:' \ $(TARGET_DIR)/sbin/rabbitmq-defaults >$(TARGET_DIR)/sbin/rabbitmq-defaults.tmp \ @@ -21,11 +41,14 @@ dist: mkdir -p $(TARGET_DIR)/etc/rabbitmq tar -zcf $(TARGET_TARBALL).tar.gz $(TARGET_DIR) - rm -rf $(SOURCE_DIR) $(TARGET_DIR) + + if test "$(PACKAGES_DIR)"; then \ + mkdir -p "$(PACKAGES_DIR)"; \ + mv $(TARGET_TARBALL).tar.gz "$(PACKAGES_DIR)"; \ + fi clean: clean_partial rm -f rabbitmq-server-generic-unix-*.tar.gz clean_partial: - rm -rf $(SOURCE_DIR) - rm -rf $(TARGET_DIR) + rm -rf rabbitmq-server-* rabbitmq_server-* diff --git a/packaging/standalone/Makefile b/packaging/standalone/Makefile index 903458836c..578ed57345 100644 --- a/packaging/standalone/Makefile +++ b/packaging/standalone/Makefile @@ -1,4 +1,19 @@ -VERSION=0.0.0 +SOURCE_DIST_FILE ?= $(wildcard ../../rabbitmq-server-*.tar.xz) + +ifneq ($(filter-out clean,$(MAKECMDGOALS)),) +ifeq ($(SOURCE_DIST_FILE),) +$(error Cannot find source archive; please specify SOURCE_DIST_FILE) +endif +ifneq ($(words $(SOURCE_DIST_FILE)),1) +$(error Multile source archives found; please specify SOURCE_DIST_FILE) +endif + +VERSION ?= $(patsubst rabbitmq-server-%.tar.xz,%,$(notdir $(SOURCE_DIST_FILE))) +ifeq ($(VERSION),) +$(error Cannot determine version; please specify VERSION) +endif +endif + SOURCE_DIR=rabbitmq-server-$(VERSION) TARGET_DIR=rabbitmq_server-$(VERSION) TARGET_TARBALL=rabbitmq-server-$(OS)-standalone-$(VERSION) @@ -18,15 +33,24 @@ RABBITMQ_DEFAULTS=$(TARGET_DIR)/sbin/rabbitmq-defaults fix_defaults = sed -e $(1) $(RABBITMQ_DEFAULTS) > $(RABBITMQ_DEFAULTS).tmp \ && mv $(RABBITMQ_DEFAULTS).tmp $(RABBITMQ_DEFAULTS) +unexport DEPS_DIR +unexport ERL_LIBS + +all: dist + @: + dist: - tar -zxf ../../dist/$(SOURCE_DIR).tar.gz + rm -rf $(SOURCE_DIR) $(TARGET_DIR) + xzcat $(SOURCE_DIST_FILE) | tar -xf - $(MAKE) -C $(SOURCE_DIR) \ - TARGET_DIR=`pwd`/$(TARGET_DIR) \ - SBIN_DIR=`pwd`/$(TARGET_DIR)/sbin \ - MAN_DIR=`pwd`/$(TARGET_DIR)/share/man \ - DOC_INSTALL_DIR=`pwd`/$(TARGET_DIR)/etc/rabbitmq \ - install + PREFIX= RMQ_ROOTDIR= \ + RMQ_ERLAPP_DIR=$(abspath $(TARGET_DIR)) \ + MANDIR=$(abspath $(TARGET_DIR))/share/man \ + manpages install install-man + + mkdir -p $(TARGET_DIR)/etc/rabbitmq + cp $(SOURCE_DIR)/docs/rabbitmq.config.example $(TARGET_DIR)/etc/rabbitmq ## Here we set the RABBITMQ_HOME variable, ## then we make ERL_DIR point to our released erl @@ -66,16 +90,19 @@ dist: # fix Erlang ROOTDIR patch -o $(RLS_DIR)/erts-$(ERTS_VSN)/bin/erl $(RLS_DIR)/erts-$(ERTS_VSN)/bin/erl.src < erl.diff + rm -f $(RLS_DIR)/erts-$(ERTS_VSN)/bin/erl.orig - tar -zcf $(TARGET_TARBALL).tar.gz -C $(TARGET_DIR)/release $(TARGET_DIR) - rm -rf $(SOURCE_DIR) $(TARGET_DIR) + cd $(TARGET_DIR)/release && \ + find $(TARGET_DIR) -print0 | LC_COLLATE=C sort -z | \ + xargs -0 tar -cnf - | xz > $(CURDIR)/$(TARGET_TARBALL).tar.xz -clean: clean_partial - rm -f rabbitmq-server-$(OS)-standalone-*.tar.gz + if test "$(PACKAGES_DIR)"; then \ + mkdir -p "$(PACKAGES_DIR)"; \ + mv $(TARGET_TARBALL).tar.xz "$(PACKAGES_DIR)"; \ + fi -clean_partial: - rm -rf $(SOURCE_DIR) - rm -rf $(TARGET_DIR) +clean: + rm -rf rabbitmq-server-* rabbitmq_server-* .PHONY : generate_release generate_release: @@ -83,6 +110,7 @@ generate_release: -I $(TARGET_DIR)/include/ -o src -Wall \ -v +debug_info -Duse_specs -Duse_proper_qc \ -pa $(TARGET_DIR)/ebin/ src/rabbit_release.erl + ERL_LIBS="$(TARGET_DIR)/plugins:$$ERL_LIBS" \ erl \ -pa "$(RABBITMQ_EBIN_ROOT)" \ -pa src \ @@ -90,4 +118,5 @@ generate_release: -hidden \ -s rabbit_release \ -extra "$(RABBITMQ_PLUGINS_DIR)" "$(RABBITMQ_PLUGINS_EXPAND_DIR)" "$(RABBITMQ_HOME)" + test -f $(RABBITMQ_HOME)/rabbit.tar.gz rm src/rabbit_release.beam diff --git a/packaging/standalone/src/rabbit_release.erl b/packaging/standalone/src/rabbit_release.erl index f5e1ecf8a1..4e16fd52b5 100644 --- a/packaging/standalone/src/rabbit_release.erl +++ b/packaging/standalone/src/rabbit_release.erl @@ -40,8 +40,8 @@ start() -> %% add the plugin ebin folder to the code path. add_plugins_to_path(UnpackedPluginDir), - PluginAppNames = [P#plugin.name || - P <- rabbit_plugins:list(PluginsDistDir)], + PluginAppNames = [rabbit_common | [P#plugin.name || + P <- rabbit_plugins:list(PluginsDistDir)]], %% Build the entire set of dependencies - this will load the %% applications along the way @@ -56,7 +56,9 @@ start() -> %% we need a list of ERTS apps we need to ship with rabbit {ok, SslAppsConfig} = application:get_env(rabbit, ssl_apps), - BaseApps = SslAppsConfig ++ AllApps -- PluginAppNames, + BaseApps = lists:umerge( + lists:sort(SslAppsConfig), + lists:sort(AllApps -- PluginAppNames)), AppVersions = [determine_version(App) || App <- BaseApps], RabbitVersion = proplists:get_value(rabbit, AppVersions), diff --git a/packaging/windows-exe/Makefile b/packaging/windows-exe/Makefile index ab50e30b1d..26ef4585c3 100644 --- a/packaging/windows-exe/Makefile +++ b/packaging/windows-exe/Makefile @@ -1,16 +1,33 @@ -VERSION=0.0.0 -ZIP=../windows/rabbitmq-server-windows-$(VERSION) +ifeq ($(PACKAGES_DIR),) +ZIP_DIR = ../windows +else +ZIP_DIR = $(PACKAGES_DIR) +endif +ZIP = $(notdir $(wildcard $(ZIP_DIR)/rabbitmq-server-windows-*.zip)) + +VERSION = $(patsubst rabbitmq-server-windows-%.zip,%,$(ZIP)) + +unexport DEPS_DIR +unexport ERL_LIBS + +all: dist + @: dist: rabbitmq-$(VERSION).nsi rabbitmq_server-$(VERSION) makensis -V2 rabbitmq-$(VERSION).nsi + if test "$(PACKAGES_DIR)"; then \ + mkdir -p "$(PACKAGES_DIR)"; \ + mv rabbitmq-server-$(VERSION).exe "$(PACKAGES_DIR)"; \ + fi + rabbitmq-$(VERSION).nsi: rabbitmq_nsi.in sed \ -e 's|%%VERSION%%|$(VERSION)|' \ $< > $@ rabbitmq_server-$(VERSION): - unzip -q $(ZIP) + unzip -q $(ZIP_DIR)/$(ZIP) clean: rm -rf rabbitmq-*.nsi rabbitmq_server-* rabbitmq-server-*.exe diff --git a/packaging/windows-exe/rabbitmq_nsi.in b/packaging/windows-exe/rabbitmq_nsi.in index 153ff0ef93..7ad711ba38 100644 --- a/packaging/windows-exe/rabbitmq_nsi.in +++ b/packaging/windows-exe/rabbitmq_nsi.in @@ -31,16 +31,6 @@ RequestExecutionLevel admin SetCompressor /solid lzma -VIProductVersion "%%VERSION%%.0" -VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "%%VERSION%%" -VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "RabbitMQ Server" -;VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "" -VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "Pivotal Software, Inc" -;VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" "" ; TODO ? -VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved." -VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "RabbitMQ Server" -VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "%%VERSION%%" - ;-------------------------------- ; Pages @@ -64,6 +54,16 @@ VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "%%VERSION%%" ;-------------------------------- +VIProductVersion "%%VERSION%%.0" +VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "%%VERSION%%" +VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "RabbitMQ Server" +;VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "" +VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "Pivotal Software, Inc" +;VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" "" ; TODO ? +VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved." +VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "RabbitMQ Server" +VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "%%VERSION%%" + ; The stuff to install Section "RabbitMQ Server (required)" Rabbit diff --git a/packaging/windows/Makefile b/packaging/windows/Makefile index 5dc802a8c2..beda5752be 100644 --- a/packaging/windows/Makefile +++ b/packaging/windows/Makefile @@ -1,43 +1,43 @@ -VERSION=0.0.0 -SOURCE_DIR=rabbitmq-server-$(VERSION) -TARGET_DIR=rabbitmq_server-$(VERSION) -TARGET_ZIP=rabbitmq-server-windows-$(VERSION) +SOURCE_DIST_FILE ?= $(wildcard ../../../rabbitmq-server-*.tar.xz) + +ifneq ($(filter-out clean,$(MAKECMDGOALS)),) +ifeq ($(SOURCE_DIST_FILE),) +$(error Cannot find source archive; please specify SOURCE_DIST_FILE) +endif +ifneq ($(words $(SOURCE_DIST_FILE)),1) +$(error Multile source archives found; please specify SOURCE_DIST_FILE) +endif + +VERSION ?= $(patsubst rabbitmq-server-%.tar.xz,%,$(notdir $(SOURCE_DIST_FILE))) +ifeq ($(VERSION),) +$(error Cannot determine version; please specify VERSION) +endif +endif + +SOURCE_DIR = rabbitmq-server-$(VERSION) +TARGET_DIR = rabbitmq_server-$(VERSION) +TARGET_ZIP = rabbitmq-server-windows-$(VERSION) + +unexport DEPS_DIR +unexport ERL_LIBS + +all: dist + @: dist: - tar -zxf ../../dist/$(SOURCE_DIR).tar.gz - $(MAKE) -C $(SOURCE_DIR) - - mkdir -p $(SOURCE_DIR)/sbin - mv $(SOURCE_DIR)/scripts/*.bat $(SOURCE_DIR)/sbin - mkdir -p $(SOURCE_DIR)/etc - cp $(SOURCE_DIR)/docs/rabbitmq.config.example $(SOURCE_DIR)/etc/rabbitmq.config.example - cp README-etc $(SOURCE_DIR)/etc/README.txt - rm -rf $(SOURCE_DIR)/scripts - rm -rf $(SOURCE_DIR)/codegen* $(SOURCE_DIR)/Makefile $(SOURCE_DIR)/*mk - rm -f $(SOURCE_DIR)/README - rm -rf $(SOURCE_DIR)/docs - rm -rf $(SOURCE_DIR)/src - rm -rf $(SOURCE_DIR)/dist - - mv $(SOURCE_DIR) $(TARGET_DIR) - mkdir -p $(TARGET_DIR) - mv $(TARGET_DIR)/plugins/README $(TARGET_DIR)/plugins/README.txt - xmlto -o . xhtml-nochunks ../../docs/rabbitmq-service.xml - elinks -dump -no-references -no-numbering rabbitmq-service.html \ - > $(TARGET_DIR)/readme-service.txt - todos $(TARGET_DIR)/readme-service.txt - todos $(TARGET_DIR)/INSTALL - todos $(TARGET_DIR)/LICENSE* - todos $(TARGET_DIR)/plugins/README.txt - todos $(TARGET_DIR)/etc/rabbitmq.config.example - todos $(TARGET_DIR)/etc/README.txt - rm -rf $(TARGET_DIR)/plugins-src + tar -Jxf $(SOURCE_DIST_FILE) + $(MAKE) -C $(SOURCE_DIR) install-windows \ + DESTDIR=$(abspath $(TARGET_DIR)) \ + WINDOWS_PREFIX= + + cp -a README-etc $(TARGET_DIR)/etc/README.txt + zip -q -r $(TARGET_ZIP).zip $(TARGET_DIR) - rm -rf $(TARGET_DIR) rabbitmq-service.html -clean: clean_partial - rm -f rabbitmq-server-windows-*.zip + if test "$(PACKAGES_DIR)"; then \ + mkdir -p "$(PACKAGES_DIR)"; \ + mv $(TARGET_ZIP).zip "$(PACKAGES_DIR)"; \ + fi -clean_partial: - rm -rf $(SOURCE_DIR) - rm -rf $(TARGET_DIR) +clean: + rm -rf rabbitmq-server-* rabbitmq_server-* diff --git a/packaging/windows/README-etc b/packaging/windows/README-etc index 807698e81f..b431247c6b 100644 --- a/packaging/windows/README-etc +++ b/packaging/windows/README-etc @@ -1,7 +1,7 @@ -In this directory you can find an example configuration file for RabbitMQ. - -Note that this directory is *not* where the real RabbitMQ -configuration lives. The default location for the real configuration -file is %APPDATA%\RabbitMQ\rabbitmq.config. - -%APPDATA% usually expands to C:\Users\%USERNAME%\AppData\Roaming or similar. +In this directory you can find an example configuration file for RabbitMQ.
+
+Note that this directory is *not* where the real RabbitMQ
+configuration lives. The default location for the real configuration
+file is %APPDATA%\RabbitMQ\rabbitmq.config.
+
+%APPDATA% usually expands to C:\Users\%USERNAME%\AppData\Roaming or similar.
|
