summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--packaging/debs/Debian/debian/control2
-rw-r--r--packaging/debs/Debian/debian/postinst22
-rw-r--r--packaging/debs/Debian/debian/templates16
-rwxr-xr-xscripts/rabbitmq-mnesia-current49
-rw-r--r--src/rabbit_mnesia.erl18
-rw-r--r--src/rabbit_tests.erl2
7 files changed, 112 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 04a0aff6..66637ee2 100644
--- a/Makefile
+++ b/Makefile
@@ -63,6 +63,9 @@ cleandb: stop-node
run: all
NODE_IP_ADDRESS=$(NODE_IP_ADDRESS) NODE_PORT=$(NODE_PORT) NODE_ONLY=true LOG_BASE=$(LOG_BASE) RABBIT_ARGS="$(RABBIT_ARGS) -s rabbit" MNESIA_DIR=$(MNESIA_DIR) ./scripts/rabbitmq-server
+check-mnesia-schema: all
+ NODE_IP_ADDRESS=$(NODE_IP_ADDRESS) NODE_PORT=$(NODE_PORT) LOG_BASE=$(LOG_BASE) MNESIA_DIR=$(MNESIA_DIR) ./scripts/rabbitmq-mnesia-current
+
run-node: all
NODE_IP_ADDRESS=$(NODE_IP_ADDRESS) NODE_PORT=$(NODE_PORT) NODE_ONLY=true LOG_BASE=$(LOG_BASE) RABBIT_ARGS="$(RABBIT_ARGS)" MNESIA_DIR=$(MNESIA_DIR) ./scripts/rabbitmq-server
@@ -134,6 +137,7 @@ install: all
cp scripts/rabbitmq-server $(SBIN_DIR)
cp scripts/rabbitmqctl $(SBIN_DIR)
cp scripts/rabbitmq-multi $(SBIN_DIR)
+ cp scripts/rabbitmq-mnesia-current $(SBIN_DIR)
for manpage in docs/*.pod ; do \
pod2man -c "RabbitMQ AMQP Server" -d "" -r "" \
$$manpage | gzip --best > \
diff --git a/packaging/debs/Debian/debian/control b/packaging/debs/Debian/debian/control
index 749791a4..a0d858be 100644
--- a/packaging/debs/Debian/debian/control
+++ b/packaging/debs/Debian/debian/control
@@ -7,7 +7,7 @@ Standards-Version: 3.7.2
Package: rabbitmq-server
Architecture: all
-Depends: erlang-nox, adduser, logrotate
+Depends: erlang-nox, adduser, logrotate, debconf
Description: An AMQP server written in Erlang
RabbitMQ is an implementation of AMQP, the emerging standard for high
performance enterprise messaging. The RabbitMQ server is a robust and
diff --git a/packaging/debs/Debian/debian/postinst b/packaging/debs/Debian/debian/postinst
index f92131d0..13d8552f 100644
--- a/packaging/debs/Debian/debian/postinst
+++ b/packaging/debs/Debian/debian/postinst
@@ -34,6 +34,28 @@ chown -R rabbitmq:rabbitmq /var/log/rabbitmq
case "$1" in
configure)
+ . /usr/share/debconf/confmodule
+
+ if ! su rabbitmq -s /bin/sh -c /usr/lib/rabbitmq/bin/rabbitmq-mnesia-current ; then
+ db_beginblock
+ db_input high rabbitmq-server/mnesia-dir-note || true
+ db_input high rabbitmq-server/do-what-with-mnesia-dir || true
+ db_endblock
+ db_go
+
+ db_get rabbitmq-server/do-what-with-mnesia-dir
+ if [ "$RET" = "Delete it" ]; then
+ rm -r /var/lib/rabbitmq/mnesia/
+ elif [ "$RET" = "Move it elsewhere" ]; then
+ db_input high rabbitmq-server/move-mnesia-dir-where || true
+ db_go
+
+ db_get rabbitmq-server/move-mnesia-dir-where
+
+ mkdir -p "`dirname $RET`"
+ mv /var/lib/rabbitmq/mnesia "$RET"
+ fi
+ fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
diff --git a/packaging/debs/Debian/debian/templates b/packaging/debs/Debian/debian/templates
new file mode 100644
index 00000000..89f5754b
--- /dev/null
+++ b/packaging/debs/Debian/debian/templates
@@ -0,0 +1,16 @@
+Template: rabbitmq-server/mnesia-dir-note
+Type: note
+Description: Schema changed
+ The RabbitMQ database schema has changed. If your RabbitMQ database contains important data, such as user accounts, durable exchanges and queues, or persistent messages, then we recommend you contact support@rabbitmq.com for assistance with the upgrade. If you want to experiment with the new version in the meantime, simply move the database directory to a safe place. In all other cases just remove the directory.
+
+
+Template: rabbitmq-server/do-what-with-mnesia-dir
+Type: select
+Choices: Delete it, Move it elsewhere, Keep it in place (WILL BREAK)
+Default: Delete it
+Description: What do you want to do with the RabbitMQ database directory?
+
+Template: rabbitmq-server/move-mnesia-dir-where
+Type: string
+Default: /var/lib/rabbitmq/mnesia-old/
+Description: Where do you want to move the RabbitMQ database directory?
diff --git a/scripts/rabbitmq-mnesia-current b/scripts/rabbitmq-mnesia-current
new file mode 100755
index 00000000..21f04f88
--- /dev/null
+++ b/scripts/rabbitmq-mnesia-current
@@ -0,0 +1,49 @@
+#!/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 Developers of the Original Code are LShift Ltd.,
+## Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
+##
+## Portions created by LShift Ltd., Cohesive Financial Technologies
+## LLC., and Rabbit Technologies Ltd. are Copyright (C) 2007-2008
+## LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
+## Technologies Ltd.;
+##
+## All Rights Reserved.
+##
+## Contributor(s): ______________________________________.
+##
+
+[ "x" = "x$NODENAME" ] && NODENAME=rabbit
+[ "x" = "x$NODE_IP_ADDRESS" ] && NODE_IP_ADDRESS=0.0.0.0
+[ "x" = "x$NODE_PORT" ] && NODE_PORT=5672
+
+CLUSTER_CONFIG_FILE=/etc/default/rabbitmq_cluster.config
+
+[ "x" = "x$LOG_BASE" ] && LOG_BASE=/var/log/rabbitmq
+[ "x" = "x$MNESIA_BASE" ] && MNESIA_BASE=/var/lib/rabbitmq/mnesia
+[ "x" = "x$MNESIA_DIR" ] && MNESIA_DIR=${MNESIA_BASE}/${NODENAME}
+
+if [ -f "$CLUSTER_CONFIG_FILE" ]; then
+ CLUSTER_CONFIG="-rabbit cluster_config \"$CLUSTER_CONFIG_FILE\""
+else
+ CLUSTER_CONFIG=""
+fi
+
+exec erl \
+ -pa "`dirname $0`/../ebin" \
+ -noshell \
+ -eval 'halt(case rabbit_mnesia:schema_current() of true -> 0; false -> 1 end).' \
+ -mnesia dir "\"${MNESIA_DIR}\"" \
+ -kernel error_logger '{file,"'/dev/null'"}' \
+ ${CLUSTER_CONFIG}
diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl
index 8d34d285..ca8b5878 100644
--- a/src/rabbit_mnesia.erl
+++ b/src/rabbit_mnesia.erl
@@ -30,6 +30,9 @@
-export([table_names/0]).
+%% Called by rabbitmq-mnesia-current script
+-export([schema_current/0]).
+
%% create_tables/0 exported for helping embed RabbitMQ in or alongside
%% other mnesia-using Erlang applications, such as ejabberd
-export([create_tables/0]).
@@ -48,6 +51,7 @@
-spec(reset/0 :: () -> 'ok').
-spec(force_reset/0 :: () -> 'ok').
-spec(create_tables/0 :: () -> 'ok').
+-spec(schema_current/0 :: () -> bool()).
-endif.
@@ -91,6 +95,20 @@ cluster(ClusterNodes) ->
reset() -> reset(false).
force_reset() -> reset(true).
+%% This is invoked by rabbitmq-mnesia-current.
+schema_current() ->
+ application:start(mnesia),
+ ok = ensure_mnesia_running(),
+ ok = ensure_mnesia_dir(),
+ ok = init_db(read_cluster_nodes_config()),
+ try
+ ensure_schema_integrity(),
+ true
+ catch
+ {error, {schema_integrity_check_failed, _Reason}} ->
+ false
+ end.
+
%%--------------------------------------------------------------------
table_definitions() ->
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index db78bbcc..09e2cfe4 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -131,6 +131,8 @@ test_topic_matching() ->
passed.
test_app_management() ->
+ true = rabbit_mnesia:schema_current(),
+
%% starting, stopping, status
ok = control_action(stop_app, []),
ok = control_action(stop_app, []),