Skip to content

Commit d010282

Browse files
authored
BIGTOP-4456: Improve log for setup agent (#237)
1 parent f3175ad commit d010282

File tree

8 files changed

+84
-21
lines changed

8 files changed

+84
-21
lines changed

bigtop-manager-agent/src/main/resources/bin/env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
#
23
# Licensed to the Apache Software Foundation (ASF) under one
34
# or more contributor license agreements. See the NOTICE file
@@ -17,5 +18,4 @@
1718
# under the License.
1819
#
1920

20-
21-
export JAVA_OPTS=""
21+
export JAVA_OPTS=""

bigtop-manager-agent/src/main/resources/bin/start.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
# under the License.
1919
#
2020

21+
set -e
22+
2123
BIN_DIR=$(dirname $0)
2224
BIGTOP_MANAGER_HOME=${BIGTOP_MANAGER_HOME:-$(cd $BIN_DIR/..; pwd)}
2325

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/HostServiceImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,15 @@ public void installDependencies(HostDTO hostDTO, String hostname, InstalledStatu
279279
+ "\nEOF\n"
280280
+ "chmod +x ./setup-agent.sh && ./setup-agent.sh " + path + " " + repoUrl + " " + grpcPort;
281281
} catch (IOException e) {
282-
log.error("Unable to setup agent, hostname: {}, msg: {}", hostname, e.getMessage());
283-
282+
log.error("Unable to write agent script, hostname: {}, msg: {}", hostname, e.getMessage());
284283
installedStatusVO.setStatus(InstalledStatusEnum.FAILED);
285284
installedStatusVO.setMessage(e.getMessage());
286285
return;
287286
}
288287

289288
ShellResult result = execCommandOnRemoteHost(hostDTO, hostname, command);
290289
if (result.getExitCode() != MessageConstants.SUCCESS_CODE) {
291-
log.error("Unable to setup agent, hostname: {}, msg: {}", hostname, result.getErrMsg());
292-
290+
log.error("Unable to setup agent, hostname: {}, msg: {}", hostname, result);
293291
installedStatusVO.setStatus(InstalledStatusEnum.FAILED);
294292
installedStatusVO.setMessage(result.getErrMsg());
295293
return;

bigtop-manager-server/src/main/resources/scripts/setup-agent.sh

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,25 @@
2121
set -e
2222

2323
[ $# -lt 3 ] && {
24-
echo "Usage: $0 <dir_prefix> <repo_url> <grpc_port> [checksum_alg checksum_value]" >&2
24+
info "Usage: $0 <dir_prefix> <repo_url> <grpc_port> [checksum_alg checksum_value]"
2525
exit 1
2626
}
2727

2828
USER=$(whoami)
2929
GROUP=$(id -gn)
3030

31+
info() {
32+
echo $1 >> setup-agent.log 2>&1
33+
}
34+
35+
error () {
36+
echo $1 >&2
37+
echo $1 >> setup-agent.log 2>&1
38+
}
39+
3140
check_sudo() {
3241
if ! sudo -n true 2>/dev/null; then
33-
echo "ERROR: User '$USER' doesn't have sudo privileges" >&2
42+
error "User '$USER' doesn't have sudo privileges"
3443
exit 1
3544
fi
3645
}
@@ -59,7 +68,7 @@ validate_checksum() {
5968

6069
local calc_val=$($sum_cmd "$file" | awk '{print $1}')
6170
[ "$calc_val" = "$CHECK_VAL" ] || {
62-
echo "Checksum mismatch: Expected ${CHECK_ALG}=$CHECK_VAL, Found=$calc_val" >&2
71+
error "Checksum mismatch: Expected ${CHECK_ALG}=$CHECK_VAL, Found=$calc_val"
6372
return 1
6473
}
6574
}
@@ -70,27 +79,29 @@ handle_tar_file() {
7079
if [ -f "$TAR_FILE" ]; then
7180
if [ -n "$CHECK_ALG" ]; then
7281
validate_checksum "$TAR_FILE" || {
73-
echo "Removing invalid file: $TAR_FILE" >&2
82+
info "Removing invalid file: $TAR_FILE"
7483
rm -f "$TAR_FILE"
75-
return 1
7684
}
85+
else
86+
info "Using existing file: $TAR_FILE"
87+
return 0
7788
fi
78-
return 0
7989
fi
8090

8191
# Download file
92+
info "Downloading agent tarball from $DOWNLOAD_URL to $TAR_FILE"
8293
if command -v wget &> /dev/null; then
83-
wget "$DOWNLOAD_URL" -O "$TAR_FILE"
94+
wget -q "$DOWNLOAD_URL" -O "$TAR_FILE"
8495
else
85-
curl -L "$DOWNLOAD_URL" -o "$TAR_FILE"
96+
curl -sL "$DOWNLOAD_URL" -o "$TAR_FILE"
8697
fi
8798

8899
# Post-download validation
89100
if [ -n "$CHECK_ALG" ]; then
90-
echo "Validating checksum"
101+
info "Validating checksum"
91102
validate_checksum "$TAR_FILE" || {
92103
rm -f "$TAR_FILE"
93-
echo "Downloaded file checksum validation failed" >&2
104+
error "Downloaded file checksum validation failed"
94105
exit 1
95106
}
96107
fi
@@ -107,12 +118,32 @@ deploy_agent() {
107118
start() {
108119
export GRPC_PORT="$GRPC_PORT"
109120

121+
info "Prepare to start agent"
110122
if ! pgrep -f "${PROCESS_NAME}" > /dev/null; then
111-
nohup ${TARGET_DIR}/bin/start.sh --debug > /dev/null 2>&1 &
123+
info "Starting agent"
124+
nohup ${TARGET_DIR}/bin/start.sh --debug > /dev/null 2>>setup-agent.log &
112125
sleep 10
113-
pgrep -f "${PROCESS_NAME}" > /dev/null || exit 1
126+
if ! pgrep -f "${PROCESS_NAME}" > /dev/null; then
127+
error "Failed to start agent, please check the log"
128+
exit 1
129+
else
130+
info "Agent started successfully"
131+
fi
132+
else
133+
info "Agent is already running"
114134
fi
115135
}
116136

137+
# Remove previous log file
138+
rm -f setup-agent.log
139+
140+
# Log variables
141+
info "DIR_PREFIX: $DIR_PREFIX"
142+
info "REPO_URL: $REPO_URL"
143+
info "GRPC_PORT: $GRPC_PORT"
144+
info "CHECK_ALG: $CHECK_ALG"
145+
info "CHECK_VAL: $CHECK_VAL"
146+
147+
# Run deployment
117148
deploy_agent
118149
start

dev-support/docker/containers/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ while [ $# -gt 0 ]; do
186186
echo "Requires a os" 1>&2
187187
usage
188188
fi
189-
if [ $2 != "rocky-8" ] && [ $2 != "openeuler-24" ]; then
190-
echo "The OS should be [rocky-8] or [openeuler-24]" 1>&2
189+
if [ $2 != "rocky-8" ] && [ $2 != "openeuler-22" ] && [ $2 != "openeuler-24" ]; then
190+
echo "The OS should be [rocky-8], [openeuler-22] or [openeuler-24]" 1>&2
191191
usage
192192
fi
193193
OS=$2
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
FROM openeuler/openeuler:22.03
17+
18+
RUN dnf install -y sudo wget openssh-clients openssh-server mariadb mariadb-server net-tools chrony krb5-server krb5-libs krb5-workstation git python3 procps-ng
19+
RUN dnf install -y postgresql java-17-openjdk-devel vim numactl
20+
21+
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk
22+
ENV PATH=$JAVA_HOME/bin:$PATH
23+
RUN wget --no-check-certificate https://archive.apache.org/dist/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz && \
24+
tar -xvf apache-maven-3.8.8-bin.tar.gz && \
25+
mv apache-maven-3.8.8 /usr/lib/maven
26+
ENV PATH=${PATH}:/usr/lib/maven/bin
27+
28+
RUN wget https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl3.py -O /usr/bin/systemctl
29+
RUN /bin/sed -i 's,# StrictHostKeyChecking ask,StrictHostKeyChecking no,g' /etc/ssh/ssh_config

dev-support/docker/image/Dockerfile.openeuler24

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RUN dnf install -y postgresql java-17-openjdk-devel vim numactl
2020

2121
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk
2222
ENV PATH=$JAVA_HOME/bin:$PATH
23-
RUN wget --no-check-certificate https://downloads.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz && \
23+
RUN wget --no-check-certificate https://archive.apache.org/dist/maven/maven-3/3.8.8/apache-maven-3.8.8-bin.tar.gz && \
2424
tar -xvf apache-maven-3.8.8-bin.tar.gz && \
2525
mv apache-maven-3.8.8 /usr/lib/maven
2626
ENV PATH=${PATH}:/usr/lib/maven/bin

dev-support/docker/image/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ case ${OS}-${VERSION_INT} in
5252
rocky-8)
5353
DOCKERFILE="Dockerfile.rocky8"
5454
;;
55+
openeuler-22)
56+
DOCKERFILE="Dockerfile.openeuler22"
57+
;;
5558
openeuler-24)
5659
DOCKERFILE="Dockerfile.openeuler24"
5760
;;

0 commit comments

Comments
 (0)