rest.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #! /usr/bin/env bash
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # https://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing,
  14. # software distributed under the License is distributed on an
  15. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. # KIND, either express or implied. See the License for the
  17. # specific language governing permissions and limitations
  18. # under the License.
  19. #
  20. #
  21. # If this scripted is run out of /usr/bin or some other system bin directory
  22. # it should be linked to and not copied. Things like java jar files are found
  23. # relative to the canonical path of this script.
  24. #
  25. # Only follow symlinks if readlink supports it
  26. if readlink -f "$0" &>/dev/null; then
  27. ZKREST=$(readlink -f "$0")
  28. else
  29. ZKREST="$0"
  30. fi
  31. ZKREST_HOME=$(dirname "$ZKREST")
  32. case "$(uname)" in
  33. CYGWIN* | MINGW*) cygwin=true ;;
  34. *) cygwin=false ;;
  35. esac
  36. if $cygwin; then
  37. # cygwin has a "kill" in the shell itself, gets confused
  38. KILL='/bin/kill'
  39. else
  40. KILL='kill'
  41. fi
  42. if [[ -z $ZKREST_PIDFILE ]]; then
  43. ZKREST_PIDFILE=$ZKREST_HOME/server.pid
  44. fi
  45. ZKREST_MAIN=org.apache.zookeeper.server.jersey.RestMain
  46. ZKREST_CONF=$ZKREST_HOME/conf
  47. ZKREST_LOG=$ZKREST_HOME/zkrest.log
  48. CLASSPATH="$ZKREST_CONF:$CLASSPATH"
  49. for i in "$ZKREST_HOME"/lib/*.jar; do
  50. CLASSPATH="$i:$CLASSPATH"
  51. done
  52. for i in "$ZKREST_HOME"/zookeeper-*.jar; do
  53. CLASSPATH="$i:$CLASSPATH"
  54. done
  55. export CLASSPATH
  56. case $1 in
  57. start)
  58. echo "Starting ZooKeeper REST Gateway ... "
  59. # shellcheck disable=SC2206
  60. flags=($JVMFLAGS)
  61. java "${flags[@]}" "$ZKREST_MAIN" &>"$ZKREST_LOG" &
  62. echo -n $! >"$ZKREST_PIDFILE"
  63. echo STARTED
  64. ;;
  65. stop)
  66. echo "Stopping ZooKeeper REST Gateway ... "
  67. if [[ ! -f $ZKREST_PIDFILE ]]; then
  68. echo "error: could not find file $ZKREST_PIDFILE"
  69. exit 1
  70. else
  71. $KILL -9 "$(cat "$ZKREST_PIDFILE")"
  72. rm "$ZKREST_PIDFILE"
  73. echo STOPPED
  74. fi
  75. ;;
  76. restart)
  77. shift
  78. "$0" stop "$@"
  79. sleep 3
  80. "$0" start "$@"
  81. ;;
  82. *)
  83. echo "Usage: $0 {start|stop|restart}" >&2
  84. ;;
  85. esac