-
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 4 commits
d4c905f
6931054
237f5b7
fb5eb34
63b2e59
e31a646
d4b8d01
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/.*=//')" | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ZOO_LOG_FILE=zookeeper-$USER-cleanup-$HOSTNAME.log | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck disable=SC2206 | ||||||||||||||||||||||||||||||||||||||||||||
| flags=($JVMFLAGS) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| flags=($JVMFLAGS) | |
| flags=("-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" $JVMFLAGS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed manually (see below for a reason why) in 63b2e59 (this PR)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 flags array, this simplifies to:
| 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 | |
| directories=() | |
| [[ -n $ZOODATADIR ]] && directories=("$ZOODATADIR") | |
| [[ -n $ZOODATALOGDIR ]] && directories=("$ZOODATALOGDIR" "${directories[@]}") | |
| "$JAVA" "${flags[@]}" org.apache.zookeeper.server.PurgeTxnLog "${directories[@]}" "$@" |
This also covers the case where only dataLogDir is set, which I think wasn't covered before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that is a much better approach :(
I couldn't apply the patch directly from GitHub due to
Applying suggestions on deleted lines is currently not supported.
So I did it manually in 63b2e59 (this PR) together with your suggestions for the flags
Uh oh!
There was an error while loading. Please reload this page.