diff options
| author | Diana Corbacho <diana@rabbitmq.com> | 2017-05-03 12:29:52 +0100 |
|---|---|---|
| committer | Diana Corbacho <diana@rabbitmq.com> | 2017-05-03 12:29:52 +0100 |
| commit | 6b13679b725ec12aee2569f07ac15618eb99a34b (patch) | |
| tree | f29e1d7e3d66cbb80c6a3c3c92a81e3506866ab3 /scripts | |
| parent | f580a7652166a4836b0fbbe881c3f6e6a5b49f36 (diff) | |
| parent | 8cedd3f53a14e45ccc68868bbc6401bb321ee50f (diff) | |
| download | rabbitmq-server-git-6b13679b725ec12aee2569f07ac15618eb99a34b.tar.gz | |
Merge remote-tracking branch 'origin/stable'
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/rabbitmq-server | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index 41d1a81332..a318b55d75 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/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 @@ -12,9 +12,11 @@ ## The Original Code is RabbitMQ. ## ## The Initial Developer of the Original Code is GoPivotal, Inc. -## Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved. +## Copyright (c) 2007-2017 Pivotal Software, Inc. All rights reserved. ## +set -e + # Get default settings with user overrides for (RABBITMQ_)<var_name> # Non-empty defaults should be set in rabbitmq-env . `dirname $0`/rabbitmq-env @@ -278,21 +280,38 @@ else # The Erlang VM should ignore SIGINT. RABBITMQ_SERVER_START_ARGS="${RABBITMQ_SERVER_START_ARGS} ${RABBITMQ_IGNORE_SIGINT_FLAG}" - # Signal handlers. They all stop RabbitMQ properly (using - # rabbitmqctl stop). Depending on the signal, this script will exit - # with a non-zero error code: + # Signal handlers. They all stop RabbitMQ properly, using + # rabbitmqctl stop. This script will exit with different exit codes: # SIGHUP SIGTERM SIGTSTP - # They are considered a normal process termination, so the script - # exits with 0. + # Exits 0 since this is considered a normal process termination. # SIGINT - # They are considered an abnormal process termination, the script - # exits with the job exit code. + # Exits 128 + $signal_number where $signal_number is 2 for SIGINT (see + # http://pubs.opengroup.org/onlinepubs/009695399/utilities/kill.html). + # This is considered an abnormal process termination. Normally, we + # don't need to specify this exit code because the shell propagates it. + # Unfortunately, the signal handler doesn't work as expected in Dash, + # thus we need to explicitely restate the exit code. trap "stop_rabbitmq_server; exit 0" HUP TERM TSTP - trap "stop_rabbitmq_server" INT + trap "stop_rabbitmq_server; exit 130" INT start_rabbitmq_server "$@" & + rabbitmq_server_pid=$! # Block until RabbitMQ exits or a signal is caught. # Waits for last command (which is start_rabbitmq_server) - wait $! + # + # The "|| true" is here to work around an issue with Dash. Normally + # in a Bourne shell, if `wait` is interrupted by a signal, the + # signal handlers defined above are executed and the script + # terminates with the exit code of `wait` (unless the signal handler + # overrides that). + # In the case of Dash, it looks like `set -e` (set at the beginning + # of this script) gets precedence over signal handling. Therefore, + # when `wait` is interrupted, its exit code is non-zero and because + # of `set -e`, the script terminates immediately without running the + # signal handler. To work around this issue, we use "|| true" to + # force that statement to succeed and the signal handler to properly + # execute. Because the statement below has an exit code of 0, the + # signal handler has to restate the expected exit code. + wait $rabbitmq_server_pid || true fi |
