From 95a7ba33b5177763a52d74380fe80b807ee03191 Mon Sep 17 00:00:00 2001 From: Alexandru Scvortov Date: Tue, 25 Oct 2011 15:45:13 +0100 Subject: rebase on default --- docs/rabbitmqctl.1.xml | 8 +++++++- packaging/common/rabbitmq-server.init | 2 +- src/rabbit_control.erl | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/rabbitmqctl.1.xml b/docs/rabbitmqctl.1.xml index 662a36c7..f21888bd 100644 --- a/docs/rabbitmqctl.1.xml +++ b/docs/rabbitmqctl.1.xml @@ -103,7 +103,7 @@ - stop + stop pid_file Stops the Erlang node on which RabbitMQ is running. To @@ -111,6 +111,12 @@ the Server in the installation guide. + + If a is specified, also waits + for the process specified there to terminate. See the + description of the command below + for details on this file. + For example: rabbitmqctl stop diff --git a/packaging/common/rabbitmq-server.init b/packaging/common/rabbitmq-server.init index 15fd5d5b..450cac15 100644 --- a/packaging/common/rabbitmq-server.init +++ b/packaging/common/rabbitmq-server.init @@ -81,7 +81,7 @@ stop_rabbitmq () { status_rabbitmq quiet if [ $RETVAL = 0 ] ; then set +e - $CONTROL stop > ${INIT_LOG_DIR}/shutdown_log 2> ${INIT_LOG_DIR}/shutdown_err + $CONTROL stop ${PID_FILE} > ${INIT_LOG_DIR}/shutdown_log 2> ${INIT_LOG_DIR}/shutdown_err RETVAL=$? set -e if [ $RETVAL = 0 ] ; then diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 905e4fd0..cef5fd67 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -161,6 +161,10 @@ usage() -> %%---------------------------------------------------------------------------- +action(stop, Node, [PidFile], _Opts, Inform) -> + action(stop, Node, [], _Opts, Inform), + wait_for_process_death(PidFile); + action(stop, Node, [], _Opts, Inform) -> Inform("Stopping and halting node ~p", [Node]), call(Node, {rabbit, stop_and_halt, []}); @@ -376,6 +380,20 @@ wait_for_application(Node, Pid) -> false -> {error, process_not_running} end. +wait_for_process_death(PidFile) -> + Pid = case file:read_file(PidFile) of + {ok, Bin} -> string:strip(binary_to_list(Bin), right, $\n); + {error, _} = E -> exit({error, {could_not_read_pid, E}}) + end, + wait_for_process_death1(Pid). + +wait_for_process_death1(Pid) -> + case process_up(Pid) of + true -> timer:sleep(1000), + wait_for_process_death1(Pid); + false -> ok + end. + wait_and_read_pid_file(PidFile) -> case file:read_file(PidFile) of {ok, Bin} -> string:strip(binary_to_list(Bin), right, $\n); -- cgit v1.2.1