diff options
| author | Alexey Lebedeff <alebedev@mirantis.com> | 2016-03-11 17:42:15 +0300 |
|---|---|---|
| committer | Alexey Lebedeff <alebedev@mirantis.com> | 2016-03-11 19:10:19 +0300 |
| commit | 2d6383bade61fea0b8652b72d25bb1a9f0d6133f (patch) | |
| tree | 686b960de5dddf13fa8e31011e94e9a7115fd608 /scripts/rabbitmq-server | |
| parent | 2ed6627c178b22851ad359f2243a4d474a2e46e5 (diff) | |
| download | rabbitmq-server-git-2d6383bade61fea0b8652b72d25bb1a9f0d6133f.tar.gz | |
Improve systemd integration
Hopefully this patch will fix all systemd-related problems:
- Proxy shell process (which converts signals to `rabbitmqtl stop`) will
no longer be started under systemd. There is no need in it, as systemd
unit already contains instructions for graceful shutdown.
- Ready notification for systemd will be sent with the help of `socat`,
as `systemd-notify` is currently broken for non-root users. `socat` is
the most lightweight way to do it (other options are using NIF or some
external helper in Perl).
- epmd will not be able to interfere by sending it's own ready
notifications.
- systemd journal will contain some additional messages about startup
and shutdown sequence, just to be sure that everything is working
correctly.
Fixes #664
Diffstat (limited to 'scripts/rabbitmq-server')
| -rwxr-xr-x | scripts/rabbitmq-server | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index a517cc8182..5acc86682b 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -47,7 +47,7 @@ case "$(uname -s)" in exit $EX_CANTCREAT fi if ! echo $$ > ${RABBITMQ_PID_FILE}; then - # Bettern diagnostics - otherwise the only report in logs is about failed 'echo' + # Better diagnostics - otherwise the only report in logs is about failed 'echo' # command, but without any other details: neither what script has failed nor what # file output was redirected to. echo "Failed to write pid file: ${RABBITMQ_PID_FILE}" @@ -58,8 +58,13 @@ esac RABBITMQ_EBIN_ROOT="${RABBITMQ_HOME}/ebin" +[ "$NOTIFY_SOCKET" ] && RUNNING_UNDER_SYSTEMD=true + set +e +# NOTIFY_SOCKET is needed here to prevent epmd from impersonating the +# success of our startup sequence to systemd. +NOTIFY_SOCKET= \ RABBITMQ_CONFIG_FILE=$RABBITMQ_CONFIG_FILE \ RABBITMQ_DIST_PORT=$RABBITMQ_DIST_PORT \ ${ERL_DIR}erl -pa "$RABBITMQ_EBIN_ROOT" \ @@ -172,7 +177,20 @@ check_not_empty() { fi } -if [ 'x' = "x$RABBITMQ_ALLOW_INPUT" -a -z "$detached" ]; then +if [ "$RABBITMQ_ALLOW_INPUT" -o "$RUNNING_UNDER_SYSTEMD" -o "$detached" ]; then + # Run erlang VM directly, completely replacing current shell + # process - so the pid file written in the code above will be + # valid (unless detached, which is also handled in the code + # above). + # + # And also this is the correct mode to run the broker under + # systemd - there is no need in a proxy process that converts + # signals to graceful shutdown command, the unit file should already + # contain instructions for graceful shutdown. Also by removing + # this additional process we could simply use value returned by + # `os:getpid/0` for a systemd ready notification. + start_rabbitmq_server "$@" +else # When RabbitMQ runs in the foreground but the Erlang shell is # disabled, we setup signal handlers to stop RabbitMQ properly. This # is at least useful in the case of Docker. @@ -181,7 +199,7 @@ if [ 'x' = "x$RABBITMQ_ALLOW_INPUT" -a -z "$detached" ]; then RABBITMQ_SERVER_START_ARGS="${RABBITMQ_SERVER_START_ARGS} +B i" # Signal handlers. They all stop RabbitMQ properly (using - # rabbitmqctl stop). Depending on the signal, this script will exwit + # rabbitmqctl stop). Depending on the signal, this script will exit # with a non-zero error code: # SIGHUP SIGTERM SIGTSTP # They are considered a normal process termination, so the script @@ -197,6 +215,4 @@ if [ 'x' = "x$RABBITMQ_ALLOW_INPUT" -a -z "$detached" ]; then # Block until RabbitMQ exits or a signal is caught. # Waits for last command (which is start_rabbitmq_server) wait $! -else - start_rabbitmq_server "$@" fi |
