Update to the version 3.3.5 from rabbitmq.com
[packages/centos6/rabbitmq-server.git] / 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-2014 GoPivotal, Inc.  All rights reserved.
16 ##
17
18 # Escape spaces and quotes, because shell is revolting.
19 for arg in "$@" ; do
20         # Escape quotes in parameters, so that they're passed through cleanly.
21         arg=$(sed -e 's/"/\\"/g' <<-END
22                 $arg
23                 END
24         )
25         CMDLINE="${CMDLINE} \"${arg}\""
26 done
27
28 cd /var/lib/rabbitmq
29
30 SCRIPT=`basename $0`
31
32 if [ `id -u` = `id -u rabbitmq` -a "$SCRIPT" = "rabbitmq-server" ] ; then
33     /usr/lib/rabbitmq/bin/rabbitmq-server "$@" 
34 elif [ `id -u` = `id -u rabbitmq` -o "$SCRIPT" = "rabbitmq-plugins" ] ; then
35     /usr/lib/rabbitmq/bin/${SCRIPT} "$@"
36 elif [ `id -u` = 0 ] ; then
37     su rabbitmq -s /bin/sh -c "/usr/lib/rabbitmq/bin/${SCRIPT} ${CMDLINE}"
38 else
39     /usr/lib/rabbitmq/bin/${SCRIPT}
40     echo
41     echo "Only root or rabbitmq should run ${SCRIPT}"
42     echo
43     exit 1
44 fi