summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@lshift.net>2008-11-27 16:26:29 +0000
committerSimon MacMullen <simon@lshift.net>2008-11-27 16:26:29 +0000
commitbd00b2c6aa5839d739c8ee3871c8bd3f3d1d4137 (patch)
tree6f683b2df948b17cebdff503ac103667c84c8eaf
parentce149ff9a892d160cc666426ba769b718c3a9f16 (diff)
downloadrabbitmq-server-git-bd00b2c6aa5839d739c8ee3871c8bd3f3d1d4137.tar.gz
Create rabbitmq-mnesia-update-needed script
-rw-r--r--Makefile3
-rwxr-xr-xscripts/rabbitmq-mnesia-update-needed49
-rw-r--r--src/rabbit_mnesia.erl18
3 files changed, 70 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 04a0aff622..e7edaa56ab 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
+test_mnesia: all
+ NODE_IP_ADDRESS=$(NODE_IP_ADDRESS) NODE_PORT=$(NODE_PORT) LOG_BASE=$(LOG_BASE) MNESIA_DIR=$(MNESIA_DIR) ./scripts/rabbitmq-mnesia-update-needed
+
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
diff --git a/scripts/rabbitmq-mnesia-update-needed b/scripts/rabbitmq-mnesia-update-needed
new file mode 100755
index 0000000000..dcc5b45306
--- /dev/null
+++ b/scripts/rabbitmq-mnesia-update-needed
@@ -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 'rabbit_mnesia:update_needed()' \
+ -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 9b67135def..140574b5db 100644
--- a/src/rabbit_mnesia.erl
+++ b/src/rabbit_mnesia.erl
@@ -30,6 +30,9 @@
-export([table_names/0]).
+%% Called by rabbit-mnesia-update-needed script
+-export([update_needed/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(update_needed/0 :: () -> 'halt').
-endif.
@@ -91,6 +95,20 @@ cluster(ClusterNodes) ->
reset() -> reset(false).
force_reset() -> reset(true).
+%% This is invoked by rabbitmq-mnesia-update-needed. It will halt with an error
+%% code if an update is needed, and halt without one otherwise.
+update_needed() ->
+ application:start(mnesia),
+ ok = ensure_mnesia_running(),
+ ok = ensure_mnesia_dir(),
+ ok = init_db(read_cluster_nodes_config()),
+ try ensure_schema_integrity()
+ catch
+ {error, {schema_integrity_check_failed, _Reason}} ->
+ halt(1)
+ end,
+ halt().
+
%%--------------------------------------------------------------------
table_definitions() ->