zkCleanup.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. # This script cleans up old transaction logs and snapshots
  22. #
  23. #
  24. # If this scripted is run out of /usr/bin or some other system bin directory
  25. # it should be linked to and not copied. Things like java jar files are found
  26. # relative to the canonical path of this script.
  27. #
  28. # use POSIX interface, symlink is followed automatically
  29. ZOOBIN="${BASH_SOURCE-$0}"
  30. ZOOBIN="$(dirname "$ZOOBIN")"
  31. ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
  32. if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
  33. # shellcheck source=bin/zkEnv.sh
  34. . "$ZOOBINDIR"/../libexec/zkEnv.sh
  35. else
  36. # shellcheck source=bin/zkEnv.sh
  37. . "$ZOOBINDIR"/zkEnv.sh
  38. fi
  39. ZOODATADIR="$(grep "^[[:space:]]*dataDir=" "$ZOOCFG" | sed -e 's/.*=//')"
  40. ZOODATALOGDIR="$(grep "^[[:space:]]*dataLogDir=" "$ZOOCFG" | sed -e 's/.*=//')"
  41. ZOO_LOG_FILE=zookeeper-$USER-cleanup-$HOSTNAME.log
  42. # shellcheck disable=SC2206
  43. flags=($JVMFLAGS)
  44. if [[ -z $ZOODATALOGDIR ]]; then
  45. "$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" "${flags[@]}" \
  46. org.apache.zookeeper.server.PurgeTxnLog "$ZOODATADIR" "$@"
  47. else
  48. "$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" "${flags[@]}" \
  49. org.apache.zookeeper.server.PurgeTxnLog "$ZOODATALOGDIR" "$ZOODATADIR" "$@"
  50. fi