Skip to content

Commit 69d95a2

Browse files
authored
ZOOKEEPER-3766: Clean up bash scripts
ZOOKEEPER-3766: Clean up bash scripts For ZOOKEEPER-3766: * Export CLASSPATH in scripts and remove `-cp $CLASSPATH` uses, so that java picks up the classpath from the environment, to avoid absurdly long command lines in process listings (this should also fix an issue with older versions of pgrep/pkill, such as that installed on RHEL8; see https://bugzilla.redhat.com/show_bug.cgi?id=1782309 for details) * Add a new `classpath` command to print the CLASSPATH environment variable in the form `CLASSPATH=$CLASSPATH` from the script, so that the script's view of the CLASSPATH environment can easily be inspected when troubleshooting java processes Also fix other code quality issues in all bash scripts: * Add CI checks for shfmt and shellcheck for all bash scripts * Standardize "shebang" lines * Standardize license header formatting * Format using shfmt tool and address all shellcheck problems * Remove unnecessary quoting and use of curly braces * Standardize on double square braces to avoid unpredictable use of /usr/bin/\[ instead of built-in bash braces * Remove a useless check of `$?` in bin/zkServer-initialize.sh * Remove an impossible to reach exit from bin/zkServer-initialize.sh * Remove an impossible to fail check of `$?` after nohup is executed in bin/zkServer.sh (nohup with a trailing `&` always returns a zero exit code for success, even if the command fails; if it fails it fails undetectibly in the background) * Avoid using sed for regex, and use built-in bash regex instead * Delete some old scripts (some of which are broken anyway) that don't appear to be used anywhere, and don't seem to have any current need * Bump rat plugin version for https in license and add license to .gitattributes to make rat plugin happy again Reviewers: tisonkun, anmolnar Author: ctubbsii Closes #2224 from ctubbsii/cleanup-scripts
1 parent 6e4ec27 commit 69d95a2

File tree

34 files changed

+1208
-2583
lines changed

34 files changed

+1208
-2583
lines changed

.gitattributes

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
120
# Auto detect text files and perform LF normalization
221
* text=auto
322

.github/workflows/scripts.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
# This workflow enforces quality checks on bash scripts in the project
21+
22+
name: ScriptQA
23+
24+
on:
25+
push:
26+
branches: [ '*' ]
27+
pull_request:
28+
branches: [ '*' ]
29+
30+
permissions:
31+
contents: read
32+
33+
jobs:
34+
shfmt:
35+
name: shfmt
36+
timeout-minutes: 3
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Show the first log message
41+
run: git log -n1
42+
- name: Install shfmt
43+
run: tools/ci/install-shfmt.sh
44+
- name: Checking formatting of all scripts
45+
run: tools/ci/run-shfmt.sh
46+
47+
shellcheck:
48+
name: ShellCheck
49+
timeout-minutes: 3
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
- name: Show the first log message
54+
run: git log -n1
55+
- name: Install shfmt
56+
run: tools/ci/install-shfmt.sh
57+
- name: Running shellcheck on all scripts
58+
run: tools/ci/run-shellcheck.sh

bin/zkCleanup.sh

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
#!/usr/bin/env bash
2-
3-
# Licensed to the Apache Software Foundation (ASF) under one or more
4-
# contributor license agreements. See the NOTICE file distributed with
5-
# this work for additional information regarding copyright ownership.
6-
# The ASF licenses this file to You under the Apache License, Version 2.0
7-
# (the "License"); you may not use this file except in compliance with
8-
# the License. You may obtain a copy of the License at
9-
#
10-
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
12-
# Unless required by applicable law or agreed to in writing, software
13-
# distributed under the License is distributed on an "AS IS" BASIS,
14-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
# See the License for the specific language governing permissions and
16-
# limitations under the License.
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+
#
1720

1821
#
1922
# This script cleans up old transaction logs and snapshots
@@ -27,12 +30,14 @@
2730

2831
# use POSIX interface, symlink is followed automatically
2932
ZOOBIN="${BASH_SOURCE-$0}"
30-
ZOOBIN="$(dirname "${ZOOBIN}")"
31-
ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
33+
ZOOBIN="$(dirname "$ZOOBIN")"
34+
ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
3235

33-
if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
36+
if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
37+
# shellcheck source=bin/zkEnv.sh
3438
. "$ZOOBINDIR"/../libexec/zkEnv.sh
3539
else
40+
# shellcheck source=bin/zkEnv.sh
3641
. "$ZOOBINDIR"/zkEnv.sh
3742
fi
3843

@@ -41,13 +46,12 @@ ZOODATALOGDIR="$(grep "^[[:space:]]*dataLogDir=" "$ZOOCFG" | sed -e 's/.*=//')"
4146

4247
ZOO_LOG_FILE=zookeeper-$USER-cleanup-$HOSTNAME.log
4348

44-
if [ "x$ZOODATALOGDIR" = "x" ]
45-
then
46-
"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \
47-
-cp "$CLASSPATH" $JVMFLAGS \
48-
org.apache.zookeeper.server.PurgeTxnLog "$ZOODATADIR" $*
49+
# shellcheck disable=SC2206
50+
flags=($JVMFLAGS)
51+
if [[ -z $ZOODATALOGDIR ]]; then
52+
"$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" "${flags[@]}" \
53+
org.apache.zookeeper.server.PurgeTxnLog "$ZOODATADIR" "$@"
4954
else
50-
"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \
51-
-cp "$CLASSPATH" $JVMFLAGS \
52-
org.apache.zookeeper.server.PurgeTxnLog "$ZOODATALOGDIR" "$ZOODATADIR" $*
55+
"$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" "${flags[@]}" \
56+
org.apache.zookeeper.server.PurgeTxnLog "$ZOODATALOGDIR" "$ZOODATADIR" "$@"
5357
fi

bin/zkCli.sh

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
#!/usr/bin/env bash
2-
3-
# Licensed to the Apache Software Foundation (ASF) under one or more
4-
# contributor license agreements. See the NOTICE file distributed with
5-
# this work for additional information regarding copyright ownership.
6-
# The ASF licenses this file to You under the Apache License, Version 2.0
7-
# (the "License"); you may not use this file except in compliance with
8-
# the License. You may obtain a copy of the License at
9-
#
10-
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
12-
# Unless required by applicable law or agreed to in writing, software
13-
# distributed under the License is distributed on an "AS IS" BASIS,
14-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
# See the License for the specific language governing permissions and
16-
# limitations under the License.
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+
#
1720

1821
#
1922
# This script cleans up old transaction logs and snapshots
@@ -27,17 +30,23 @@
2730

2831
# use POSIX interface, symlink is followed automatically
2932
ZOOBIN="${BASH_SOURCE-$0}"
30-
ZOOBIN="$(dirname "${ZOOBIN}")"
31-
ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
33+
ZOOBIN="$(dirname "$ZOOBIN")"
34+
ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
3235

33-
if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
36+
if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
37+
# shellcheck source=bin/zkEnv.sh
3438
. "$ZOOBINDIR"/../libexec/zkEnv.sh
3539
else
40+
# shellcheck source=bin/zkEnv.sh
3641
. "$ZOOBINDIR"/zkEnv.sh
3742
fi
3843

3944
ZOO_LOG_FILE=zookeeper-$USER-cli-$HOSTNAME.log
4045

41-
"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \
42-
-cp "$CLASSPATH" $CLIENT_JVMFLAGS $JVMFLAGS \
43-
org.apache.zookeeper.ZooKeeperMain "$@"
46+
# shellcheck disable=SC2206
47+
clientflags=($CLIENT_JVMFLAGS)
48+
# shellcheck disable=SC2206
49+
flags=($JVMFLAGS)
50+
"$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" \
51+
"${clientflags[@]}" "${flags[@]}" \
52+
org.apache.zookeeper.ZooKeeperMain "$@"

0 commit comments

Comments
 (0)