|
1 |
| -#!/bin/sh -e |
| 1 | +#!/bin/sh |
2 | 2 | ## The contents of this file are subject to the Mozilla Public License
|
3 | 3 | ## Version 1.1 (the "License"); you may not use this file except in
|
4 | 4 | ## compliance with the License. You may obtain a copy of the License
|
|
12 | 12 | ## The Original Code is RabbitMQ.
|
13 | 13 | ##
|
14 | 14 | ## The Initial Developer of the Original Code is GoPivotal, Inc.
|
15 |
| -## Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved. |
| 15 | +## Copyright (c) 2007-2017 Pivotal Software, Inc. All rights reserved. |
16 | 16 | ##
|
17 | 17 |
|
| 18 | +set -e |
| 19 | + |
18 | 20 | # Get default settings with user overrides for (RABBITMQ_)<var_name>
|
19 | 21 | # Non-empty defaults should be set in rabbitmq-env
|
20 | 22 | . `dirname $0`/rabbitmq-env
|
@@ -233,21 +235,38 @@ else
|
233 | 235 | # The Erlang VM should ignore SIGINT.
|
234 | 236 | RABBITMQ_SERVER_START_ARGS="${RABBITMQ_SERVER_START_ARGS} ${RABBITMQ_IGNORE_SIGINT_FLAG}"
|
235 | 237 |
|
236 |
| - # Signal handlers. They all stop RabbitMQ properly (using |
237 |
| - # rabbitmqctl stop). Depending on the signal, this script will exit |
238 |
| - # with a non-zero error code: |
| 238 | + # Signal handlers. They all stop RabbitMQ properly, using |
| 239 | + # rabbitmqctl stop. This script will exit with different exit codes: |
239 | 240 | # SIGHUP SIGTERM SIGTSTP
|
240 |
| - # They are considered a normal process termination, so the script |
241 |
| - # exits with 0. |
| 241 | + # Exits 0 since this is considered a normal process termination. |
242 | 242 | # SIGINT
|
243 |
| - # They are considered an abnormal process termination, the script |
244 |
| - # exits with the job exit code. |
| 243 | + # Exits 128 + $signal_number where $signal_number is 2 for SIGINT (see |
| 244 | + # http://pubs.opengroup.org/onlinepubs/009695399/utilities/kill.html). |
| 245 | + # This is considered an abnormal process termination. Normally, we |
| 246 | + # don't need to specify this exit code because the shell propagates it. |
| 247 | + # Unfortunately, the signal handler doesn't work as expected in Dash, |
| 248 | + # thus we need to explicitely restate the exit code. |
245 | 249 | trap "stop_rabbitmq_server; exit 0" HUP TERM TSTP
|
246 |
| - trap "stop_rabbitmq_server" INT |
| 250 | + trap "stop_rabbitmq_server; exit 130" INT |
247 | 251 |
|
248 | 252 | start_rabbitmq_server "$@" &
|
| 253 | + rabbitmq_server_pid=$! |
249 | 254 |
|
250 | 255 | # Block until RabbitMQ exits or a signal is caught.
|
251 | 256 | # Waits for last command (which is start_rabbitmq_server)
|
252 |
| - wait $! |
| 257 | + # |
| 258 | + # The "|| true" is here to work around an issue with Dash. Normally |
| 259 | + # in a Bourne shell, if `wait` is interrupted by a signal, the |
| 260 | + # signal handlers defined above are executed and the script |
| 261 | + # terminates with the exit code of `wait` (unless the signal handler |
| 262 | + # overrides that). |
| 263 | + # In the case of Dash, it looks like `set -e` (set at the beginning |
| 264 | + # of this script) gets precedence over signal handling. Therefore, |
| 265 | + # when `wait` is interrupted, its exit code is non-zero and because |
| 266 | + # of `set -e`, the script terminates immediately without running the |
| 267 | + # signal handler. To work around this issue, we use "|| true" to |
| 268 | + # force that statement to succeed and the signal handler to properly |
| 269 | + # execute. Because the statement below has an exit code of 0, the |
| 270 | + # signal handler has to restate the expected exit code. |
| 271 | + wait $rabbitmq_server_pid || true |
253 | 272 | fi
|
0 commit comments