summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2008-12-05 09:31:03 +0000
committerMatthias Radestock <matthias@lshift.net>2008-12-05 09:31:03 +0000
commit5fa4f462d7d3a691ab0bb159e388a096f7e0f019 (patch)
tree55213ac76a9b152ebc012cc5fe65d8a5d3596a0a
parent8baa7fc6ba47830b629873f8b1c4a517072bb7d5 (diff)
parent714c8d1957e9f5332b6deaf858bfa64d842960db (diff)
downloadrabbitmq-server-bug19900.tar.gz
merge default into bug19900bug19900
-rw-r--r--Makefile4
-rw-r--r--codegen.py3
-rw-r--r--packaging/RPMS/Fedora/rabbitmq-server.spec2
-rw-r--r--packaging/debs/Debian/debian/control4
-rw-r--r--packaging/debs/Debian/debian/dirs1
-rw-r--r--packaging/debs/Debian/debian/init.d4
-rw-r--r--packaging/debs/Debian/debian/postinst22
-rw-r--r--packaging/debs/Debian/debian/rabbitmqctl_wrapper9
-rw-r--r--packaging/debs/Debian/debian/rules9
-rw-r--r--packaging/debs/Debian/debian/templates16
-rw-r--r--packaging/windows/Makefile3
-rw-r--r--packaging/windows/rabbitmq-service.pod138
-rwxr-xr-xscripts/rabbitmq-mnesia-current50
-rwxr-xr-xscripts/rabbitmq-server2
-rwxr-xr-x[-rw-r--r--]scripts/rabbitmq-server.bat2
-rwxr-xr-xscripts/rabbitmq-service.bat189
-rwxr-xr-xscripts/rabbitmqctl7
-rw-r--r--src/rabbit_alarm.erl70
-rw-r--r--src/rabbit_control.erl71
-rw-r--r--src/rabbit_log.erl14
-rw-r--r--src/rabbit_memsup_linux.erl150
-rw-r--r--src/rabbit_misc.erl7
-rw-r--r--src/rabbit_mnesia.erl18
-rw-r--r--src/rabbit_multi.erl24
-rw-r--r--src/rabbit_router.erl13
-rw-r--r--src/rabbit_tests.erl2
26 files changed, 748 insertions, 86 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/codegen.py b/codegen.py
index 5dbc57c7..629f2b8c 100644
--- a/codegen.py
+++ b/codegen.py
@@ -58,7 +58,8 @@ erlangDefaultValueTypeConvMap = {
str : lambda x: "<<\"" + x + "\">>",
int : lambda x: str(x),
float : lambda x: str(x),
- dict: convertTable
+ dict: convertTable,
+ unicode: lambda x: "<<\"" + x.encode("utf-8") + "\">>"
}
def erlangize(s):
diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec
index 23ebecef..9067a844 100644
--- a/packaging/RPMS/Fedora/rabbitmq-server.spec
+++ b/packaging/RPMS/Fedora/rabbitmq-server.spec
@@ -11,7 +11,7 @@ URL: http://www.rabbitmq.com/
Vendor: LShift Ltd., Cohesive Financial Technologies LLC., Rabbit Technlogies Ltd.
%if 0%{?debian}
%else
-BuildRequires: erlang, python-json
+BuildRequires: erlang, python-simplejson
%endif
Requires: erlang, logrotate
Packager: Hubert Plociniczak <hubert@lshift.net>
diff --git a/packaging/debs/Debian/debian/control b/packaging/debs/Debian/debian/control
index 749791a4..f6761713 100644
--- a/packaging/debs/Debian/debian/control
+++ b/packaging/debs/Debian/debian/control
@@ -2,12 +2,12 @@ Source: rabbitmq-server
Section: net
Priority: extra
Maintainer: Tony Garnock-Jones <tonyg@rabbitmq.com>
-Build-Depends: cdbs, debhelper (>= 5), erlang-nox, erlang-dev, python-json
+Build-Depends: cdbs, debhelper (>= 5), erlang-nox, erlang-dev, python-simplejson
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/dirs b/packaging/debs/Debian/debian/dirs
index 74f86314..1a707bc1 100644
--- a/packaging/debs/Debian/debian/dirs
+++ b/packaging/debs/Debian/debian/dirs
@@ -1,3 +1,4 @@
+usr/lib/rabbitmq/bin
usr/lib/erlang/lib
usr/sbin
usr/share/man
diff --git a/packaging/debs/Debian/debian/init.d b/packaging/debs/Debian/debian/init.d
index a93f3066..ace474c5 100644
--- a/packaging/debs/Debian/debian/init.d
+++ b/packaging/debs/Debian/debian/init.d
@@ -10,7 +10,7 @@
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-DAEMON=/usr/sbin/rabbitmq-multi
+DAEMON=/usr/lib/rabbitmq/bin/rabbitmq-multi
NAME=rabbitmq-server
DESC=rabbitmq-server
USER=rabbitmq
@@ -51,7 +51,7 @@ start_rabbitmq () {
stop_rabbitmq () {
set +e
status_rabbitmq quiet
- if [ $RETVAL == 0 ] ; then
+ if [ $RETVAL = 0 ] ; then
su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown_log 2> /var/log/rabbitmq/shutdown_err
RETVAL=$?
if [ $RETVAL != 0 ] ; then
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/rabbitmqctl_wrapper b/packaging/debs/Debian/debian/rabbitmqctl_wrapper
index c484bb27..774731fc 100644
--- a/packaging/debs/Debian/debian/rabbitmqctl_wrapper
+++ b/packaging/debs/Debian/debian/rabbitmqctl_wrapper
@@ -10,5 +10,12 @@ for arg in "$@" ; do
done
cd /
-su rabbitmq -s /bin/sh -c "/usr/sbin/rabbitmqctl_real ${CMDLINE}"
+
+if [ ${UID} = 0 ] ; then
+ su rabbitmq -s /bin/sh -c "/usr/lib/rabbitmq/bin/rabbitmqctl ${CMDLINE}"
+else
+ /usr/lib/rabbitmq/bin/rabbitmqctl
+ echo -e "\nOnly root should run rabbitmqctl\n"
+ exit 1
+fi
diff --git a/packaging/debs/Debian/debian/rules b/packaging/debs/Debian/debian/rules
index 39af711c..fa4cb855 100644
--- a/packaging/debs/Debian/debian/rules
+++ b/packaging/debs/Debian/debian/rules
@@ -3,17 +3,16 @@
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/makefile.mk
-RABBIT_LIB=$(DEB_DESTDIR)usr/lib/erlang/lib/rabbitmq_server-$(DEB_UPSTREAM_VERSION)
+RABBIT_LIB=$(DEB_DESTDIR)usr/lib/erlang/lib/rabbitmq_server-$(DEB_UPSTREAM_VERSION)/
+RABBIT_BIN=$(DEB_DESTDIR)usr/lib/rabbitmq/bin/
-DEB_MAKE_INSTALL_TARGET := install TARGET_DIR=$(RABBIT_LIB)/ SBIN_DIR=$(DEB_DESTDIR)usr/sbin MAN_DIR=$(DEB_DESTDIR)usr/share/man
+DEB_MAKE_INSTALL_TARGET := install TARGET_DIR=$(RABBIT_LIB) SBIN_DIR=$(RABBIT_BIN) MAN_DIR=$(DEB_DESTDIR)usr/share/man/
DOCDIR=$(DEB_DESTDIR)usr/share/doc/rabbitmq-server/
install/rabbitmq-server::
mkdir -p $(DOCDIR)
- rm $(RABBIT_LIB)/LICENSE*
- mv $(DEB_DESTDIR)usr/sbin/rabbitmqctl $(DEB_DESTDIR)usr/sbin/rabbitmqctl_real
+ rm $(RABBIT_LIB)LICENSE*
cp debian/rabbitmqctl_wrapper $(DEB_DESTDIR)usr/sbin/rabbitmqctl
cp debian/rabbitmq-server.logrotate $(DEB_DESTDIR)etc/logrotate.d/rabbitmq-server
- cp $(DEB_DESTDIR)usr/share/man/man1/rabbitmqctl.1.gz $(DEB_DESTDIR)usr/share/man/man1/rabbitmqctl_real.1.gz
chmod a+x $(DEB_DESTDIR)usr/sbin/rabbitmqctl
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/packaging/windows/Makefile b/packaging/windows/Makefile
index f9437da7..9d16fd9f 100644
--- a/packaging/windows/Makefile
+++ b/packaging/windows/Makefile
@@ -10,6 +10,7 @@ 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/rabbitmqctl.bat $(SOURCE_DIR)/sbin
mv $(SOURCE_DIR)/scripts/rabbitmq-multi.bat $(SOURCE_DIR)/sbin
rm -rf $(SOURCE_DIR)/scripts
@@ -18,6 +19,8 @@ dist:
rm -rf $(SOURCE_DIR)/docs
mv $(SOURCE_DIR) $(TARGET_DIR)
+ pod2text --loose rabbitmq-service.pod $(TARGET_DIR)/readme-service.txt
+ unix2dos $(TARGET_DIR)/readme-service.txt
zip -r $(TARGET_ZIP).zip $(TARGET_DIR)
rm -rf $(TARGET_DIR)
diff --git a/packaging/windows/rabbitmq-service.pod b/packaging/windows/rabbitmq-service.pod
new file mode 100644
index 00000000..6a97c435
--- /dev/null
+++ b/packaging/windows/rabbitmq-service.pod
@@ -0,0 +1,138 @@
+=head1 NAME
+
+rabbitmq-service - manage RabbitMQ AMQP service
+
+=head1 SYNOPSIS
+
+rabbitmq-service.bat command
+
+=head1 DESCRIPTION
+
+RabbitMQ is an implementation of AMQP, the emerging standard for high
+performance enterprise messaging. The RabbitMQ server is a robust and
+scalable implementation of an AMQP broker.
+
+Running B<rabbitmq-service> allows the RabbitMQ broker to be run as a
+service on NT/2000/2003/XP/Vista® environments. The RabbitMQ broker
+service can be started and stopped using the Windows® services
+applet.
+
+By default the service will run in the authentication context of the
+local system account. It is therefore necessary to synchronise Erlang
+cookies between the local system account (typically
+C<C:\WINDOWS\.erlang.cookie> and the account that will be used to
+run B<rabbitmqctl>.
+
+=head1 COMMANDS
+
+=head2 help
+
+Display usage information.
+
+=head2 install
+
+Install the service. The service will not be started.
+Subsequent invocations will update the service parameters if
+relevant environment variables were modified.
+
+=head2 remove
+
+Remove the service. If the service is running then it will
+automatically be stopped before being removed. No files will be
+deleted as a consequence and B<rabbitmq-server> will remain operable.
+
+=head2 start
+
+Start the service. The service must have been correctly installed
+beforehand.
+
+=head2 stop
+
+Stop the service. The service must be running for this command to
+have any effect.
+
+=head2 disable
+
+Disable the service. This is the equivalent of setting the startup
+type to B<Disabled> using the service control panel.
+
+=head2 enable
+
+Enable the service. This is the equivalent of setting the startup
+type to B<Automatic> using the service control panel.
+
+=head1 ENVIRONMENT
+
+=head2 SERVICENAME
+
+Defaults to RabbitMQ.
+This is the location of log and database directories.
+
+=head2 RABBITMQ_BASE
+
+Defaults to the application data directory of the current user.
+This is the location of log and database directories.
+
+=head2 NODENAME
+
+Defaults to "rabbit". This can be useful if you want to run more
+than one node per machine - B<NODENAME> should be unique per
+erlang-node-and-machine combination. See clustering on a single
+machine guide
+at L<http://www.rabbitmq.com/clustering.html#single-machine> for
+details.
+
+=head2 NODE_IP_ADDRESS
+
+Defaults to "0.0.0.0". This can be changed if you only want to bind
+to one network interface.
+
+=head2 NODE_PORT
+
+Defaults to 5672.
+
+=head2 ERLANG_SERVICE_MANAGER_PATH
+
+Defaults to F<C:\Program Files\erl5.5.5\erts-5.5.5\bin>. This is
+the installation location of the Erlang service manager.
+
+=head2 CLUSTER_CONFIG_FILE
+
+If this file is present it is used by the server to
+auto-configure a RabbitMQ cluster. See the clustering guide
+at L<http://www.rabbitmq.com/clustering.html> for details.
+
+=head2 CONSOLE_LOG
+
+Set this varable to B<new> or B<reuse> to have the console
+output from the server redirected to a file named B<SERVICENAME>.debug
+in the application data directory of the user that installed the service.
+Under Vista this will be F<C:\Documents and Settings\User\AppData\username\SERVICENAME>.
+Under previous versions of Windows this will be
+F<C:\Documents and Settings\username\Application Data\SERVICENAME>.
+If B<CONSOLE_LOG> is set to B<new> then a new file will be created
+each time the service starts. If B<CONSOLE_LOG> is set to B<reuse>
+then the file will be overwritten each time the service starts.
+The default behaviour when B<CONSOLE_LOG> is not set or set to a
+value other than B<new> or B<reuse> is to discard the server output.
+
+=head1 EXAMPLES
+
+Start a previously-installed RabbitMQ AMQP service:
+
+ rabbitmq-service start
+
+=head1 AUTHOR
+
+Originally written by The RabbitMQ Team <info@lshift.net>
+
+=head1 COPYRIGHT
+
+This package, the RabbitMQ server is licensed under the MPL.
+
+If you have any questions regarding licensing, please contact us at
+info@rabbitmq.com.
+
+=head1 REFERENCES
+
+RabbitMQ Web Site: http://www.rabbitmq.com
diff --git a/scripts/rabbitmq-mnesia-current b/scripts/rabbitmq-mnesia-current
new file mode 100755
index 00000000..45f1a845
--- /dev/null
+++ b/scripts/rabbitmq-mnesia-current
@@ -0,0 +1,50 @@
+#!/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 \
+ -sname ${NODENAME} \
+ -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/scripts/rabbitmq-server b/scripts/rabbitmq-server
index fba2f026..1ce5458e 100755
--- a/scripts/rabbitmq-server
+++ b/scripts/rabbitmq-server
@@ -66,7 +66,7 @@ exec erl \
-sasl sasl_error_logger '{file,"'${SASL_LOGS}'"}' \
-os_mon start_cpu_sup true \
-os_mon start_disksup false \
- -os_mon start_memsup true \
+ -os_mon start_memsup false \
-os_mon start_os_sup false \
-os_mon memsup_system_only true \
-os_mon system_memory_high_watermark 0.95 \
diff --git a/scripts/rabbitmq-server.bat b/scripts/rabbitmq-server.bat
index 38b8cc53..b21c2739 100644..100755
--- a/scripts/rabbitmq-server.bat
+++ b/scripts/rabbitmq-server.bat
@@ -107,7 +107,7 @@ set MNESIA_DIR=%MNESIA_BASE%/%NODENAME%-mnesia
-sasl sasl_error_logger {file,\""%LOG_BASE%/%NODENAME%-sasl.log"\"} ^
-os_mon start_cpu_sup true ^
-os_mon start_disksup false ^
--os_mon start_memsup true ^
+-os_mon start_memsup false ^
-os_mon start_os_sup false ^
-os_mon memsup_system_only true ^
-os_mon system_memory_high_watermark 0.95 ^
diff --git a/scripts/rabbitmq-service.bat b/scripts/rabbitmq-service.bat
new file mode 100755
index 00000000..4b9cc452
--- /dev/null
+++ b/scripts/rabbitmq-service.bat
@@ -0,0 +1,189 @@
+@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 at
+REM 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 the
+REM License for the specific language governing rights and limitations
+REM under the License.
+REM
+REM The Original Code is RabbitMQ.
+REM
+REM The Initial Developers of the Original Code are LShift Ltd.,
+REM Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
+REM
+REM Portions created by LShift Ltd., Cohesive Financial Technologies
+REM LLC., and Rabbit Technologies Ltd. are Copyright (C) 2007-2008
+REM LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
+REM Technologies Ltd.;
+REM
+REM All Rights Reserved.
+REM
+REM Contributor(s): ______________________________________.
+REM
+
+if "%SERVICENAME%"=="" (
+ set SERVICENAME=RabbitMQ
+)
+
+if "%RABBITMQ_BASE%"=="" (
+ set RABBITMQ_BASE=%APPDATA%\%SERVICENAME%
+)
+
+if "%NODENAME%"=="" (
+ set NODENAME=rabbit
+)
+
+if "%NODE_IP_ADDRESS%"=="" (
+ set NODE_IP_ADDRESS=0.0.0.0
+)
+
+if "%NODE_PORT%"=="" (
+ set NODE_PORT=5672
+)
+
+if "%ERLANG_SERVICE_MANAGER_PATH%"=="" (
+ set ERLANG_SERVICE_MANAGER_PATH=C:\Program Files\erl5.5.5\erts-5.5.5\bin
+)
+
+set CONSOLE_FLAG=
+set CONSOLE_LOG_VALID=
+for %%i in (new reuse) do if "%%i" == "%CONSOLE_LOG%" set CONSOLE_LOG_VALID=TRUE
+if "%CONSOLE_LOG_VALID%" == "TRUE" (
+ set CONSOLE_FLAG=-debugtype %CONSOLE_LOG%
+)
+
+rem *** End of configuration ***
+
+if not exist "%ERLANG_SERVICE_MANAGER_PATH%\erlsrv.exe" (
+ echo.
+ echo **********************************************
+ echo ERLANG_SERVICE_MANAGER_PATH not set correctly.
+ echo **********************************************
+ echo.
+ echo %ERLANG_SERVICE_MANAGER_PATH%\erlsrv.exe not found!
+ echo Please set ERLANG_SERVICE_MANAGER_PATH to the folder containing "erlsrv.exe".
+ echo.
+ exit /B 1
+)
+
+rem erlang prefers forwardslash as separator in paths
+set RABBITMQ_BASE_UNIX=%RABBITMQ_BASE:\=/%
+set MNESIA_BASE=%RABBITMQ_BASE_UNIX%/db
+set LOG_BASE=%RABBITMQ_BASE_UNIX%/log
+
+
+rem We save the previous logs in their respective backup
+rem Log management (rotation, filtering based on size...) is left as an exercise for the user.
+
+set BACKUP_EXTENSION=.1
+
+set LOGS="%RABBITMQ_BASE%\log\%NODENAME%.log"
+set SASL_LOGS="%RABBITMQ_BASE%\log\%NODENAME%-sasl.log"
+
+set LOGS_BACKUP="%RABBITMQ_BASE%\log\%NODENAME%.log%BACKUP_EXTENSION%"
+set SASL_LOGS_BACKUP="%RABBITMQ_BASE%\log\%NODENAME%-sasl.log%BACKUP_EXTENSION%"
+
+if exist %LOGS% (
+ type %LOGS% >> %LOGS_BACKUP%
+)
+if exist %SASL_LOGS% (
+ type %SASL_LOGS% >> %SASL_LOGS_BACKUP%
+)
+
+rem End of log management
+
+
+set CLUSTER_CONFIG_FILE=%RABBITMQ_BASE%\rabbitmq_cluster.config
+set CLUSTER_CONFIG=
+if not exist "%CLUSTER_CONFIG_FILE%" GOTO L1
+set CLUSTER_CONFIG=-rabbit cluster_config \""%CLUSTER_CONFIG_FILE:\=/%"\"
+:L1
+
+set MNESIA_DIR=%MNESIA_BASE%/%NODENAME%-mnesia
+
+
+if "%1" == "install" goto INSTALL_SERVICE
+for %%i in (start stop disable enable list remove) do if "%%i" == "%1" goto MODIFY_SERVICE
+
+echo.
+echo *********************
+echo Service control usage
+echo *********************
+echo.
+echo %~n0 help - Display this help
+echo %~n0 install - Install the %SERVICENAME% service
+echo %~n0 remove - Remove the %SERVICENAME% service
+echo.
+echo The following actions can also be accomplished by using
+echo Windows Services Management Console (services.msc):
+echo.
+echo %~n0 start - Start the %SERVICENAME% service
+echo %~n0 stop - Stop the %SERVICENAME% service
+echo %~n0 disable - Disable the %SERVICENAME% service
+echo %~n0 enable - Enable the %SERVICENAME% service
+echo.
+exit /B
+
+
+:INSTALL_SERVICE
+
+if not exist "%RABBITMQ_BASE%" (
+ echo Creating base directory %RABBITMQ_BASE% & md "%RABBITMQ_BASE%"
+)
+
+"%ERLANG_SERVICE_MANAGER_PATH%\erlsrv" list %SERVICENAME% 2>NUL 1>NUL
+if errorlevel 1 (
+ "%ERLANG_SERVICE_MANAGER_PATH%\erlsrv" add %SERVICENAME%
+) else (
+ echo %SERVICENAME% service is already present - only updating service parameters
+)
+
+set RABBIT_EBIN=%~dp0..\ebin
+
+set ERLANG_SERVICE_ARGUMENTS= ^
+-pa "%RABBIT_EBIN%" ^
+-boot start_sasl ^
+-s rabbit ^
++W w ^
++A30 ^
+-kernel inet_default_listen_options "[{nodelay,true},{sndbuf,16384},{recbuf,4096}]" ^
+-kernel inet_default_connect_options "[{nodelay,true}]" ^
+-rabbit tcp_listeners "[{\"%NODE_IP_ADDRESS%\",%NODE_PORT%}]" ^
+-kernel error_logger {file,\""%LOG_BASE%/%NODENAME%.log"\"} ^
+-sasl errlog_type error ^
+-sasl sasl_error_logger {file,\""%LOG_BASE%/%NODENAME%-sasl.log"\"} ^
+-os_mon start_cpu_sup true ^
+-os_mon start_disksup false ^
+-os_mon start_memsup true ^
+-os_mon start_os_sup false ^
+-os_mon memsup_system_only true ^
+-os_mon system_memory_high_watermark 0.95 ^
+-mnesia dir \""%MNESIA_DIR%"\" ^
+%CLUSTER_CONFIG% ^
+%RABBIT_ARGS% ^
+%*
+
+set ERLANG_SERVICE_ARGUMENTS=%ERLANG_SERVICE_ARGUMENTS:\=\\%
+set ERLANG_SERVICE_ARGUMENTS=%ERLANG_SERVICE_ARGUMENTS:"=\"%
+
+"%ERLANG_SERVICE_MANAGER_PATH%\erlsrv" set %SERVICENAME% ^
+-machine "%ERLANG_SERVICE_MANAGER_PATH%\erl.exe" ^
+-env ERL_CRASH_DUMP="%RABBITMQ_BASE_UNIX%/log" ^
+-workdir "%RABBITMQ_BASE%" ^
+-stopaction "rabbit:stop_and_halt()." ^
+-sname %NODENAME% ^
+%CONSOLE_FLAG% ^
+-args "%ERLANG_SERVICE_ARGUMENTS%" > NUL
+goto END
+
+
+:MODIFY_SERVICE
+
+"%ERLANG_SERVICE_MANAGER_PATH%\erlsrv" %1 %SERVICENAME%
+goto END
+
+
+:END \ No newline at end of file
diff --git a/scripts/rabbitmqctl b/scripts/rabbitmqctl
index 419dcf63..bf00a9c7 100755
--- a/scripts/rabbitmqctl
+++ b/scripts/rabbitmqctl
@@ -24,17 +24,10 @@
## Contributor(s): ______________________________________.
##
-[ "x" = "x$NODENAME" ] && NODENAME=rabbit
-MNESIA_BASE=/var/lib/rabbitmq/mnesia
-LOG_BASE=/var/log/rabbitmq
-ERL_ARGS=
-MNESIA_DIR=${MNESIA_BASE}/${NODENAME}
-
exec erl \
-pa "`dirname $0`/../ebin" \
-noinput \
-hidden \
- ${ERL_ARGS} \
-sname rabbitmqctl$$ \
-s rabbit_control \
-extra "$@"
diff --git a/src/rabbit_alarm.erl b/src/rabbit_alarm.erl
index c2d6aaff..6d65b3a4 100644
--- a/src/rabbit_alarm.erl
+++ b/src/rabbit_alarm.erl
@@ -50,22 +50,57 @@
%%----------------------------------------------------------------------------
start() ->
+ ok = alarm_handler:add_alarm_handler(?MODULE),
+ case whereis(memsup) of
+ undefined ->
+ Mod = case os:type() of
+ %% memsup doesn't take account of buffers or
+ %% cache when considering "free" memory -
+ %% therefore on Linux we can get memory alarms
+ %% very easily without any pressure existing on
+ %% memory at all. Therefore we need to use our
+ %% own simple memory monitor.
+ %%
+ {unix, linux} -> rabbit_memsup_linux;
+
+ %% Start memsup programmatically rather than via
+ %% the rabbitmq-server script. This is not quite
+ %% the right thing to do as os_mon checks to see
+ %% if memsup is available before starting it,
+ %% but as memsup is available everywhere (even
+ %% on VXWorks) it should be ok.
+ %%
+ %% One benefit of the programmatic startup is
+ %% that we can add our alarm_handler before
+ %% memsup is running, thus ensuring that we
+ %% notice memory alarms that go off on startup.
+ %%
+ _ -> memsup
+ end,
+ %% This is based on os_mon:childspec(memsup, true)
+ {ok, _} = supervisor:start_child(
+ os_mon_sup,
+ {memsup, {Mod, start_link, []},
+ permanent, 2000, worker, [Mod]}),
+ ok;
+ _ ->
+ ok
+ end,
%% The default memsup check interval is 1 minute, which is way too
- %% long - rabbit can gobble up all memory in a matter of
- %% seconds. Unfortunately the memory_check_interval configuration
- %% parameter and memsup:set_check_interval/1 function only provide
- %% a granularity of minutes. So we have to peel off one layer of
- %% the API to get to the underlying layer which operates at the
+ %% long - rabbit can gobble up all memory in a matter of seconds.
+ %% Unfortunately the memory_check_interval configuration parameter
+ %% and memsup:set_check_interval/1 function only provide a
+ %% granularity of minutes. So we have to peel off one layer of the
+ %% API to get to the underlying layer which operates at the
%% granularity of milliseconds.
%%
%% Note that the new setting will only take effect after the first
%% check has completed, i.e. after one minute. So if rabbit eats
%% all the memory within the first minute after startup then we
%% are out of luck.
- ok = os_mon:call(memsup, {set_check_interval, ?MEMSUP_CHECK_INTERVAL},
- infinity),
-
- ok = alarm_handler:add_alarm_handler(?MODULE).
+ ok = os_mon:call(memsup,
+ {set_check_interval, ?MEMSUP_CHECK_INTERVAL},
+ infinity).
stop() ->
ok = alarm_handler:delete_alarm_handler(?MODULE).
@@ -77,9 +112,7 @@ register(Pid, HighMemMFA) ->
%%----------------------------------------------------------------------------
init([]) ->
- HWM = system_memory_high_watermark(),
- {ok, #alarms{alertees = dict:new(),
- system_memory_high_watermark = HWM}}.
+ {ok, #alarms{alertees = dict:new()}}.
handle_call({register, Pid, HighMemMFA},
State = #alarms{alertees = Alertess}) ->
@@ -121,19 +154,6 @@ code_change(_OldVsn, State, _Extra) ->
%%----------------------------------------------------------------------------
-system_memory_high_watermark() ->
- %% When we register our alarm_handler, the
- %% system_memory_high_watermark alarm may already have gone
- %% off. How do we find out about that? Calling
- %% alarm_handler:get_alarms() would deadlock. So instead we ask
- %% memsup. Unfortunately that doesn't expose a suitable API, so we
- %% have to reach quite deeply into its internals.
- {dictionary, D} = process_info(whereis(memsup), dictionary),
- case lists:keysearch(system_memory_high_watermark, 1, D) of
- {value, {_, set}} -> true;
- _Other -> false
- end.
-
alert(Alert, Alertees) ->
dict:fold(fun (Pid, {M, F, A}, Acc) ->
ok = erlang:apply(M, F, A ++ [Pid, Alert]),
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl
index 2f7e58e0..b821fa0d 100644
--- a/src/rabbit_control.erl
+++ b/src/rabbit_control.erl
@@ -35,23 +35,40 @@
start() ->
FullCommand = init:get_plain_arguments(),
#params{quiet = Quiet, node = Node, command = Command, args = Args} =
- parse_args(FullCommand, #params{quiet = false, node = rabbit_misc:localnode(rabbit)}),
- Inform = case Quiet of
- true -> fun(_Format, _Data) -> ok end;
- false -> fun io:format/2
+ parse_args(FullCommand, #params{quiet = false,
+ node = rabbit_misc:localnode(rabbit)}),
+ Inform = case Quiet of
+ true -> fun(_Format, _Args1) -> ok end;
+ false -> fun(Format, Args1) ->
+ io:format(Format ++ " ...~n", Args1)
+ end
end,
+ %% The reason we don't use a try/catch here is that rpc:call turns
+ %% thrown errors into normal return values
case catch action(Command, Node, Args, Inform) of
ok ->
- Inform("done.~n", []),
+ case Quiet of
+ true -> ok;
+ false -> io:format("...done.~n")
+ end,
init:stop();
{'EXIT', {function_clause, [{?MODULE, action, _} | _]}} ->
- io:format("Error~nInvalid command ~p~n", [FullCommand]),
+ error("invalid command '~s'",
+ [lists:flatten(
+ rabbit_misc:intersperse(
+ " ", [atom_to_list(Command) | Args]))]),
usage();
+ {error, Reason} ->
+ error("~p", [Reason]),
+ halt(2);
Other ->
- io:format("Error~nrabbit_control action ~p failed:~n~p~n", [Command, Other]),
+ error("~p", [Other]),
halt(2)
end.
+error(Format, Args) ->
+ rabbit_misc:format_stderr("Error: " ++ Format ++ "~n", Args).
+
parse_args(["-n", NodeS | Args], Params) ->
Node = case lists:member($@, NodeS) of
true -> list_to_atom(NodeS);
@@ -109,86 +126,86 @@ output of hostname -s is usually the correct suffix to use after the \"@\" sign.
halt(1).
action(stop, Node, [], Inform) ->
- Inform("Stopping and halting node ~p ...~n", [Node]),
+ Inform("Stopping and halting node ~p", [Node]),
call(Node, {rabbit, stop_and_halt, []});
action(stop_app, Node, [], Inform) ->
- Inform("Stopping node ~p ...~n", [Node]),
+ Inform("Stopping node ~p", [Node]),
call(Node, {rabbit, stop, []});
action(start_app, Node, [], Inform) ->
- Inform("Starting node ~p ...~n", [Node]),
+ Inform("Starting node ~p", [Node]),
call(Node, {rabbit, start, []});
action(reset, Node, [], Inform) ->
- Inform("Resetting node ~p ...~n", [Node]),
+ Inform("Resetting node ~p", [Node]),
call(Node, {rabbit_mnesia, reset, []});
action(force_reset, Node, [], Inform) ->
- Inform("Forcefully resetting node ~p ...~n", [Node]),
+ Inform("Forcefully resetting node ~p", [Node]),
call(Node, {rabbit_mnesia, force_reset, []});
action(cluster, Node, ClusterNodeSs, Inform) ->
ClusterNodes = lists:map(fun list_to_atom/1, ClusterNodeSs),
- Inform("Clustering node ~p with ~p ...~n",
+ Inform("Clustering node ~p with ~p",
[Node, ClusterNodes]),
rpc_call(Node, rabbit_mnesia, cluster, [ClusterNodes]);
action(status, Node, [], Inform) ->
- Inform("Status of node ~p ...~n", [Node]),
+ Inform("Status of node ~p", [Node]),
Res = call(Node, {rabbit, status, []}),
io:format("~p~n", [Res]),
ok;
action(rotate_logs, Node, [], Inform) ->
- Inform("Reopening logs for node ~p ...~n", [Node]),
+ Inform("Reopening logs for node ~p", [Node]),
call(Node, {rabbit, rotate_logs, [""]});
action(rotate_logs, Node, Args = [Suffix], Inform) ->
- Inform("Rotating logs to files with suffix ~p ...~n", [Suffix]),
+ Inform("Rotating logs to files with suffix ~p", [Suffix]),
call(Node, {rabbit, rotate_logs, Args});
action(add_user, Node, Args = [Username, _Password], Inform) ->
- Inform("Creating user ~p ...~n", [Username]),
+ Inform("Creating user ~p", [Username]),
call(Node, {rabbit_access_control, add_user, Args});
action(delete_user, Node, Args = [_Username], Inform) ->
- Inform("Deleting user ~p ...~n", Args),
+ Inform("Deleting user ~p", Args),
call(Node, {rabbit_access_control, delete_user, Args});
action(change_password, Node, Args = [Username, _Newpassword], Inform) ->
- Inform("Changing password for user ~p ...~n", [Username]),
+ Inform("Changing password for user ~p", [Username]),
call(Node, {rabbit_access_control, change_password, Args});
action(list_users, Node, [], Inform) ->
- Inform("Listing users ...~n", []),
+ Inform("Listing users", []),
display_list(call(Node, {rabbit_access_control, list_users, []}));
action(add_vhost, Node, Args = [_VHostPath], Inform) ->
- Inform("Creating vhost ~p ...~n", Args),
+ Inform("Creating vhost ~p", Args),
call(Node, {rabbit_access_control, add_vhost, Args});
action(delete_vhost, Node, Args = [_VHostPath], Inform) ->
- Inform("Deleting vhost ~p ...~n", Args),
+ Inform("Deleting vhost ~p", Args),
call(Node, {rabbit_access_control, delete_vhost, Args});
action(list_vhosts, Node, [], Inform) ->
- Inform("Listing vhosts ...~n", []),
+ Inform("Listing vhosts", []),
display_list(call(Node, {rabbit_access_control, list_vhosts, []}));
action(map_user_vhost, Node, Args = [_Username, _VHostPath], Inform) ->
- Inform("Mapping user ~p to vhost ~p ...~n", Args),
+ Inform("Mapping user ~p to vhost ~p", Args),
call(Node, {rabbit_access_control, map_user_vhost, Args});
action(unmap_user_vhost, Node, Args = [_Username, _VHostPath], Inform) ->
- Inform("Unmapping user ~p from vhost ~p ...~n", Args),
+ Inform("Unmapping user ~p from vhost ~p", Args),
call(Node, {rabbit_access_control, unmap_user_vhost, Args});
action(list_user_vhosts, Node, Args = [_Username], Inform) ->
- Inform("Listing vhosts for user ~p...~n", Args),
+ Inform("Listing vhosts for user ~p", Args),
display_list(call(Node, {rabbit_access_control, list_user_vhosts, Args}));
action(list_vhost_users, Node, Args = [_VHostPath], Inform) ->
- Inform("Listing users for vhosts ~p...~n", Args),
+ Inform("Listing users for vhosts ~p", Args),
display_list(call(Node, {rabbit_access_control, list_vhost_users, Args})).
display_list(L) when is_list(L) ->
diff --git a/src/rabbit_log.erl b/src/rabbit_log.erl
index a8f839f0..b4729230 100644
--- a/src/rabbit_log.erl
+++ b/src/rabbit_log.erl
@@ -32,7 +32,7 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
--export([debug/1, debug/2, info/1, info/2,
+-export([debug/1, debug/2, message/4, info/1, info/2,
warning/1, warning/2, error/1, error/2]).
-import(io).
@@ -67,6 +67,10 @@ debug(Fmt) ->
debug(Fmt, Args) when is_list(Args) ->
gen_server:cast(?SERVER, {debug, Fmt, Args}).
+message(Direction, Channel, MethodRecord, Content) ->
+ gen_server:cast(?SERVER,
+ {message, Direction, Channel, MethodRecord, Content}).
+
info(Fmt) ->
gen_server:cast(?SERVER, {info, Fmt}).
@@ -100,6 +104,14 @@ handle_cast({debug, Fmt, Args}, State) ->
io:format("debug:: "), io:format(Fmt, Args),
error_logger:info_msg("debug:: " ++ Fmt, Args),
{noreply, State};
+handle_cast({message, Direction, Channel, MethodRecord, Content}, State) ->
+ io:format("~s ch~p ~p~n",
+ [case Direction of
+ in -> "-->";
+ out -> "<--" end,
+ Channel,
+ {MethodRecord, Content}]),
+ {noreply, State};
handle_cast({info, Fmt}, State) ->
error_logger:info_msg(Fmt),
{noreply, State};
diff --git a/src/rabbit_memsup_linux.erl b/src/rabbit_memsup_linux.erl
new file mode 100644
index 00000000..b77ffcab
--- /dev/null
+++ b/src/rabbit_memsup_linux.erl
@@ -0,0 +1,150 @@
+%% 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): ______________________________________.
+%%
+
+-module(rabbit_memsup_linux).
+
+-behaviour(gen_server).
+
+-export([start_link/0]).
+
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+-export([update/0]).
+
+-define(SERVER, memsup). %% must be the same as the standard memsup
+
+-define(DEFAULT_MEMORY_CHECK_INTERVAL, 1000).
+
+-record(state, {memory_fraction, alarmed, timeout, timer}).
+
+%%----------------------------------------------------------------------------
+
+-ifdef(use_specs).
+
+-spec(start_link/0 :: () -> {'ok', pid()} | 'ignore' | {'error', any()}).
+-spec(update/0 :: () -> 'ok').
+
+-endif.
+
+%%----------------------------------------------------------------------------
+
+start_link() ->
+ gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
+
+
+update() ->
+ gen_server:cast(?SERVER, update).
+
+%%----------------------------------------------------------------------------
+
+init(_Args) ->
+ Fraction = os_mon:get_env(memsup, system_memory_high_watermark),
+ TRef = start_timer(?DEFAULT_MEMORY_CHECK_INTERVAL),
+ {ok, #state{alarmed = false,
+ memory_fraction = Fraction,
+ timeout = ?DEFAULT_MEMORY_CHECK_INTERVAL,
+ timer = TRef}}.
+
+start_timer(Timeout) ->
+ {ok, TRef} = timer:apply_interval(Timeout, ?MODULE, update, []),
+ TRef.
+
+%% Export the same API as the real memsup. Note that
+%% get_sysmem_high_watermark gives an int in the range 0 - 100, while
+%% set_sysmem_high_watermark takes a float in the range 0.0 - 1.0.
+handle_call(get_sysmem_high_watermark, _From, State) ->
+ {reply, trunc(100 * State#state.memory_fraction), State};
+
+handle_call({set_sysmem_high_watermark, Float}, _From, State) ->
+ {reply, ok, State#state{memory_fraction = Float}};
+
+handle_call(get_check_interval, _From, State) ->
+ {reply, State#state.timeout, State};
+
+handle_call({set_check_interval, Timeout}, _From, State) ->
+ {ok, cancel} = timer:cancel(State#state.timer),
+ {reply, ok, State#state{timeout = Timeout, timer = start_timer(Timeout)}};
+
+handle_call(_Request, _From, State) ->
+ {noreply, State}.
+
+handle_cast(update, State = #state{alarmed = Alarmed,
+ memory_fraction = MemoryFraction}) ->
+ File = read_proc_file("/proc/meminfo"),
+ Lines = string:tokens(File, "\n"),
+ Dict = dict:from_list(lists:map(fun parse_line/1, Lines)),
+ MemTotal = dict:fetch('MemTotal', Dict),
+ MemUsed = MemTotal
+ - dict:fetch('MemFree', Dict)
+ - dict:fetch('Buffers', Dict)
+ - dict:fetch('Cached', Dict),
+ NewAlarmed = MemUsed / MemTotal > MemoryFraction,
+ case {Alarmed, NewAlarmed} of
+ {false, true} ->
+ alarm_handler:set_alarm({system_memory_high_watermark, []});
+ {true, false} ->
+ alarm_handler:clear_alarm(system_memory_high_watermark);
+ _ ->
+ ok
+ end,
+ {noreply, State#state{alarmed = NewAlarmed}};
+
+handle_cast(_Request, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%%----------------------------------------------------------------------------
+
+-define(BUFFER_SIZE, 1024).
+
+%% file:read_file does not work on files in /proc as it seems to get
+%% the size of the file first and then read that many bytes. But files
+%% in /proc always have length 0, we just have to read until we get
+%% eof.
+read_proc_file(File) ->
+ {ok, IoDevice} = file:open(File, [read, raw]),
+ Res = read_proc_file(IoDevice, []),
+ file:close(IoDevice),
+ lists:flatten(lists:reverse(Res)).
+
+read_proc_file(IoDevice, Acc) ->
+ case file:read(IoDevice, ?BUFFER_SIZE) of
+ {ok, Res} -> read_proc_file(IoDevice, [Res | Acc]);
+ eof -> Acc
+ end.
+
+%% A line looks like "FooBar: 123456 kB"
+parse_line(Line) ->
+ [Name, Value | _] = string:tokens(Line, ": "),
+ {list_to_atom(Name), list_to_integer(Value)}.
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index cdd80594..6be73e43 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -43,6 +43,7 @@
-export([guid/0, string_guid/1, binstring_guid/1]).
-export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]).
-export([append_file/2, ensure_parent_dirs_exist/1]).
+-export([format_stderr/2]).
-import(mnesia).
-import(lists).
@@ -99,6 +100,7 @@
-spec(dirty_dump_log/1 :: (string()) -> 'ok' | {'error', any()}).
-spec(append_file/2 :: (string(), string()) -> 'ok' | {'error', any()}).
-spec(ensure_parent_dirs_exist/1 :: (string()) -> 'ok').
+-spec(format_stderr/2 :: (string(), [any()]) -> 'true').
-endif.
@@ -377,3 +379,8 @@ ensure_parent_dirs_exist(Filename) ->
{error, Reason} ->
throw({error, {cannot_create_parent_dirs, Filename, Reason}})
end.
+
+format_stderr(Fmt, Args) ->
+ Port = open_port({fd, 0, 2}, [out]),
+ port_command(Port, io_lib:format(Fmt, Args)),
+ port_close(Port).
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_multi.erl b/src/rabbit_multi.erl
index c6a7e920..b99dfbc1 100644
--- a/src/rabbit_multi.erl
+++ b/src/rabbit_multi.erl
@@ -46,18 +46,22 @@ start() ->
io:format("done.~n"),
init:stop();
{'EXIT', {function_clause, [{?MODULE, action, _} | _]}} ->
- io:format("Invalid command ~p~n", [FullCommand]),
+ error("invalid command '~s'",
+ [lists:flatten(
+ rabbit_misc:intersperse(" ", FullCommand))]),
usage();
timeout ->
- io:format("timeout starting some nodes.~n"),
+ error("timeout starting some nodes.", []),
halt(1);
Other ->
- io:format("~nrabbit_multi action ~p failed:~n~p~n",
- [Command, Other]),
+ error("~p", [Other]),
halt(2)
end
end.
+error(Format, Args) ->
+ rabbit_misc:format_stderr("Error: " ++ Format ++ "~n", Args).
+
parse_args([Command | Args]) ->
{list_to_atom(Command), Args}.
@@ -223,8 +227,7 @@ write_pids_file(Pids) ->
{ok, Device} ->
Device;
{error, Reason} ->
- throw({error, {cannot_create_pids_file,
- FileName, Reason}})
+ throw({cannot_create_pids_file, FileName, Reason})
end,
try
ok = io:write(Handle, Pids),
@@ -233,8 +236,7 @@ write_pids_file(Pids) ->
case file:close(Handle) of
ok -> ok;
{error, Reason1} ->
- throw({error, {cannot_create_pids_file,
- FileName, Reason1}})
+ throw({cannot_create_pids_file, FileName, Reason1})
end
end,
ok.
@@ -244,8 +246,7 @@ delete_pids_file() ->
case file:delete(FileName) of
ok -> ok;
{error, enoent} -> ok;
- {error, Reason} -> throw({error, {cannot_delete_pids_file,
- FileName, Reason}})
+ {error, Reason} -> throw({cannot_delete_pids_file, FileName, Reason})
end.
read_pids_file() ->
@@ -253,8 +254,7 @@ read_pids_file() ->
case file:consult(FileName) of
{ok, [Pids]} -> Pids;
{error, enoent} -> [];
- {error, Reason} -> throw({error, {cannot_read_pids_file,
- FileName, Reason}})
+ {error, Reason} -> throw({cannot_read_pids_file, FileName, Reason})
end.
kill_wait(Pid, TimeLeft, Forceful) when TimeLeft < 0 ->
diff --git a/src/rabbit_router.erl b/src/rabbit_router.erl
index a2337647..58eb5b54 100644
--- a/src/rabbit_router.erl
+++ b/src/rabbit_router.erl
@@ -36,6 +36,9 @@
-define(SERVER, ?MODULE).
+%% cross-node routing optimisation is disabled because of bug 19758.
+-define(BUG19758, true).
+
%%----------------------------------------------------------------------------
-ifdef(use_specs).
@@ -51,6 +54,14 @@
start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
+-ifdef(BUG19758).
+
+deliver(QPids, Mandatory, Immediate, Txn, Message) ->
+ check_delivery(Mandatory, Immediate,
+ run_bindings(QPids, Mandatory, Immediate, Txn, Message)).
+
+-else.
+
deliver(QPids, Mandatory, Immediate, Txn, Message) ->
%% we reduce inter-node traffic by grouping the qpids by node and
%% only delivering one copy of the message to each node involved,
@@ -114,6 +125,8 @@ deliver_per_node(NodeQPids, Mandatory, Immediate,
R),
check_delivery(Mandatory, Immediate, {Routed, lists:append(Handled)}).
+-endif.
+
%%--------------------------------------------------------------------
init([]) ->
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index 83e28c2f..d7c8bddf 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, []),