rabbitmq-script-wrapper 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. # Escape spaces and quotes, because shell is revolting.
  18. for arg in "$@" ; do
  19. # Escape quotes in parameters, so that they're passed through cleanly.
  20. arg=$(sed -e 's/"/\\"/g' <<-END
  21. $arg
  22. END
  23. )
  24. CMDLINE="${CMDLINE} \"${arg}\""
  25. done
  26. SCRIPT="$(basename "$0")"
  27. if [ $(id -u) = $(id -u rabbitmq) ] && [ "$SCRIPT" = "rabbitmq-server" ]; then
  28. cd /var/lib/rabbitmq
  29. /usr/lib/rabbitmq/bin/rabbitmq-server "$@" > "/var/log/rabbitmq/startup_log" 2> "/var/log/rabbitmq/startup_err"
  30. elif [ $(id -u) = $(id -u rabbitmq) ]; then
  31. cd /var/lib/rabbitmq
  32. if [ -f "${PWD}/.erlang.cookie" ] ; then
  33. export HOME=.
  34. fi
  35. "/usr/lib/rabbitmq/bin/${SCRIPT}" "$@"
  36. elif [ $(id -u) = 0 ] ; then
  37. cd /var/lib/rabbitmq
  38. su rabbitmq -s /bin/sh -c "/usr/lib/rabbitmq/bin/${SCRIPT} ${CMDLINE}"
  39. else
  40. "/usr/lib/rabbitmq/bin/${SCRIPT}"
  41. echo
  42. echo "Only root or rabbitmq should run ${SCRIPT}"
  43. echo
  44. exit 1
  45. fi