Skip to content

Commit 5343637

Browse files
obdevfootkaLINxiansheng
authored andcommitted
add base-dir in config
Co-authored-by: footka <672528926@qq.com> Co-authored-by: LINxiansheng <wangzelin19961202@gmail.com>
1 parent 58102d5 commit 5343637

9 files changed

Lines changed: 68 additions & 41 deletions

File tree

deps/init/oceanbase.el7.aarch64.deps

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ os=7
88
arch=aarch64
99
repo=http://mirrors.oceanbase.com/oceanbase/community/stable/el/7/aarch64/
1010

11-
[target-obdeploy]
12-
os=7
13-
arch=aarch64
14-
repo=https://ob-yum.oceanbase-dev.com/7/aarch64/test/ob-deploy/
15-
1611

1712
[deps]
1813
devdeps-gtest-1.8.0-132022101316.el7.aarch64.rpm

src/observer/ob_service.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ TelemetryTask::TelemetryTask(bool embed_mode)
160160

161161
void TelemetryTask::runTimerTask()
162162
{
163-
const char *env_reporter = std::getenv("REPORT");
163+
const char *env_reporter = std::getenv("REPORTER");
164164
const char *reporter = env_reporter ? env_reporter : (embed_mode_ ? "embed" : "server");
165165
share::report_telemetry(reporter, "bootstraped");
166166
}

tools/systemd/profile/post_uninstall.sh.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ if [ "$1" -eq 0 ] 2>/dev/null || [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
1616
echo "# This script will clean all SeekDB configuration and data files" >> "$clean_script"
1717
fi
1818

19-
echo "rm -rf /usr/libexec/oceanbase/scripts/cluster_id" >> "$clean_script"
2019
echo "rm -rf /var/lib/oceanbase" >> "$clean_script"
2120
echo "echo OK" >> "$clean_script"
2221

tools/systemd/profile/pre_uninstall.sh.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [ -f "$cnf_file" ] && [ -s "$cnf_file" ]; then
2929
echo "rm -rf $data_dir" >> "$clean_script"
3030
fi
3131

32+
base_dir=$(cat "$cnf_file" | grep -o 'base-dir=[^[:space:]]*' | sed 's/base-dir=//')
33+
if [ -n "$base_dir" ]; then
34+
echo "rm -rf $base_dir" >> "$clean_script"
35+
fi
36+
3237
# Make the script executable
3338
chmod +x "$clean_script"
3439
fi

tools/systemd/profile/seekdb.cnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
port=2881
2+
base-dir=/var/lib/oceanbase
23
data-dir=/var/lib/oceanbase/store
34
redo-dir=/var/lib/oceanbase/store/redo
45
datafile_size=2G

tools/systemd/profile/seekdb.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Description=seekdb
44
[Service]
55
User=root
66
Type=notify
7-
Environment=REPORT=systemd
7+
Environment=REPORTER=systemd
88
ExecStart=/usr/libexec/oceanbase/scripts/seekdb_systemd_start
99
ExecStop=/usr/libexec/oceanbase/scripts/seekdb_systemd_stop
1010
PIDFile=/var/lib/oceanbase/run/observer.pid

tools/systemd/profile/seekdb_systemd_start

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
CONFIG_FILE="/etc/oceanbase/seekdb.cnf"
66
BASE_DIR="/var/lib/oceanbase"
7-
SEEKDB_TELEMETRY_FILE="$BASE_DIR/run/telemetry.json"
8-
CURRENT_DIR=$(dirname "$0")
9-
report=3
7+
SYSTEMD_PID_FILE="$BASE_DIR/run/observer.pid"
108

119
# Check if config file exists
1210
if [ ! -f "$CONFIG_FILE" ]; then
@@ -34,6 +32,9 @@ read_config() {
3432
"port")
3533
ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --port=$value"
3634
;;
35+
"base-dir")
36+
BASE_DIR="$value"
37+
;;
3738
"data-dir")
3839
ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS --data-dir=$value"
3940
;;
@@ -56,26 +57,27 @@ CMD="/usr/bin/observer --base-dir=$BASE_DIR $ADDITIONAL_PARAMS"
5657
echo "Starting seekdb with command: $CMD"
5758
echo "Configuration loaded from: $CONFIG_FILE"
5859

59-
# Execute the command
60-
$CMD &
61-
CMD_PID=$!
62-
63-
# Wait for the command to complete and check its exit status
64-
wait $CMD_PID
60+
$CMD
6561
CMD_EXIT_CODE=$?
6662

63+
# Create softlink for PID file to systemd expected location
64+
SEEKDB_PID_FILE="$BASE_DIR/run/observer.pid"
65+
if [ -f "$SEEKDB_PID_FILE" ] && [ "$SEEKDB_PID_FILE" != "$SYSTEMD_PID_FILE" ]; then
66+
# Create target directory if it doesn't exist
67+
mkdir -p "$(dirname "$SYSTEMD_PID_FILE")"
68+
# Remove existing link or file if exists
69+
rm -f "$SYSTEMD_PID_FILE"
70+
# Create softlink
71+
ln -s "$SEEKDB_PID_FILE" "$SYSTEMD_PID_FILE"
72+
fi
73+
6774
# Check if command executed successfully
6875
if [ $CMD_EXIT_CODE -eq 0 ]; then
69-
# Start obshell agent
76+
# Start obshell agent (ignore errors)
7077
echo "SeekDB started successfully, starting obshell agent..."
7178
if [ -f "/usr/bin/obshell" ]; then
7279
sleep 1
73-
/usr/bin/obshell agent start --seekdb --base-dir=$BASE_DIR
74-
if [ $? -eq 0 ]; then
75-
echo "obshell agent started successfully"
76-
else
77-
echo "Failed to start obshell agent"
78-
fi
80+
/usr/bin/obshell agent start --seekdb --base-dir=$BASE_DIR || true
7981
else
8082
echo "Warning: /usr/bin/obshell not found, skipping obshell agent start"
8183
fi
Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
#!/bin/bash
2+
CONFIG_FILE="/etc/oceanbase/seekdb.cnf"
23
BASE_DIR="/var/lib/oceanbase"
34

4-
pid=$(cat $BASE_DIR/run/daemon.pid)
5-
kill -9 "$pid"
6-
pid=$(cat $BASE_DIR/run/obshell.pid)
7-
kill -9 "$pid"
8-
pid=$(cat $BASE_DIR/run/observer.pid)
9-
kill -9 "$pid"
5+
# Function to read base-dir from configuration file (consistent with start script)
6+
read_base_dir_from_config() {
7+
if [ -f "$CONFIG_FILE" ]; then
8+
while IFS= read -r line; do
9+
# Skip empty lines and comments
10+
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
11+
12+
key="${line%%=*}"
13+
value="${line#*=}"
14+
15+
# Trim whitespace
16+
key="$(echo "$key" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
17+
value="$(echo "$value" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
18+
19+
if [ "$key" = "base-dir" ]; then
20+
BASE_DIR="$value"
21+
echo "Using base-dir from config: $BASE_DIR"
22+
return 0
23+
fi
24+
done < "$CONFIG_FILE"
25+
fi
26+
return 1
27+
}
28+
29+
read_base_dir_from_config
30+
31+
if [ -f "$BASE_DIR/run/daemon.pid" ]; then
32+
pid=$(cat "$BASE_DIR/run/daemon.pid")
33+
kill -9 "$pid" 2>/dev/null || true
34+
fi
35+
36+
if [ -f "$BASE_DIR/run/obshell.pid" ]; then
37+
pid=$(cat "$BASE_DIR/run/obshell.pid")
38+
kill -9 "$pid" 2>/dev/null || true
39+
fi
40+
41+
if [ -f "$BASE_DIR/run/observer.pid" ]; then
42+
pid=$(cat "$BASE_DIR/run/observer.pid")
43+
kill -9 "$pid" 2>/dev/null || true
44+
fi
45+
1046
systemd-notify "STATUS=seekdb is down"

tools/systemd/profile/telemetry.sh.template

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ function add_observer_config {
4646
}
4747

4848
function update_json {
49-
clusterId=0
50-
# Get script directory
51-
SEEKDB_TELEMETRY_FILE="$BASE_DIR/run/telemetry.json"
52-
53-
# Check if cluster_id file exists
54-
if [ -f "$SEEKDB_TELEMETRY_FILE" ]; then
55-
# If file exists, read clusterId from file cluster_id
56-
clusterId=$(grep '"id":' $SEEKDB_TELEMETRY_FILE | sed -E 's/.*"id": *"([^"]*)".*/\1/')
57-
fi
58-
5949
sed -i "s|#reporter#|${reporter}|g" $json_file
6050
sed -i "s|#type#|${type}|g" $json_file
6151
sed -i "s|#step#|${step}|g" $json_file
@@ -64,7 +54,6 @@ function update_json {
6454
sed -i "s|#hostHash#|${hostHash}|g" $json_file
6555
sed -i "s|#osName#|${osName}|g" $json_file
6656
sed -i "s|#osRelease#|${osRelease}|g" $json_file
67-
sed -i "s|#clusterId#|${clusterId}|g" $json_file
6857
}
6958

7059
# Function Name: do_telemetry

0 commit comments

Comments
 (0)