rest.sh 2.2 KB

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