summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Joubert <emile@lshift.net>2008-11-09 23:32:13 +0000
committerEmile Joubert <emile@lshift.net>2008-11-09 23:32:13 +0000
commitc1b8b1d3a075df2514b2eed9f15ecf2593fbd265 (patch)
tree603fba8a5d4ae21bc299f0d3e7f3934db76e42a1
parent4c183564e75aecd662bcc73268f2d817c8b4cdfe (diff)
parentdd69094bd1e34c03764c4bc0c4398bdf2dabca7f (diff)
downloadrabbitmq-server-c1b8b1d3a075df2514b2eed9f15ecf2593fbd265.tar.gz
Merged bug18381 into bug19684
-rw-r--r--packaging/Makefile3
-rwxr-xr-xpackaging/checks.sh45
-rw-r--r--packaging/debs/Debian/Makefile1
-rw-r--r--packaging/windows/Makefile4
-rw-r--r--packaging/windows/rabbitmq-service.pod138
-rwxr-xr-xscripts/rabbitmq-service.bat190
-rw-r--r--src/rabbit_amqqueue.erl18
-rw-r--r--src/rabbit_control.erl29
-rw-r--r--src/rabbit_misc.erl15
9 files changed, 393 insertions, 50 deletions
diff --git a/packaging/Makefile b/packaging/Makefile
deleted file mode 100644
index 44a9b328..00000000
--- a/packaging/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
-check_tools:
- @sh ./checks.sh
- @echo All the needed tools seem to be installed, great!
diff --git a/packaging/checks.sh b/packaging/checks.sh
deleted file mode 100755
index 63e88701..00000000
--- a/packaging/checks.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#! /bin/sh
-
-# We check for the presence of the tools necessary to build a release on a
-# Debian based OS.
-
-TOOLS_STOP=0
-
-checker () {
- if [ ! `which $1` ]
- then
- echo "$1 is missing, please install it"
- TOOLS_STOP=1
- NEW_NAME=`echo $1 | sed -e 's/-/_/g'`
- eval "$NEW_NAME=1"
- else
- echo "$1 found"
- fi
-};
-
-echo ~~~~~~~~~~~~ Looking for mandatory programs ~~~~~~~~~~~~
-
-for i in cdbs-edit-patch reprepro rpm elinks wget zip gpg rsync
-do
- checker $i
-done
-echo ~~~~~~~~~~~~~~~~~~~~~~~~~~ DONE ~~~~~~~~~~~~~~~~~~~~~~~
-
-if [ 1 = $TOOLS_STOP ]
-then
- [ $cdbs_edit_patch ] && cdbs_edit_patch="cdbs "
- [ $reprepro ] && reprepro="reprepro "
- [ $rpm ] && rpm="rpm "
- [ $elinks ] && elinks="elinks "
- [ $wget ] && wget="wget "
- [ $zip ] && zip="zip "
- [ $gpg ] && gpg="gpg "
- [ $rsync ] && rsync="rsync "
-
- echo
- echo We suggest you run the command
- echo "apt-get install ${cdbs_edit_patch}${reprepro}${rpm}${elinks}${wget}${zip}${gpg}${rsync}"
- echo
-fi
-
-exit $TOOLS_STOP
diff --git a/packaging/debs/Debian/Makefile b/packaging/debs/Debian/Makefile
index 3e74cb52..9479feb0 100644
--- a/packaging/debs/Debian/Makefile
+++ b/packaging/debs/Debian/Makefile
@@ -16,7 +16,6 @@ all:
@echo 'Please choose a target from the Makefile.'
package: clean
- make -C ../.. check_tools
cp $(TARBALL_DIR)/$(TARBALL) $(DEBIAN_ORIG_TARBALL)
tar -zxvf $(DEBIAN_ORIG_TARBALL)
cp -r debian $(UNPACKED_DIR)
diff --git a/packaging/windows/Makefile b/packaging/windows/Makefile
index f9437da7..b052f40a 100644
--- a/packaging/windows/Makefile
+++ b/packaging/windows/Makefile
@@ -2,6 +2,7 @@ VERSION=0.0.0
SOURCE_DIR=rabbitmq-server-$(VERSION)
TARGET_DIR=rabbitmq_server-$(VERSION)
TARGET_ZIP=rabbitmq-server-windows-$(VERSION)
+TOP_DIR=$(shell pwd)
dist:
make -C ../.. VERSION=$(VERSION) srcdist
@@ -10,6 +11,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 +20,8 @@ dist:
rm -rf $(SOURCE_DIR)/docs
mv $(SOURCE_DIR) $(TARGET_DIR)
+ pod2text --loose $(TOP_DIR)/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..d2ee48f9
--- /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<rabbitctl>.
+
+=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-service.bat b/scripts/rabbitmq-service.bat
new file mode 100755
index 00000000..5a176726
--- /dev/null
+++ b/scripts/rabbitmq-service.bat
@@ -0,0 +1,190 @@
+@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_TMP=%~dp0%
+set RABBIT_EBIN=%RABBIT_EBIN_TMP:\=/%../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/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl
index f241e695..6f846daf 100644
--- a/src/rabbit_amqqueue.erl
+++ b/src/rabbit_amqqueue.erl
@@ -35,6 +35,7 @@
-export([notify_sent/2]).
-export([commit_all/2, rollback_all/2, notify_down_all/2]).
-export([on_node_down/1]).
+-export([info_queue_sorted/1, info_queue_sorted/2]).
-import(mnesia).
-import(gen_server).
@@ -104,6 +105,8 @@
-spec(internal_delete/1 :: (queue_name()) -> 'ok' | not_found()).
-spec(on_node_down/1 :: (node()) -> 'ok').
-spec(pseudo_queue/2 :: (binary(), pid()) -> amqqueue()).
+-spec(info_queue_sorted/2 :: (info_key(), non_neg_integer()) -> [{amqqueue(), info()}]).
+-spec(info_queue_sorted/1 :: (info_key()) -> [{amqqueue(), info()}]).
-endif.
@@ -335,3 +338,18 @@ safe_pmap_ok(H, F, L) ->
[] -> ok;
Errors -> {error, Errors}
end.
+
+
+info_lookup({#amqqueue{}, InfoTupleList}, InfoKey) ->
+ case lists:keysearch(InfoKey, 1, InfoTupleList) of
+ false -> {error, not_found};
+ {value, {InfoKey, InfoValue}} -> InfoValue
+ end.
+
+%% TODO: avoid sorting if Length is much less than the number of queues
+info_queue_sorted(InfoKey) ->
+ lists:sort(fun(A, B) -> info_lookup(A, InfoKey) > info_lookup(B, InfoKey) end,
+ rabbit_amqqueue:info_all()).
+info_queue_sorted(InfoKey, Length) ->
+ lists:sublist(info_queue_sorted(InfoKey), Length).
+
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl
index bc588279..6589c384 100644
--- a/src/rabbit_control.erl
+++ b/src/rabbit_control.erl
@@ -89,6 +89,12 @@ Available commands:
list_user_vhosts <UserName>
list_vhost_users <VHostPath>
+ set_memory_threshold <Percentage>
+ get_memory_consumption
+
+ list_queues
+ list_deepest_queues
+
<node> should be the name of the master node of the RabbitMQ cluster. It
defaults to the node named \"rabbit\" on the local host. On a host named
\"server.example.com\", the master node will usually be rabbit@server (unless
@@ -179,7 +185,28 @@ action(list_user_vhosts, Node, Args = [_Username]) ->
action(list_vhost_users, Node, Args = [_VHostPath]) ->
io:format("Listing users for vhosts ~p...", Args),
- display_list(call(Node, {rabbit_access_control, list_vhost_users, Args})).
+ display_list(call(Node, {rabbit_access_control, list_vhost_users, Args}));
+
+action(set_memory_threshold, Node, Args) ->
+ io:format("% Setting memory threshold to ~p ...~n", Args),
+ rpc_call(Node, rabbit_misc, set_memory_threshold, Args);
+
+action(get_memory_consumption, Node, []) ->
+ io:format("% Getting memory consumption ...~n", []),
+ Res = rpc_call(Node, rabbit_misc, get_memory_consumption, []),
+ io:format("~p~n", [Res]);
+
+action(list_queues, Node, []) ->
+ io:format("Listing all queues ..."),
+ Res = rpc_call(Node, rabbit_amqqueue, info_all, []),
+ io:format("~p~n", [Res]),
+ ok;
+
+action(list_deepest_queues, Node, Args = [Depth]) ->
+ io:format("Listing ~p deepest queues ...~n", Args),
+ Res = rpc_call(Node, rabbit_amqqueue, info_queue_sorted, [messages, list_to_integer(Depth)]),
+ io:format("~p~n", [Res]),
+ ok.
display_list(L) when is_list(L) ->
lists:foreach(fun (I) ->
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index 7638af58..a807c6e9 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]).
+-export([set_memory_threshold/1, get_memory_consumption/0]).
-import(mnesia).
-import(lists).
@@ -99,6 +100,8 @@
-spec(dirty_dump_log/1 :: (string()) -> 'ok' | {'error', any()}).
-spec(append_file/2 :: (string(), string()) -> 'ok' | {'error', any()}).
+-spec(get_memory_consumption/0 :: () -> ({non_neg_integer(), non_neg_integer()})).
+-spec(set_memory_threshold/1 :: (string()) -> 'ok' | {'error', any()}).
-endif.
%%----------------------------------------------------------------------------
@@ -369,3 +372,15 @@ append_file(File, _, Suffix) ->
{ok, Data} -> file:write_file([File, Suffix], Data, [append]);
Error -> Error
end.
+
+set_memory_threshold(Level) ->
+ case Res = string:to_float(Level) of
+ {error, _} -> Res;
+ {_Percentage, [_]} -> {error, unexpected_suffix};
+ {Percentage, _} -> memsup:set_sysmem_high_watermark(Percentage)
+ end.
+
+get_memory_consumption() ->
+ {Total, Allocated, _Worst} = memsup:get_memory_data(),
+ {Total, Allocated}.
+