-
Notifications
You must be signed in to change notification settings - Fork 7.3k
ZOOKEEPER-4985 Fix zkCleanup.sh script to not fail on non-standard config directories #2324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,27 +31,43 @@ | |||||||||||||||||||||||||||||||||||||||||||
| # use POSIX interface, symlink is followed automatically | ||||||||||||||||||||||||||||||||||||||||||||
| ZOOBIN="${BASH_SOURCE-$0}" | ||||||||||||||||||||||||||||||||||||||||||||
| ZOOBIN="$(dirname "$ZOOBIN")" | ||||||||||||||||||||||||||||||||||||||||||||
| ZOOBINDIR="$(cd "$ZOOBIN" && pwd)" | ||||||||||||||||||||||||||||||||||||||||||||
| ZOOBINDIR="$(cd "$ZOOBIN" && pwd)" || exit | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck source=bin/zkEnv.sh | ||||||||||||||||||||||||||||||||||||||||||||
| . "$ZOOBINDIR"/../libexec/zkEnv.sh | ||||||||||||||||||||||||||||||||||||||||||||
| . "$ZOOBINDIR"/../libexec/zkEnv.sh "$@" | ||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck source=bin/zkEnv.sh | ||||||||||||||||||||||||||||||||||||||||||||
| . "$ZOOBINDIR"/zkEnv.sh | ||||||||||||||||||||||||||||||||||||||||||||
| . "$ZOOBINDIR"/zkEnv.sh "$@" | ||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ZOODATADIR="$(grep "^[[:space:]]*dataDir=" "$ZOOCFG" | sed -e 's/.*=//')" | ||||||||||||||||||||||||||||||||||||||||||||
| ZOODATALOGDIR="$(grep "^[[:space:]]*dataLogDir=" "$ZOOCFG" | sed -e 's/.*=//')" | ||||||||||||||||||||||||||||||||||||||||||||
| ZOODATADIR="" | ||||||||||||||||||||||||||||||||||||||||||||
| ZOODATALOGDIR="" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Only try to read config if ZOOCFG exists | ||||||||||||||||||||||||||||||||||||||||||||
| if [[ -f $ZOOCFG ]]; then | ||||||||||||||||||||||||||||||||||||||||||||
| ZOODATADIR="$(grep "^[[:space:]]*dataDir=" "$ZOOCFG" 2>/dev/null | sed -e 's/.*=//')" | ||||||||||||||||||||||||||||||||||||||||||||
| ZOODATALOGDIR="$(grep "^[[:space:]]*dataLogDir=" "$ZOOCFG" 2>/dev/null | sed -e 's/.*=//')" | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+49
to
+50
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is perhaps something for another PR, since it's a bit out of scope here, and there may be other scripts that would also benefit from this change, but I noticed that It can be done with bash regular expressions and a simple capture group, though, without calling another process: re='^[^=]*=[[:space:]]*(.*)[[:space:]]*$'
ZOODATADIR="$(grep "^[[:space:]]*dataDir=" "$ZOOCFG" 2>/dev/null)"
[[ $ZOODATADIR =~ $re ]] && ZOODATADIR="${BASH_REMATCH[1]}"
ZOODATALOGDIR="$(grep "^[[:space:]]*dataLogDir=" "$ZOOCFG" 2>/dev/null)"
[[ $ZOODATALOGDIR =~ $re ]] && ZOODATALOGDIR="${BASH_REMATCH[1]}" |
||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ZOO_LOG_FILE=zookeeper-$USER-cleanup-$HOSTNAME.log | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck disable=SC2206 | ||||||||||||||||||||||||||||||||||||||||||||
| flags=($JVMFLAGS) | ||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| if [[ -z $ZOODATALOGDIR ]]; then | ||||||||||||||||||||||||||||||||||||||||||||
| "$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" "${flags[@]}" \ | ||||||||||||||||||||||||||||||||||||||||||||
| org.apache.zookeeper.server.PurgeTxnLog "$ZOODATADIR" "$@" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # If config provides directories, use them; otherwise pass all args to PurgeTxnLog | ||||||||||||||||||||||||||||||||||||||||||||
| if [[ -n $ZOODATADIR ]]; then | ||||||||||||||||||||||||||||||||||||||||||||
| if [[ -z $ZOODATALOGDIR ]]; then | ||||||||||||||||||||||||||||||||||||||||||||
| # Only dataDir specified | ||||||||||||||||||||||||||||||||||||||||||||
| "$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "${flags[@]}" org.apache.zookeeper.server.PurgeTxnLog "$ZOODATADIR" "$@" | ||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||
| # Both dataDir and dataLogDir specified | ||||||||||||||||||||||||||||||||||||||||||||
| "$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "${flags[@]}" org.apache.zookeeper.server.PurgeTxnLog "$ZOODATALOGDIR" "$ZOODATADIR" "$@" | ||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||
| "$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" "${flags[@]}" \ | ||||||||||||||||||||||||||||||||||||||||||||
| org.apache.zookeeper.server.PurgeTxnLog "$ZOODATALOGDIR" "$ZOODATADIR" "$@" | ||||||||||||||||||||||||||||||||||||||||||||
| # No config or config doesn't specify directories - pass all args to PurgeTxnLog | ||||||||||||||||||||||||||||||||||||||||||||
| "$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "${flags[@]}" org.apache.zookeeper.server.PurgeTxnLog "$@" | ||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+59
to
73
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The complexity of this if/else can be entirely removed if you just build up the command-line arguments. Combining with my earlier suggestion to add the other system properties to the
Suggested change
This also covers the case where only |
||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.