diff options
author | Emile Joubert <emile@rabbitmq.com> | 2011-10-31 16:35:29 +0000 |
---|---|---|
committer | Emile Joubert <emile@rabbitmq.com> | 2011-10-31 16:35:29 +0000 |
commit | 9d851e0ab750cc154cb418fff6e6efa4241ee00e (patch) | |
tree | 99b5bd6fb921724a17f3309f0efadfb801690265 | |
parent | 45adb5ec32c09f6cc8e105d55d86b9d07ddebb39 (diff) | |
parent | 3eb9a0288963d29689e47232a99e0ac5861e6500 (diff) | |
download | rabbitmq-server-9d851e0ab750cc154cb418fff6e6efa4241ee00e.tar.gz |
Merged bug24517 into default
-rw-r--r-- | docs/rabbitmqctl.1.xml | 8 | ||||
-rw-r--r-- | packaging/common/rabbitmq-server.init | 2 | ||||
-rw-r--r-- | src/rabbit_control.erl | 43 |
3 files changed, 41 insertions, 12 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 @@ <variablelist> <varlistentry> - <term><cmdsynopsis><command>stop</command></cmdsynopsis></term> + <term><cmdsynopsis><command>stop</command> <arg choice="opt"><replaceable>pid_file</replaceable></arg></cmdsynopsis></term> <listitem> <para> Stops the Erlang node on which RabbitMQ is running. To @@ -111,6 +111,12 @@ the Server</citetitle> in the <ulink url="http://www.rabbitmq.com/install.html">installation guide</ulink>. </para> + <para> + If a <option>pid_file</option> is specified, also waits + for the process specified there to terminate. See the + description of the <option>wait</option> command below + for details on this file. + </para> <para role="example-prefix">For example:</para> <screen role="example">rabbitmqctl stop</screen> <para role="example"> diff --git a/packaging/common/rabbitmq-server.init b/packaging/common/rabbitmq-server.init index c59af6c1..4084d8c7 100644 --- a/packaging/common/rabbitmq-server.init +++ b/packaging/common/rabbitmq-server.init @@ -83,7 +83,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 66a5ab5b..fa8dd262 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -20,6 +20,7 @@ -export([start/0, stop/0, action/5, diagnostics/1]). -define(RPC_TIMEOUT, infinity). +-define(EXTERNAL_CHECK_INTERVAL, 1000). -define(QUIET_OPT, "-q"). -define(NODE_OPT, "-n"). @@ -161,9 +162,16 @@ usage() -> %%---------------------------------------------------------------------------- -action(stop, Node, [], _Opts, Inform) -> +action(stop, Node, Args, _Opts, Inform) -> Inform("Stopping and halting node ~p", [Node]), - call(Node, {rabbit, stop_and_halt, []}); + Res = call(Node, {rabbit, stop_and_halt, []}), + case {Res, Args} of + {ok, [PidFile]} -> wait_for_process_death( + read_pid_file(PidFile, false)); + {ok, [_, _| _]} -> exit({badarg, Args}); + _ -> ok + end, + Res; action(stop_app, Node, [], _Opts, Inform) -> Inform("Stopping node ~p", [Node]), @@ -365,7 +373,7 @@ action(report, Node, _Args, _Opts, Inform) -> %%---------------------------------------------------------------------------- wait_for_application(Node, PidFile, Inform) -> - Pid = wait_and_read_pid_file(PidFile), + Pid = read_pid_file(PidFile, true), Inform("pid is ~s", [Pid]), wait_for_application(Node, Pid). @@ -373,18 +381,33 @@ wait_for_application(Node, Pid) -> case process_up(Pid) of true -> case rabbit:is_running(Node) of true -> ok; - false -> timer:sleep(1000), + false -> timer:sleep(?EXTERNAL_CHECK_INTERVAL), wait_for_application(Node, Pid) end; false -> {error, process_not_running} end. -wait_and_read_pid_file(PidFile) -> - case file:read_file(PidFile) of - {ok, Bin} -> string:strip(binary_to_list(Bin), right, $\n); - {error, enoent} -> timer:sleep(500), - wait_and_read_pid_file(PidFile); - {error, _} = E -> exit({error, {could_not_read_pid, E}}) +wait_for_process_death(Pid) -> + case process_up(Pid) of + true -> timer:sleep(?EXTERNAL_CHECK_INTERVAL), + wait_for_process_death(Pid); + false -> ok + end. + +read_pid_file(PidFile, Wait) -> + case {file:read_file(PidFile), Wait} of + {{ok, Bin}, _} -> + S = string:strip(binary_to_list(Bin), right, $\n), + try list_to_integer(S) + catch error:badarg -> + exit({error, {garbage_in_pid_file, PidFile}}) + end, + S; + {{error, enoent}, true} -> + timer:sleep(?EXTERNAL_CHECK_INTERVAL), + read_pid_file(PidFile, Wait); + {{error, _} = E, _} -> + exit({error, {could_not_read_pid, E}}) end. % Test using some OS clunkiness since we shouldn't trust |