Blame rabbitmq-script-wrapper

Hubert Plociniczak 1b1224
#!/bin/sh
f44ad9
##  The contents of this file are subject to the Mozilla Public License
f44ad9
##  Version 1.1 (the "License"); you may not use this file except in
f44ad9
##  compliance with the License. You may obtain a copy of the License
f44ad9
##  at http://www.mozilla.org/MPL/
Hubert Plociniczak 1b1224
##
f44ad9
##  Software distributed under the License is distributed on an "AS IS"
f44ad9
##  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
f44ad9
##  the License for the specific language governing rights and
f44ad9
##  limitations under the License.
Hubert Plociniczak 1b1224
##
f44ad9
##  The Original Code is RabbitMQ.
Hubert Plociniczak 1b1224
##
b093db
##  The Initial Developer of the Original Code is GoPivotal, Inc.
b093db
##  Copyright (c) 2007-2015 Pivotal Software, Inc.  All rights reserved.
Hubert Plociniczak 1b1224
##
Hubert Plociniczak 1b1224
b093db
SED_OPT="-E"
b093db
if [ $(uname -s) = "Linux" ]; then
b093db
    SED_OPT="-r"
b093db
fi
b093db
Hubert Plociniczak cc9fdf
for arg in "$@" ; do
b093db
    # Wrap each arg in single quotes and wrap single quotes in double quotes, so that they're passed through cleanly.
b093db
    arg=`printf %s "$arg" | sed $SED_OPT -e "s/'/'\"'\"'/g"`
b093db
    CMDLINE="${CMDLINE} '${arg}'"
Hubert Plociniczak cc9fdf
done
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
cd /var/lib/rabbitmq
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
SCRIPT=`basename $0`
Hubert Plociniczak cc9fdf
d817ac
if [ `id -u` = `id -u rabbitmq` -a "$SCRIPT" = "rabbitmq-server" ] ; then
b093db
    RABBITMQ_ENV=/usr/lib/rabbitmq/bin/rabbitmq-env
b093db
    RABBITMQ_SCRIPTS_DIR=$(dirname "$RABBITMQ_ENV")
b093db
    . "$RABBITMQ_ENV"
b093db
b093db
    exec /usr/lib/rabbitmq/bin/rabbitmq-server "$@"
d817ac
elif [ `id -u` = `id -u rabbitmq` -o "$SCRIPT" = "rabbitmq-plugins" ] ; then
b093db
    if [ -f $PWD/.erlang.cookie ] ; then
b093db
        export HOME=.
b093db
    fi
b093db
    exec /usr/lib/rabbitmq/bin/${SCRIPT} "$@"
d817ac
elif [ `id -u` = 0 ] ; then
d817ac
    su rabbitmq -s /bin/sh -c "/usr/lib/rabbitmq/bin/${SCRIPT} ${CMDLINE}"
Hubert Plociniczak cc9fdf
else
f44ad9
    /usr/lib/rabbitmq/bin/${SCRIPT}
f44ad9
    echo
f44ad9
    echo "Only root or rabbitmq should run ${SCRIPT}"
f44ad9
    echo
f44ad9
    exit 1
Hubert Plociniczak cc9fdf
fi