diff options
| author | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-10-10 09:51:56 +0100 |
|---|---|---|
| committer | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-10-10 09:51:56 +0100 |
| commit | fe15c3ac5d5186506702c46b0f0cb2e8dcbb2530 (patch) | |
| tree | bbbfe073cb6cf492c4faa654ce21d71f57dfefe0 | |
| parent | f88351e1078750fcfc5f8b8a66bda5a3b1aece12 (diff) | |
| parent | 6c358592c74a2da74a84920a4eec57f8b99a162a (diff) | |
| download | rabbitmq-server-git-fe15c3ac5d5186506702c46b0f0cb2e8dcbb2530.tar.gz | |
merge default into bug21319
| -rw-r--r-- | Makefile | 50 | ||||
| -rw-r--r-- | docs/rabbitmq-plugins.1.xml | 174 | ||||
| -rw-r--r-- | include/rabbit.hrl | 7 | ||||
| -rw-r--r-- | packaging/RPMS/Fedora/rabbitmq-server.spec | 3 | ||||
| -rw-r--r-- | packaging/common/LICENSE | 14 | ||||
| -rw-r--r-- | packaging/common/rabbitmq-script-wrapper | 6 | ||||
| -rwxr-xr-x | packaging/debs/Debian/debian/copyright | 62 | ||||
| -rw-r--r-- | packaging/debs/Debian/debian/rules | 2 | ||||
| -rw-r--r-- | packaging/macports/Portfile.in | 20 | ||||
| -rw-r--r-- | packaging/windows/Makefile | 9 | ||||
| -rwxr-xr-x | scripts/rabbitmq-plugins | 34 | ||||
| -rwxr-xr-x | scripts/rabbitmq-plugins.bat | 51 | ||||
| -rwxr-xr-x | scripts/rabbitmq-server | 4 | ||||
| -rwxr-xr-x[-rw-r--r--] | scripts/rabbitmq-server.bat | 7 | ||||
| -rwxr-xr-x[-rw-r--r--] | scripts/rabbitmq-service.bat | 7 | ||||
| -rw-r--r-- | src/rabbit_control.erl | 19 | ||||
| -rw-r--r-- | src/rabbit_misc.erl | 9 | ||||
| -rw-r--r-- | src/rabbit_plugins.erl | 348 | ||||
| -rw-r--r-- | src/rabbit_prelaunch.erl | 37 |
19 files changed, 813 insertions, 50 deletions
@@ -14,11 +14,11 @@ DOCS_DIR=docs INCLUDES=$(wildcard $(INCLUDE_DIR)/*.hrl) $(INCLUDE_DIR)/rabbit_framing.hrl SOURCES=$(wildcard $(SOURCE_DIR)/*.erl) $(SOURCE_DIR)/rabbit_framing_amqp_0_9_1.erl $(SOURCE_DIR)/rabbit_framing_amqp_0_8.erl $(USAGES_ERL) BEAM_TARGETS=$(patsubst $(SOURCE_DIR)/%.erl, $(EBIN_DIR)/%.beam, $(SOURCES)) -TARGETS=$(EBIN_DIR)/rabbit.app $(INCLUDE_DIR)/rabbit_framing.hrl $(BEAM_TARGETS) +TARGETS=$(EBIN_DIR)/rabbit.app $(INCLUDE_DIR)/rabbit_framing.hrl $(BEAM_TARGETS) plugins WEB_URL=http://www.rabbitmq.com/ MANPAGES=$(patsubst %.xml, %.gz, $(wildcard $(DOCS_DIR)/*.[0-9].xml)) WEB_MANPAGES=$(patsubst %.xml, %.man.xml, $(wildcard $(DOCS_DIR)/*.[0-9].xml) $(DOCS_DIR)/rabbitmq-service.xml) -USAGES_XML=$(DOCS_DIR)/rabbitmqctl.1.xml +USAGES_XML=$(DOCS_DIR)/rabbitmqctl.1.xml $(DOCS_DIR)/rabbitmq-plugins.1.xml USAGES_ERL=$(foreach XML, $(USAGES_XML), $(call usage_xml_to_erl, $(XML))) QC_MODULES := rabbit_backing_queue_qc QC_TRIALS ?= 100 @@ -57,6 +57,8 @@ endif ERLC_OPTS=-I $(INCLUDE_DIR) -o $(EBIN_DIR) -Wall -v +debug_info $(call boolean_macro,$(USE_SPECS),use_specs) $(call boolean_macro,$(USE_PROPER_QC),use_proper_qc) VERSION=0.0.0 +PLUGINS_SRC_DIR?=$(shell [ -d "plugins-src" ] && echo "plugins-src" || echo ) +PLUGINS_DIR=plugins TARBALL_NAME=rabbitmq-server-$(VERSION) TARGET_SRC_DIR=dist/$(TARBALL_NAME) @@ -101,6 +103,29 @@ endif all: $(TARGETS) +.PHONY: plugins +ifneq "$(PLUGINS_SRC_DIR)" "" +plugins: + [ -d "$(PLUGINS_SRC_DIR)/rabbitmq-server" ] || ln -s "$(CURDIR)" "$(PLUGINS_SRC_DIR)/rabbitmq-server" + mkdir -p $(PLUGINS_DIR) + PLUGINS_SRC_DIR="" $(MAKE) -C "$(PLUGINS_SRC_DIR)" plugins-dist PLUGINS_DIST_DIR="$(CURDIR)/$(PLUGINS_DIR)" VERSION=$(VERSION) + echo "Put your EZs here and use rabbitmq-plugins to enable them." > $(PLUGINS_DIR)/README + rm -f $(PLUGINS_DIR)/rabbit_common*.ez + +# If you add a license here, make sure to also add it to packaging/common/LICENSE. +PLUGINS_SRC_LICENSES := "plugins-src/rabbitmq-management/LICENSE-MIT-jQuery142" \ + "plugins-src/rabbitmq-management/LICENSE-MIT-EJS10" \ + "plugins-src/rabbitmq-management/LICENSE-MIT-Sammy060" \ + "plugins-src/webmachine-wrapper/LICENSE-Apache-Basho" \ + "plugins-src/mochiweb-wrapper/LICENSE-MIT-Mochi" \ + "plugins-src/rabbitmq-management-visualiser/LICENSE-BSD-glMatrix" \ + "plugins-src/eldap-wrapper/LICENSE-MIT-eldap" +else +plugins: +# Not building plugins +PLUGINS_SRC_LICENSES := +endif + $(DEPS_FILE): $(SOURCES) $(INCLUDES) rm -f $@ echo $(subst : ,:,$(foreach FILE,$^,$(FILE):)) | escript generate_deps $@ $(EBIN_DIR) @@ -143,6 +168,8 @@ $(BASIC_PLT): $(BEAM_TARGETS) clean: rm -f $(EBIN_DIR)/*.beam rm -f $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script $(EBIN_DIR)/rabbit.rel + rm -f $(PLUGINS_DIR)/*.ez + [ -d "$(PLUGINS_SRC_DIR)" ] && PLUGINS_SRC_DIR="" PRESERVE_CLONE_DIR=1 make -C $(PLUGINS_SRC_DIR) clean || true rm -f $(INCLUDE_DIR)/rabbit_framing.hrl $(SOURCE_DIR)/rabbit_framing_amqp_*.erl codegen.pyc rm -f $(DOCS_DIR)/*.[0-9].gz $(DOCS_DIR)/*.man.xml $(DOCS_DIR)/*.erl $(USAGES_ERL) rm -f $(RABBIT_PLT) @@ -244,7 +271,15 @@ srcdist: distclean cp -r $(DOCS_DIR) $(TARGET_SRC_DIR) chmod 0755 $(TARGET_SRC_DIR)/scripts/* - (cd dist; tar -zcf $(TARBALL_NAME).tar.gz $(TARBALL_NAME)) +ifneq "$(PLUGINS_SRC_DIR)" "" + ln -s $(PLUGINS_SRC_DIR) $(TARGET_SRC_DIR)/plugins-src + cp packaging/common/LICENSE $(TARGET_SRC_DIR) + cp $(PLUGINS_SRC_LICENSES) $(TARGET_SRC_DIR) +else + @echo No plugins source distribution found +endif + + (cd dist; tar -zchf $(TARBALL_NAME).tar.gz $(TARBALL_NAME)) (cd dist; zip -q -r $(TARBALL_NAME).zip $(TARBALL_NAME)) rm -rf $(TARGET_SRC_DIR) @@ -288,15 +323,16 @@ docs_all: $(MANPAGES) $(WEB_MANPAGES) install: install_bin install_docs install_bin: all install_dirs - cp -r ebin include LICENSE LICENSE-MPL-RabbitMQ INSTALL $(TARGET_DIR) + cp -r ebin include LICENSE* INSTALL $(TARGET_DIR) chmod 0755 scripts/* - for script in rabbitmq-env rabbitmq-server rabbitmqctl; do \ + for script in rabbitmq-env rabbitmq-server rabbitmqctl rabbitmq-plugins; do \ cp scripts/$$script $(TARGET_DIR)/sbin; \ [ -e $(SBIN_DIR)/$$script ] || ln -s $(SCRIPTS_REL_PATH)/$$script $(SBIN_DIR)/$$script; \ done - mkdir -p $(TARGET_DIR)/plugins - echo Put your .ez plugin files in this directory. > $(TARGET_DIR)/plugins/README + + mkdir -p $(TARGET_DIR)/$(PLUGINS_DIR) + [ -d "$(PLUGINS_DIR)" ] && cp $(PLUGINS_DIR)/*.ez $(PLUGINS_DIR)/README $(TARGET_DIR)/$(PLUGINS_DIR) || true install_docs: docs_all install_dirs for section in 1 5; do \ diff --git a/docs/rabbitmq-plugins.1.xml b/docs/rabbitmq-plugins.1.xml new file mode 100644 index 0000000000..35f74c2823 --- /dev/null +++ b/docs/rabbitmq-plugins.1.xml @@ -0,0 +1,174 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd"> +<!-- + There is some extra magic in this document besides the usual DocBook semantics + to allow us to derive manpages, HTML and usage messages from the same source + document. + + Examples need to be moved to the end for man pages. To this end, <para>s and + <screen>s with role="example" will be moved, and with role="example-prefix" + will be removed. + + The usage messages are more involved. We have some magic in usage.xsl to pull + out the command synopsis, global option and subcommand synopses. We also pull + out <para>s with role="usage". + + Finally we construct lists of possible values for subcommand options, if the + subcommand's <varlistentry> has role="usage-has-option-list". The option which + takes the values should be marked with role="usage-option-list". +--> + +<refentry lang="en"> + <refentryinfo> + <productname>RabbitMQ Server</productname> + <authorgroup> + <corpauthor>The RabbitMQ Team <<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>></corpauthor> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>rabbitmq-plugins</refentrytitle> + <manvolnum>1</manvolnum> + <refmiscinfo class="manual">RabbitMQ Service</refmiscinfo> + </refmeta> + + <refnamediv> + <refname>rabbitmq-plugins</refname> + <refpurpose>command line tool for managing RabbitMQ broker plugins</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <cmdsynopsis> + <command>rabbitmq-plugins</command> + <arg choice="req"><replaceable>command</replaceable></arg> + <arg choice="opt" rep="repeat"><replaceable>command options</replaceable></arg> + </cmdsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + <para> + <command>rabbitmq-plugins</command> is a command line tool for managing + RabbitMQ broker plugins. It allows one to enable, disable and browse + plugins. It must be run by a user with write permissions to the RabbitMQ + configuration directory. + </para> + <para> + Some plugins depend on others to work + correctly. <command>rabbitmq-plugins</command> traverses these + dependencies and enables all required plugins. Plugins listed on + the <command>rabbitmq-plugins</command> command line are marked as + explicitly enabled; dependent plugins are marked as implicitly + enabled. Implicitly enabled plugins are automatically disabled again + when they are no longer required. + </para> + </refsect1> + + <refsect1> + <title>Commands</title> + + <variablelist> + <varlistentry> + <term><cmdsynopsis><command>list</command> <arg choice="opt">-v</arg> <arg choice="opt">-E</arg> <arg choice="opt">-e</arg> <arg choice="opt"><replaceable>pattern</replaceable></arg></cmdsynopsis></term> + <listitem> + <variablelist> + <varlistentry> + <term>-v</term> + <listitem><para>Show all plugin details.</para></listitem> + </varlistentry> + <varlistentry> + <term>-E</term> + <listitem><para>Show only explicitly enabled + plugins.</para></listitem> + </varlistentry> + <varlistentry> + <term>-e</term> + <listitem><para>Show only explicitly or implicitly + enabled plugins.</para></listitem> + </varlistentry> + <varlistentry> + <term>pattern</term> + <listitem><para>Pattern to filter the plugin names by.</para></listitem> + </varlistentry> + </variablelist> + <para> + Lists available plugins, their versions, dependencies + and descriptions. + </para> + <para> + If the optional pattern is given, only plugins whose + name mathes <command>pattern</command> are shown. + </para> + <para role="example-prefix">For example:</para> + <screen role="example">rabbitmq-plugins list</screen> + <para role="example"> + This command lists all the plugins available, on one line each. + </para> + <screen role="example">rabbitmq-plugins list -v </screen> + <para role="example"> + This command lists all the plugins available. + </para> + <screen role="example">rabbitmq-plugins list -v management</screen> + <para role="example"> + This command lists all the plugins available, but does not + display plugins whose name does not contain "management". + </para> + <screen role="example">rabbitmq-plugins list -e rabbit</screen> + <para role="example"> + This command lists all implicitly or explicitly enabled + rabbit plugins. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><cmdsynopsis><command>enable</command> <arg choice="req"><replaceable>plugin</replaceable> ...</arg></cmdsynopsis></term> + <listitem> + <variablelist> + <varlistentry> + <term>plugin</term> + <listitem><para>One or more plugins to enable.</para></listitem> + </varlistentry> + </variablelist> + <para> + Enables the specified plugins and all their + dependencies. + </para> + + <para role="example-prefix">For example:</para> + <screen role="example">rabbitmq-plugins enable rabbitmq_shovel rabbitmq_management</screen> + <para role="example"> + This command enables the <command>shovel</command> and + <command>management</command> plugins and all their + dependencies. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><cmdsynopsis><command>disable</command> <arg choice="req"><replaceable>plugin</replaceable> ...</arg></cmdsynopsis></term> + <listitem> + <variablelist> + <varlistentry> + <term>plugin</term> + <listitem><para>One or more plugins to disable.</para></listitem> + </varlistentry> + </variablelist> + <para> + Disables the specified plugins and all plugins that + depend on them. + </para> + + <para role="example-prefix">For example:</para> + <screen role="example">rabbitmq-plugins disable amqp_client</screen> + <para role="example"> + This command disables <command>amqp_client</command> and + all plugins that depend on it. + </para> + </listitem> + </varlistentry> + </variablelist> + + </refsect1> + +</refentry> diff --git a/include/rabbit.hrl b/include/rabbit.hrl index ac6399c64e..a603886c4b 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -75,6 +75,13 @@ -record(message_properties, {expiry, needs_confirming = false}). +-record(plugin, {name, %% atom() + version, %% string() + description, %% string() + type, %% 'ez' or 'dir' + dependencies, %% [{atom(), string()}] + location}). %% string() + %%---------------------------------------------------------------------------- -define(COPYRIGHT_MESSAGE, "Copyright (C) 2007-2011 VMware, Inc."). diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index 0c5aa96a1f..fb27e9bdf0 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -55,6 +55,7 @@ mkdir -p %{buildroot}%{_localstatedir}/log/rabbitmq 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 0644 %{S:3} %{buildroot}%{_sysconfdir}/logrotate.d/rabbitmq-server @@ -114,7 +115,7 @@ done %dir %{_sysconfdir}/rabbitmq %{_initrddir}/rabbitmq-server %config(noreplace) %{_sysconfdir}/logrotate.d/rabbitmq-server -%doc LICENSE LICENSE-MPL-RabbitMQ +%doc LICENSE* %clean rm -rf %{buildroot} diff --git a/packaging/common/LICENSE b/packaging/common/LICENSE new file mode 100644 index 0000000000..f8039d6a01 --- /dev/null +++ b/packaging/common/LICENSE @@ -0,0 +1,14 @@ +This package, the RabbitMQ server is licensed under the MPL. For the +MPL, please see LICENSE-MPL-RabbitMQ. + +This package makes use of the following third party libraries: +jQuery - http://jquery.com/ - MIT license, see LICENSE-MIT-jQuery142 +EJS - http://embeddedjs.com/ - MIT license, see LICENSE-MIT-EJS10 +Sammy - http://code.quirkey.com/sammy/ - MIT license, see LICENSE-MIT-Sammy060 +webmachine - http://webmachine.basho.com/ - Apache license, 2.0, LICENSE-Apache-Basho +mochiweb - http://github.com/mochi/mochiweb/ - MIT license, see LICENSE-MIT-Mochi +glMatrix - http://code.google.com/p/glmatrix/ - BSD 2-clause license, see LICENSE-BSD-glMatrix +eldap - https://github.com/etnt/eldap - MIT license, see LICENSE-MIT-eldap + +If you have any questions regarding licensing, please contact us at +info@rabbitmq.com. diff --git a/packaging/common/rabbitmq-script-wrapper b/packaging/common/rabbitmq-script-wrapper index 23d2a06cbd..0436f54609 100644 --- a/packaging/common/rabbitmq-script-wrapper +++ b/packaging/common/rabbitmq-script-wrapper @@ -29,10 +29,10 @@ cd /var/lib/rabbitmq SCRIPT=`basename $0` -if [ `id -u` = 0 ] ; then - @SU_RABBITMQ_SH_C@ "/usr/lib/rabbitmq/bin/${SCRIPT} ${CMDLINE}" -elif [ `id -u` = `id -u rabbitmq` ] ; then +if [ `id -u` = `id -u rabbitmq` -o "$SCRIPT" = "rabbitmq-plugins" ] ; then /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 diff --git a/packaging/debs/Debian/debian/copyright b/packaging/debs/Debian/debian/copyright index 7206bb9b93..aa70e7e39e 100755 --- a/packaging/debs/Debian/debian/copyright +++ b/packaging/debs/Debian/debian/copyright @@ -4,11 +4,29 @@ Wed, 3 Jan 2007 15:43:44 +0000. It was downloaded from http://www.rabbitmq.com/ The files codegen/amqp-rabbitmq-0.8.json and -codegen/amqp-rabbitmq-0.9.1.json are covered by the following terms: +codegen/amqp-rabbitmq-0.9.1.json are "Copyright (C) 2008-2011 VMware", +Inc. and are covered by the MIT license. - "Copyright (C) 2008-2011 VMware, Inc. +jQuery is "Copyright (c) 2010 John Resig" and is covered by the MIT +license. It was downloaded from http://jquery.com/ - Permission is hereby granted, free of charge, to any person +EJS is "Copyright (c) 2007 Edward Benson" and is covered by the MIT +license. It was downloaded from http://embeddedjs.com/ + +Sammy is "Copyright (c) 2008 Aaron Quint, Quirkey NYC, LLC" and is +covered by the MIT license. It was downloaded from +http://code.quirkey.com/sammy/ + +Eldap is "Copyright (c) 2010, Torbjorn Tornkvist" and is covered by +the MIT license. It was downloaded from https://github.com/etnt/eldap + +Mochiweb is "Copyright (c) 2007 Mochi Media, Inc." and is covered by +the MIT license. It was downloaded from +http://github.com/mochi/mochiweb/ + +The MIT license is as follows: + + "Permission is hereby granted, free of charge, to any person obtaining a copy of this file (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, @@ -28,6 +46,44 @@ codegen/amqp-rabbitmq-0.9.1.json are covered by the following terms: FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE." + +Webmachine is Copyright (c) Basho Technologies and is covered by the +Apache License 2.0. It was downloaded from http://webmachine.basho.com/ + +glMatrix was downloaded from http://code.google.com/p/glmatrix/ and is +covered by the following license: + + "Copyright (c) 2011, Brandon Jones + All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, are permitted provided that the + following conditions are met: + + 1. Redistributions of source code must retain the above + copyright notice, this list of conditions and the following + disclaimer. + + 2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + + The rest of this package is licensed under the Mozilla Public License 1.1 Authors and Copyright are as described below: diff --git a/packaging/debs/Debian/debian/rules b/packaging/debs/Debian/debian/rules index a785b292af..108b1ed512 100644 --- a/packaging/debs/Debian/debian/rules +++ b/packaging/debs/Debian/debian/rules @@ -14,7 +14,7 @@ DOCDIR=$(DEB_DESTDIR)usr/share/doc/rabbitmq-server/ install/rabbitmq-server:: mkdir -p $(DOCDIR) rm $(RABBIT_LIB)LICENSE* $(RABBIT_LIB)INSTALL* - for script in rabbitmqctl rabbitmq-server; do \ + for script in rabbitmqctl rabbitmq-server rabbitmq-plugins; do \ install -p -D -m 0755 debian/rabbitmq-script-wrapper $(DEB_DESTDIR)usr/sbin/$$script; \ done sed -e 's|@RABBIT_LIB@|/usr/lib/rabbitmq/lib/rabbitmq_server-$(DEB_UPSTREAM_VERSION)|g' <debian/postrm.in >debian/postrm diff --git a/packaging/macports/Portfile.in b/packaging/macports/Portfile.in index 4a866305d4..03f087d97e 100644 --- a/packaging/macports/Portfile.in +++ b/packaging/macports/Portfile.in @@ -83,24 +83,32 @@ post-destroot { reinplace -E "s:(/etc/rabbitmq/rabbitmq):${prefix}\\1:g" \ ${realsbin}/rabbitmq-env - foreach var {CONFIG_FILE LOG_BASE MNESIA_BASE} { + foreach var {CONFIG_FILE LOG_BASE MNESIA_BASE ENABLED_PLUGINS_FILE} { reinplace -E "s:^($var)=/:\\1=${prefix}/:" \ ${realsbin}/rabbitmq-server \ - ${realsbin}/rabbitmqctl + ${realsbin}/rabbitmqctl \ + ${realsbin}/rabbitmq-plugins } xinstall -m 555 ${filespath}/rabbitmq-script-wrapper \ ${wrappersbin}/rabbitmq-server reinplace -E "s:MACPORTS_PREFIX/bin:${prefix}/bin:" \ - ${wrappersbin}/rabbitmq-server + ${filespath}/rabbitmq-script-wrapper reinplace -E "s:/usr/lib/rabbitmq/bin/:${prefix}/lib/rabbitmq/bin/:" \ - ${wrappersbin}/rabbitmq-server + ${filespath}/rabbitmq-script-wrapper reinplace -E "s:/var/lib/rabbitmq:${prefix}/var/lib/rabbitmq:" \ + ${filespath}/rabbitmq-script-wrapper + + xinstall -m 555 ${filespath}/rabbitmq-script-wrapper \ ${wrappersbin}/rabbitmq-server - file copy ${wrappersbin}/rabbitmq-server ${wrappersbin}/rabbitmqctl + xinstall -m 555 ${filespath}/rabbitmq-script-wrapper \ + ${wrappersbin}/rabbitmqctl + xinstall -m 555 ${filespath}/rabbitmq-script-wrapper \ + ${wrappersbin}/rabbitmq-plugins + - xinstall -m 644 -W ${mansrc}/man1 rabbitmq-server.1.gz rabbitmqctl.1.gz \ + xinstall -m 644 -W ${mansrc}/man1 rabbitmq-server.1.gz rabbitmqctl.1.gz rabbitmq-plugins.1.gz \ ${mandest}/man1/ xinstall -m 644 -W ${mansrc}/man5 rabbitmq-env.conf.5.gz ${mandest}/man5/ } diff --git a/packaging/windows/Makefile b/packaging/windows/Makefile index a0be8d89e0..828cf00050 100644 --- a/packaging/windows/Makefile +++ b/packaging/windows/Makefile @@ -10,20 +10,23 @@ dist: mkdir $(SOURCE_DIR)/sbin mv $(SOURCE_DIR)/scripts/rabbitmq-server.bat $(SOURCE_DIR)/sbin mv $(SOURCE_DIR)/scripts/rabbitmq-service.bat $(SOURCE_DIR)/sbin + mv $(SOURCE_DIR)/scripts/rabbitmq-plugins.bat $(SOURCE_DIR)/sbin mv $(SOURCE_DIR)/scripts/rabbitmqctl.bat $(SOURCE_DIR)/sbin rm -rf $(SOURCE_DIR)/scripts - rm -rf $(SOURCE_DIR)/codegen* $(SOURCE_DIR)/Makefile + 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) - mkdir -p $(TARGET_DIR)/plugins - echo Put your .ez plugin files in this directory > $(TARGET_DIR)/plugins/README + 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 + rm -rf $(TARGET_DIR)/plugins-src zip -q -r $(TARGET_ZIP).zip $(TARGET_DIR) rm -rf $(TARGET_DIR) rabbitmq-service.html diff --git a/scripts/rabbitmq-plugins b/scripts/rabbitmq-plugins new file mode 100755 index 0000000000..4c6cb1fa1d --- /dev/null +++ b/scripts/rabbitmq-plugins @@ -0,0 +1,34 @@ +#!/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 VMware, Inc. +## Copyright (c) 2007-2011 VMware, Inc. All rights reserved. +## + +. `dirname $0`/rabbitmq-env + +ENABLED_PLUGINS_FILE=/etc/rabbitmq/enabled_plugins + +[ "x" = "x$RABBITMQ_ENABLED_PLUGINS_FILE" ] && RABBITMQ_ENABLED_PLUGINS_FILE=${ENABLED_PLUGINS_FILE} + +[ "x" = "x$RABBITMQ_PLUGINS_DIR" ] && RABBITMQ_PLUGINS_DIR="${RABBITMQ_HOME}/plugins" + +exec erl \ + -pa "${RABBITMQ_HOME}/ebin" \ + -noinput \ + -hidden \ + -sname rabbitmq-plugins$$ \ + -s rabbit_plugins \ + -enabled_plugins_file "$RABBITMQ_ENABLED_PLUGINS_FILE" \ + -plugins_dist_dir "$RABBITMQ_PLUGINS_DIR" \ + -extra "$@" diff --git a/scripts/rabbitmq-plugins.bat b/scripts/rabbitmq-plugins.bat new file mode 100755 index 0000000000..ca874a7f4b --- /dev/null +++ b/scripts/rabbitmq-plugins.bat @@ -0,0 +1,51 @@ +@echo off
+REM The contents of this file are subject to the Mozilla Public License
+REM Version 1.1 (the "License"); you may not use this file except in
+REM compliance with the License. You may obtain a copy of the License
+REM at http://www.mozilla.org/MPL/
+REM
+REM Software distributed under the License is distributed on an "AS IS"
+REM basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+REM the License for the specific language governing rights and
+REM limitations under the License.
+REM
+REM The Original Code is RabbitMQ.
+REM
+REM The Initial Developer of the Original Code is VMware, Inc.
+REM Copyright (c) 2007-2011 VMware, Inc. All rights reserved.
+REM
+
+setlocal
+
+rem Preserve values that might contain exclamation marks before
+rem enabling delayed expansion
+set TDP0=%~dp0
+set STAR=%*
+setlocal enabledelayedexpansion
+
+if "!RABBITMQ_BASE!"=="" (
+ set RABBITMQ_BASE=!APPDATA!\RabbitMQ
+)
+
+if not exist "!ERLANG_HOME!\bin\erl.exe" (
+ echo.
+ echo ******************************
+ echo ERLANG_HOME not set correctly.
+ echo ******************************
+ echo.
+ echo Please either set ERLANG_HOME to point to your Erlang installation or place the
+ echo RabbitMQ server distribution in the Erlang lib folder.
+ echo.
+ exit /B
+)
+
+if "!RABBITMQ_ENABLED_PLUGINS_FILE!"=="" (
+ set RABBITMQ_ENABLED_PLUGINS_FILE=!RABBITMQ_BASE!\enabled_plugins
+)
+
+set RABBITMQ_PLUGINS_DIR=!TDP0!..\plugins
+
+"!ERLANG_HOME!\bin\erl.exe" -pa "!TDP0!..\ebin" -noinput -hidden -sname rabbitmq-plugins!RANDOM! -s rabbit_plugins -enabled_plugins_file "!RABBITMQ_ENABLED_PLUGINS_FILE!" -plugins_dist_dir "!RABBITMQ_PLUGINS_DIR:\=/!" -extra !STAR!
+
+endlocal
+endlocal
diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index deca5b3042..11cc7215bb 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -21,6 +21,7 @@ CONFIG_FILE=/etc/rabbitmq/rabbitmq LOG_BASE=/var/log/rabbitmq MNESIA_BASE=/var/lib/rabbitmq/mnesia SERVER_START_ARGS= +ENABLED_PLUGINS_FILE=/etc/rabbitmq/enabled_plugins . `dirname $0`/rabbitmq-env @@ -52,6 +53,7 @@ fi [ "x" = "x$RABBITMQ_PLUGINS_EXPAND_DIR" ] && RABBITMQ_PLUGINS_EXPAND_DIR=${PLUGINS_EXPAND_DIR} [ "x" = "x$RABBITMQ_PLUGINS_EXPAND_DIR" ] && RABBITMQ_PLUGINS_EXPAND_DIR=${RABBITMQ_MNESIA_BASE}/${RABBITMQ_NODENAME}-plugins-expand +[ "x" = "x$RABBITMQ_ENABLED_PLUGINS_FILE" ] && RABBITMQ_ENABLED_PLUGINS_FILE=${ENABLED_PLUGINS_FILE} [ "x" = "x$RABBITMQ_PLUGINS_DIR" ] && RABBITMQ_PLUGINS_DIR="${RABBITMQ_HOME}/plugins" ## Log rotation @@ -74,7 +76,7 @@ if [ "x" = "x$RABBITMQ_NODE_ONLY" ]; then -hidden \ -s rabbit_prelaunch \ -sname rabbitmqprelaunch$$ \ - -extra "$RABBITMQ_PLUGINS_DIR" "${RABBITMQ_PLUGINS_EXPAND_DIR}" "${RABBITMQ_NODENAME}" + -extra "$RABBITMQ_ENABLED_PLUGINS_FILE" "$RABBITMQ_PLUGINS_DIR" "${RABBITMQ_PLUGINS_EXPAND_DIR}" "${RABBITMQ_NODENAME}" then RABBITMQ_BOOT_FILE="${RABBITMQ_PLUGINS_EXPAND_DIR}/rabbit" RABBITMQ_EBIN_PATH="" diff --git a/scripts/rabbitmq-server.bat b/scripts/rabbitmq-server.bat index 56bed4358a..0a78794ffc 100644..100755 --- a/scripts/rabbitmq-server.bat +++ b/scripts/rabbitmq-server.bat @@ -84,6 +84,10 @@ if "!RABBITMQ_PLUGINS_EXPAND_DIR!"=="" ( set RABBITMQ_PLUGINS_EXPAND_DIR=!RABBITMQ_MNESIA_BASE!/!RABBITMQ_NODENAME!-plugins-expand
)
+if "!RABBITMQ_ENABLED_PLUGINS_FILE!"=="" (
+ set RABBITMQ_ENABLED_PLUGINS_FILE=!RABBITMQ_BASE!\enabled_plugins
+)
+
set RABBITMQ_PLUGINS_DIR=!TDP0!..\plugins
set RABBITMQ_EBIN_ROOT=!TDP0!..\ebin
@@ -92,7 +96,8 @@ set RABBITMQ_EBIN_ROOT=!TDP0!..\ebin -noinput -hidden ^
-s rabbit_prelaunch ^
-sname rabbitmqprelaunch!RANDOM! ^
--extra "!RABBITMQ_PLUGINS_DIR:\=/!" ^
+-extra "!RABBITMQ_ENABLED_PLUGINS_FILE!" ^
+ "!RABBITMQ_PLUGINS_DIR:\=/!" ^
"!RABBITMQ_PLUGINS_EXPAND_DIR:\=/!" ^
"!RABBITMQ_NODENAME!"
diff --git a/scripts/rabbitmq-service.bat b/scripts/rabbitmq-service.bat index 26c6ea6545..e671ba7a76 100644..100755 --- a/scripts/rabbitmq-service.bat +++ b/scripts/rabbitmq-service.bat @@ -153,6 +153,10 @@ if errorlevel 1 ( echo !RABBITMQ_SERVICENAME! service is already present - only updating service parameters
)
+if "!RABBITMQ_ENABLED_PLUGINS_FILE!"=="" (
+ set RABBITMQ_ENABLED_PLUGINS_FILE=!RABBITMQ_BASE!\enabled_plugins
+)
+
set RABBITMQ_PLUGINS_DIR=!TDP0!..\plugins
set RABBITMQ_EBIN_ROOT=!TDP0!..\ebin
@@ -160,7 +164,8 @@ set RABBITMQ_EBIN_ROOT=!TDP0!..\ebin -pa "!RABBITMQ_EBIN_ROOT!" ^
-noinput -hidden ^
-s rabbit_prelaunch ^
--extra "!RABBITMQ_PLUGINS_DIR:\=/!" ^
+-extra "!RABBITMQ_ENABLED_PLUGINS_FILE!" ^
+ "!RABBITMQ_PLUGINS_DIR:\=/!" ^
"!RABBITMQ_PLUGINS_EXPAND_DIR:\=/!" ^
""
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index e9f0cf6c54..905e4fd062 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -86,7 +86,7 @@ start() -> true -> ok; false -> io:format("...done.~n") end, - quit(0); + rabbit_misc:quit(0); {'EXIT', {function_clause, [{?MODULE, action, _} | _]}} -> print_error("invalid command '~s'", [string:join([atom_to_list(Command) | Args], " ")]), @@ -96,17 +96,17 @@ start() -> usage(); {error, Reason} -> print_error("~p", [Reason]), - quit(2); + rabbit_misc:quit(2); {badrpc, {'EXIT', Reason}} -> print_error("~p", [Reason]), - quit(2); + rabbit_misc:quit(2); {badrpc, Reason} -> print_error("unable to connect to node ~w: ~w", [Node, Reason]), print_badrpc_diagnostics(Node), - quit(2); + rabbit_misc:quit(2); Other -> print_error("~p", [Other]), - quit(2) + rabbit_misc:quit(2) end. fmt_stderr(Format, Args) -> rabbit_misc:format_stderr(Format ++ "~n", Args). @@ -157,7 +157,7 @@ stop() -> usage() -> io:format("~s", [rabbit_ctl_usage:usage()]), - quit(1). + rabbit_misc:quit(1). %%---------------------------------------------------------------------------- @@ -514,10 +514,3 @@ prettify_typed_amqp_value(table, Value) -> prettify_amqp_table(Value); prettify_typed_amqp_value(array, Value) -> [prettify_typed_amqp_value(T, V) || {T, V} <- Value]; prettify_typed_amqp_value(_Type, Value) -> Value. - -%% the slower shutdown on windows required to flush stdout -quit(Status) -> - case os:type() of - {unix, _} -> halt(Status); - {win32, _} -> init:stop(Status) - end. diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 13a553f124..a9b15af872 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -55,6 +55,7 @@ -export([pget/2, pget/3, pget_or_die/2]). -export([format_message_queue/2]). -export([append_rpc_all_nodes/4]). +-export([quit/1]). %%---------------------------------------------------------------------------- @@ -197,6 +198,7 @@ -spec(pget_or_die/2 :: (term(), [term()]) -> term() | no_return()). -spec(format_message_queue/2 :: (any(), priority_queue:q()) -> term()). -spec(append_rpc_all_nodes/4 :: ([node()], atom(), atom(), [any()]) -> [any()]). +-spec(quit/1 :: (integer() | string()) -> no_return()). -endif. @@ -842,3 +844,10 @@ append_rpc_all_nodes(Nodes, M, F, A) -> {badrpc, _} -> []; _ -> Res end || Res <- ResL]). + +%% the slower shutdown on windows required to flush stdout +quit(Status) -> + case os:type() of + {unix, _} -> halt(Status); + {win32, _} -> init:stop(Status) + end. diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl new file mode 100644 index 0000000000..902fd13d66 --- /dev/null +++ b/src/rabbit_plugins.erl @@ -0,0 +1,348 @@ +%% 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 VMware, Inc. +%% Copyright (c) 2011 VMware, Inc. All rights reserved. +%% + +-module(rabbit_plugins). +-include("rabbit.hrl"). + +-export([start/0, stop/0, find_plugins/1, read_enabled_plugins/1, + lookup_plugins/2, calculate_required_plugins/2, plugin_names/1]). + +-define(VERBOSE_OPT, "-v"). +-define(ENABLED_OPT, "-E"). +-define(ENABLED_ALL_OPT, "-e"). + +%%---------------------------------------------------------------------------- + +-ifdef(use_specs). + +-spec(start/0 :: () -> no_return()). +-spec(stop/0 :: () -> 'ok'). +-spec(find_plugins/1 :: (file:filename()) -> [#plugin{}]). +-spec(read_enabled_plugins/1 :: (file:filename()) -> [atom()]). +-spec(lookup_plugins/2 :: ([atom()], [#plugin{}]) -> [#plugin{}]). +-spec(calculate_required_plugins/2 :: ([atom()], [#plugin{}]) -> [atom()]). +-spec(plugin_names/1 :: ([#plugin{}]) -> [atom()]). + +-endif. + +%%---------------------------------------------------------------------------- + +start() -> + {ok, [[PluginsFile|_]|_]} = + init:get_argument(enabled_plugins_file), + {ok, [[PluginsDir|_]|_]} = init:get_argument(plugins_dist_dir), + {[Command0 | Args], Opts} = + case rabbit_misc:get_options([{flag, ?VERBOSE_OPT}, + {flag, ?ENABLED_OPT}, + {flag, ?ENABLED_ALL_OPT}], + init:get_plain_arguments()) of + {[], _Opts} -> usage(); + CmdArgsAndOpts -> CmdArgsAndOpts + end, + Command = list_to_atom(Command0), + + case catch action(Command, Args, Opts, PluginsFile, PluginsDir) of + ok -> + rabbit_misc:quit(0); + {'EXIT', {function_clause, [{?MODULE, action, _} | _]}} -> + print_error("invalid command '~s'", + [string:join([atom_to_list(Command) | Args], " ")]), + usage(); + {error, Reason} -> + print_error("~p", [Reason]), + rabbit_misc:quit(2); + Other -> + print_error("~p", [Other]), + rabbit_misc:quit(2) + end. + +stop() -> + ok. + +print_error(Format, Args) -> + rabbit_misc:format_stderr("Error: " ++ Format ++ "~n", Args). + +usage() -> + io:format("~s", [rabbit_plugins_usage:usage()]), + rabbit_misc:quit(1). + +%%---------------------------------------------------------------------------- + +action(list, [], Opts, PluginsFile, PluginsDir) -> + action(list, [".*"], Opts, PluginsFile, PluginsDir); +action(list, [Pat], Opts, PluginsFile, PluginsDir) -> + format_plugins(Pat, Opts, PluginsFile, PluginsDir); + +action(enable, ToEnable0, _Opts, PluginsFile, PluginsDir) -> + case ToEnable0 of + [] -> throw("Not enough arguments for 'enable'"); + _ -> ok + end, + AllPlugins = find_plugins(PluginsDir), + Enabled = read_enabled_plugins(PluginsFile), + ImplicitlyEnabled = calculate_required_plugins(Enabled, AllPlugins), + ToEnable = [list_to_atom(Name) || Name <- ToEnable0], + Missing = ToEnable -- plugin_names(AllPlugins), + case Missing of + [] -> ok; + _ -> print_list("Warning: the following plugins could not be found:", + Missing) + end, + NewEnabled = lists:usort(Enabled ++ ToEnable), + write_enabled_plugins(PluginsFile, NewEnabled), + case NewEnabled -- ImplicitlyEnabled of + [] -> io:format("Plugin configuration unchanged.~n"); + _ -> NewImplicitlyEnabled = + calculate_required_plugins(NewEnabled, AllPlugins), + print_list("The following plugins have been enabled:", + NewImplicitlyEnabled -- ImplicitlyEnabled), + io:format("Plugin configuration has changed. " + "Restart RabbitMQ for changes to take effect.~n") + end; + +action(disable, ToDisable0, _Opts, PluginsFile, PluginsDir) -> + case ToDisable0 of + [] -> throw("Not enough arguments for 'disable'"); + _ -> ok + end, + ToDisable = [list_to_atom(Name) || Name <- ToDisable0], + Enabled = read_enabled_plugins(PluginsFile), + AllPlugins = find_plugins(PluginsDir), + Missing = ToDisable -- plugin_names(AllPlugins), + case Missing of + [] -> ok; + _ -> print_list("Warning: the following plugins could not be found:", + Missing) + end, + ToDisable1 = ToDisable -- Missing, + ToDisable2 = calculate_dependencies(true, ToDisable1, AllPlugins), + NewEnabled = Enabled -- ToDisable2, + case length(Enabled) =:= length(NewEnabled) of + true -> io:format("Plugin configuration unchanged.~n"); + false -> ImplicitlyEnabled = + calculate_required_plugins(Enabled, AllPlugins), + NewImplicitlyEnabled = + calculate_required_plugins(NewEnabled, AllPlugins), + print_list("The following plugins have been disabled:", + ImplicitlyEnabled -- NewImplicitlyEnabled), + write_enabled_plugins(PluginsFile, NewEnabled), + io:format("Plugin configuration has changed. " + "Restart RabbitMQ for changes to take effect.~n") + end. + +%%---------------------------------------------------------------------------- + +%% Get the #plugin{}s ready to be enabled. +find_plugins(PluginsDir) -> + EZs = [{ez, EZ} || EZ <- filelib:wildcard("*.ez", PluginsDir)], + FreeApps = [{app, App} || + App <- filelib:wildcard("*/ebin/*.app", PluginsDir)], + {Plugins, Problems} = + lists:foldl(fun ({error, EZ, Reason}, {Plugins1, Problems1}) -> + {Plugins1, [{EZ, Reason} | Problems1]}; + (Plugin = #plugin{}, {Plugins1, Problems1}) -> + {[Plugin|Plugins1], Problems1} + end, {[], []}, + [get_plugin_info(PluginsDir, Plug) || + Plug <- EZs ++ FreeApps]), + case Problems of + [] -> ok; + _ -> io:format("Warning: Problem reading some plugins: ~p~n", + [Problems]) + end, + Plugins. + +%% Get the #plugin{} from an .ez. +get_plugin_info(Base, {ez, EZ0}) -> + EZ = filename:join([Base, EZ0]), + case read_app_file(EZ) of + {application, Name, Props} -> mkplugin(Name, Props, ez, EZ); + {error, Reason} -> {error, EZ, Reason} + end; +%% Get the #plugin{} from an .app. +get_plugin_info(Base, {app, App0}) -> + App = filename:join([Base, App0]), + case rabbit_file:read_term_file(App) of + {ok, [{application, Name, Props}]} -> + mkplugin(Name, Props, dir, + filename:absname( + filename:dirname(filename:dirname(App)))); + {error, Reason} -> + {error, App, {invalid_app, Reason}} + end. + +mkplugin(Name, Props, Type, Location) -> + Version = proplists:get_value(vsn, Props, "0"), + Description = proplists:get_value(description, Props, ""), + Dependencies = + filter_applications(proplists:get_value(applications, Props, [])), + #plugin{name = Name, version = Version, description = Description, + dependencies = Dependencies, location = Location, type = Type}. + +%% Read the .app file from an ez. +read_app_file(EZ) -> + case zip:list_dir(EZ) of + {ok, [_|ZippedFiles]} -> + case find_app_files(ZippedFiles) of + [AppPath|_] -> + {ok, [{AppPath, AppFile}]} = + zip:extract(EZ, [{file_list, [AppPath]}, memory]), + parse_binary(AppFile); + [] -> + {error, no_app_file} + end; + {error, Reason} -> + {error, {invalid_ez, Reason}} + end. + +%% Return the path of the .app files in ebin/. +find_app_files(ZippedFiles) -> + {ok, RE} = re:compile("^.*/ebin/.*.app$"), + [Path || {zip_file, Path, _, _, _, _} <- ZippedFiles, + re:run(Path, RE, [{capture, none}]) =:= match]. + +%% Parse a binary into a term. +parse_binary(Bin) -> + try + {ok, Ts, _} = erl_scan:string(binary_to_list(Bin)), + {ok, Term} = erl_parse:parse_term(Ts), + Term + catch + Err -> {error, {invalid_app, Err}} + end. + +%% Pretty print a list of plugins. +format_plugins(Pattern, Opts, PluginsFile, PluginsDir) -> + Verbose = proplists:get_bool(?VERBOSE_OPT, Opts), + OnlyEnabled = proplists:get_bool(?ENABLED_OPT, Opts), + OnlyEnabledAll = proplists:get_bool(?ENABLED_ALL_OPT, Opts), + + AvailablePlugins = find_plugins(PluginsDir), + EnabledExplicitly = read_enabled_plugins(PluginsFile), + EnabledImplicitly = + calculate_required_plugins(EnabledExplicitly, AvailablePlugins) -- + EnabledExplicitly, + {ok, RE} = re:compile(Pattern), + Plugins = [ Plugin || + Plugin = #plugin{name = Name} <- AvailablePlugins, + re:run(atom_to_list(Name), RE, [{capture, none}]) =:= match, + if OnlyEnabled -> lists:member(Name, EnabledExplicitly); + true -> true + end, + if OnlyEnabledAll -> + lists:member(Name, EnabledImplicitly) or + lists:member(Name, EnabledExplicitly); + true -> + true + end], + Plugins1 = usort_plugins(Plugins), + MaxWidth = lists:max([length(atom_to_list(Name)) || + #plugin{name = Name} <- Plugins1] ++ [0]), + [ format_plugin(P, EnabledExplicitly, EnabledImplicitly, Verbose, + MaxWidth) || P <- Plugins1], + ok. + +format_plugin(#plugin{name = Name, version = Version, + description = Description, dependencies = Dependencies}, + EnabledExplicitly, EnabledImplicitly, Verbose, MaxWidth) -> + Glyph = case {lists:member(Name, EnabledExplicitly), + lists:member(Name, EnabledImplicitly)} of + {true, false} -> "[E]"; + {false, true} -> "[e]"; + _ -> "[ ]" + end, + case Verbose of + false -> + io:format("~s ~-" ++ integer_to_list(MaxWidth) ++ + "w ~s~n", [Glyph, Name, Version]); + true -> + io:format("~s ~w~n", [Glyph, Name]), + io:format(" Version: \t~s~n", [Version]), + case Dependencies of + [] -> ok; + _ -> io:format(" Dependencies:\t~p~n", [Dependencies]) + end, + io:format(" Description:\t~s~n", [Description]), + io:format("~n") + end. + +print_list(Header, Plugins) -> + io:format("~s~n", [Header]), + [io:format(" ~s~n", [P]) || P <- Plugins], + io:format("~n"). + +usort_plugins(Plugins) -> + lists:usort(fun plugins_cmp/2, Plugins). + +plugins_cmp(#plugin{name = N1, version = V1}, + #plugin{name = N2, version = V2}) -> + {N1, V1} =< {N2, V2}. + +%% Filter out applications that can be loaded *right now*. +filter_applications(Applications) -> + [Application || Application <- Applications, + not is_available_app(Application)]. + +%% Return whether is application is already available (and hence +%% doesn't need enabling). +is_available_app(Application) -> + case application:load(Application) of + {error, {already_loaded, _}} -> true; + ok -> application:unload(Application), + true; + _ -> false + end. + +%% Return the names of the given plugins. +plugin_names(Plugins) -> + [Name || #plugin{name = Name} <- Plugins]. + +%% Find plugins by name in a list of plugins. +lookup_plugins(Names, AllPlugins) -> + [P || P = #plugin{name = Name} <- AllPlugins, lists:member(Name, Names)]. + +%% Read the enabled plugin names from disk. +read_enabled_plugins(PluginsFile) -> + case rabbit_file:read_term_file(PluginsFile) of + {ok, [Plugins]} -> Plugins; + {error, enoent} -> []; + {error, Reason} -> throw({error, {cannot_read_enabled_plugins_file, + PluginsFile, Reason}}) + end. + +%% Write the enabled plugin names on disk. +write_enabled_plugins(PluginsFile, Plugins) -> + case rabbit_file:write_term_file(PluginsFile, [Plugins]) of + ok -> ok; + {error, Reason} -> throw({error, {cannot_write_enabled_plugins_file, + PluginsFile, Reason}}) + end. + +calculate_required_plugins(Sources, AllPlugins) -> + calculate_dependencies(false, Sources, AllPlugins). + +calculate_dependencies(Reverse, Sources, AllPlugins) -> + {ok, G} = rabbit_misc:build_acyclic_graph( + fun (App, _Deps) -> [{App, App}] end, + fun (App, Deps) -> [{App, Dep} || Dep <- Deps] end, + [{Name, Deps} + || #plugin{name = Name, dependencies = Deps} <- AllPlugins]), + Dests = case Reverse of + false -> digraph_utils:reachable(Sources, G); + true -> digraph_utils:reaching(Sources, G) + end, + true = digraph:delete(G), + Dests. diff --git a/src/rabbit_prelaunch.erl b/src/rabbit_prelaunch.erl index cd0c322b6d..d34ed44a8b 100644 --- a/src/rabbit_prelaunch.erl +++ b/src/rabbit_prelaunch.erl @@ -18,6 +18,8 @@ -export([start/0, stop/0]). +-include("rabbit.hrl"). + -define(BaseApps, [rabbit]). -define(ERROR_CODE, 1). @@ -41,14 +43,14 @@ start() -> io:format("Activating RabbitMQ plugins ...~n"), %% Determine our various directories - [PluginDir, UnpackedPluginDir, NodeStr] = init:get_plain_arguments(), + [EnabledPluginsFile, PluginsDistDir, UnpackedPluginDir, NodeStr] = + init:get_plain_arguments(), RootName = UnpackedPluginDir ++ "/rabbit", - %% Unpack any .ez plugins - unpack_ez_plugins(PluginDir, UnpackedPluginDir), + prepare_plugins(EnabledPluginsFile, PluginsDistDir, UnpackedPluginDir), %% Build a list of required apps based on the fixed set, and any plugins - PluginApps = find_plugins(PluginDir) ++ find_plugins(UnpackedPluginDir), + PluginApps = find_plugins(UnpackedPluginDir), RequiredApps = ?BaseApps ++ PluginApps, %% Build the entire set of dependencies - this will load the @@ -145,7 +147,19 @@ delete_recursively(Fn) -> Error -> Error end. -unpack_ez_plugins(SrcDir, DestDir) -> +prepare_plugins(EnabledPluginsFile, PluginsDistDir, DestDir) -> + AllPlugins = rabbit_plugins:find_plugins(PluginsDistDir), + Enabled = rabbit_plugins:read_enabled_plugins(EnabledPluginsFile), + ToUnpack = rabbit_plugins:calculate_required_plugins(Enabled, AllPlugins), + ToUnpackPlugins = rabbit_plugins:lookup_plugins(ToUnpack, AllPlugins), + + Missing = Enabled -- rabbit_plugins:plugin_names(ToUnpackPlugins), + case Missing of + [] -> ok; + _ -> io:format("Warning: the following enabled plugins were " + "not found: ~p~n", [Missing]) + end, + %% Eliminate the contents of the destination directory case delete_recursively(DestDir) of ok -> ok; @@ -155,12 +169,15 @@ unpack_ez_plugins(SrcDir, DestDir) -> ok -> ok; {error, E2} -> terminate("Could not create dir ~s (~p)", [DestDir, E2]) end, - [unpack_ez_plugin(PluginName, DestDir) || - PluginName <- filelib:wildcard(SrcDir ++ "/*.ez")]. -unpack_ez_plugin(PluginFn, PluginDestDir) -> - zip:unzip(PluginFn, [{cwd, PluginDestDir}]), - ok. + [prepare_plugin(Plugin, DestDir) || Plugin <- ToUnpackPlugins]. + +prepare_plugin(#plugin{type = ez, location = Location}, PluginDestDir) -> + zip:unzip(Location, [{cwd, PluginDestDir}]); +prepare_plugin(#plugin{type = dir, name = Name, location = Location}, + PluginsDestDir) -> + rabbit_file:recursive_copy(Location, + filename:join([PluginsDestDir, Name])). find_plugins(PluginDir) -> [prepare_dir_plugin(PluginName) || |
