Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-cloud / recipes-extended / rabbitmq / files / rabbitmq-script-wrapper
1 #!/bin/sh
2 ##  The contents of this file are subject to the Mozilla Public License
3 ##  Version 1.1 (the "License"); you may not use this file except in
4 ##  compliance with the License. You may obtain a copy of the License
5 ##  at http://www.mozilla.org/MPL/
6 ##
7 ##  Software distributed under the License is distributed on an "AS IS"
8 ##  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9 ##  the License for the specific language governing rights and
10 ##  limitations under the License.
11 ##
12 ##  The Original Code is RabbitMQ.
13 ##
14 ##  The Initial Developer of the Original Code is GoPivotal, Inc.
15 ##  Copyright (c) 2007-2015 Pivotal Software, Inc.  All rights reserved.
16 ##
17
18 SED_OPT="-E"
19 if [ $(uname -s) = "Linux" ]; then
20     SED_OPT="-r"
21 fi
22
23 for arg in "$@" ; do
24     # Wrap each arg in single quotes and wrap single quotes in double quotes, so that they're passed through cleanly.
25     arg=`printf %s "$arg" | sed $SED_OPT -e "s/'/'\"'\"'/g"`
26     CMDLINE="${CMDLINE} '${arg}'"
27 done
28
29 cd /var/lib/rabbitmq
30
31 SCRIPT=`basename $0`
32
33 if [ `id -u` = `id -u rabbitmq` -a "$SCRIPT" = "rabbitmq-server" ] ; then
34     RABBITMQ_ENV=/usr/lib/rabbitmq/bin/rabbitmq-env
35     RABBITMQ_SCRIPTS_DIR=$(dirname "$RABBITMQ_ENV")
36     . "$RABBITMQ_ENV"
37
38     exec /usr/lib/rabbitmq/bin/rabbitmq-server "$@"
39 elif [ `id -u` = `id -u rabbitmq` -o "$SCRIPT" = "rabbitmq-plugins" ] ; then
40     if [ -f $PWD/.erlang.cookie ] ; then
41         export HOME=.
42     fi
43     exec /usr/lib/rabbitmq/bin/${SCRIPT} "$@"
44 elif [ `id -u` = 0 ] ; then
45     # WRS. Allow to run as root
46     export HOME=${HOME:-/root}
47     /bin/sh -c "/usr/lib/rabbitmq/bin/${SCRIPT} ${CMDLINE}"
48 else
49     /usr/lib/rabbitmq/bin/${SCRIPT}
50     echo
51     echo "Only root or rabbitmq should run ${SCRIPT}"
52     echo
53     exit 1
54 fi