Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tools/systemd/profile/seekdb.cnf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# These parameters are permanently valid
base-dir=/var/lib/oceanbase
data-dir=/var/lib/oceanbase/store
redo-dir=/var/lib/oceanbase/store/redo
base-dir=/var/lib/seekdb
data-dir=/var/lib/seekdb/store
redo-dir=/var/lib/seekdb/store/redo

# These parameters are valid only during initialization
port=2881
Expand Down
3 changes: 1 addition & 2 deletions tools/systemd/profile/seekdb.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ Type=notify
Environment=REPORTER=systemd
ExecStart=/usr/libexec/seekdb/scripts/seekdb_systemd_start
ExecStop=/usr/libexec/seekdb/scripts/seekdb_systemd_stop
PIDFile=/var/lib/seekdb/run/seekdb.pid
NotifyAccess=all
NotifyAccess=main
Restart=on-failure
RestartSec=3
KillMode=process
Expand Down
35 changes: 3 additions & 32 deletions tools/systemd/profile/seekdb_systemd_start
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

CONFIG_FILE="/etc/seekdb/seekdb.cnf"
BASE_DIR="/var/lib/seekdb"
SYSTEMD_PID_FILE="$BASE_DIR/run/seekdb.pid"

# Check if config file exists
if [ ! -f "$CONFIG_FILE" ]; then
Expand Down Expand Up @@ -72,41 +71,13 @@ if [ "$force_start_with_args" = "true" ] || [ "$force_start_with_args" = "1" ] |
( [ ! -d "$REDO_DIR" ] || [ -z "$(ls -A "$REDO_DIR" 2>/dev/null)" ] ) && \
[ ! -f "$BASE_DIR/.meta" ] ); then
# New database initialization, use all parameters
CMD="/usr/bin/seekdb --base-dir=$BASE_DIR $ADDITIONAL_PARAMS"
CMD="/usr/bin/seekdb --nodaemon --base-dir=$BASE_DIR $ADDITIONAL_PARAMS"
else
# Existing database, only use base-dir
CMD="/usr/bin/seekdb --base-dir=$BASE_DIR"
CMD="/usr/bin/seekdb --nodaemon --base-dir=$BASE_DIR"
fi

echo "Starting seekdb with command: $CMD"
echo "Configuration loaded from: $CONFIG_FILE"

$CMD
CMD_EXIT_CODE=$?

# Create softlink for PID file to systemd expected location
SEEKDB_PID_FILE="$BASE_DIR/run/seekdb.pid"
if [ -f "$SEEKDB_PID_FILE" ] && [ "$SEEKDB_PID_FILE" != "$SYSTEMD_PID_FILE" ]; then
# Create target directory if it doesn't exist
mkdir -p "$(dirname "$SYSTEMD_PID_FILE")"
# Remove existing link or file if exists
rm -f "$SYSTEMD_PID_FILE"
# Create softlink
ln -s "$SEEKDB_PID_FILE" "$SYSTEMD_PID_FILE"
fi

# Check if command executed successfully
if [ $CMD_EXIT_CODE -eq 0 ]; then
# Start obshell agent (ignore errors)
echo "SeekDB started successfully, starting obshell agent..."
if [ -f "/usr/bin/obshell" ]; then
sleep 1
/usr/bin/obshell agent start --seekdb --base-dir=$BASE_DIR || true
else
echo "Warning: /usr/bin/obshell not found, skipping obshell agent start"
fi
else
echo "SeekDB failed to start with exit code: $CMD_EXIT_CODE"
fi

exit $CMD_EXIT_CODE
exec $CMD
31 changes: 21 additions & 10 deletions tools/systemd/profile/seekdb_systemd_stop
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
CONFIG_FILE="/etc/seekdb/seekdb.cnf"
BASE_DIR="/var/lib/seekdb"
STOP_TIMEOUT="${SEEKDB_STOP_TIMEOUT:-30}"

# Function to read base-dir from configuration file (consistent with start script)
read_base_dir_from_config() {
Expand Down Expand Up @@ -28,19 +29,29 @@ read_base_dir_from_config() {

read_base_dir_from_config

if [ -f "$BASE_DIR/run/daemon.pid" ]; then
pid=$(cat "$BASE_DIR/run/daemon.pid")
kill -9 "$pid" 2>/dev/null || true
pid="${MAINPID:-}"
if [ -z "$pid" ] && [ -f "$BASE_DIR/run/seekdb.pid" ]; then
pid=$(cat "$BASE_DIR/run/seekdb.pid" 2>/dev/null || true)
fi

if [ -f "$BASE_DIR/run/obshell.pid" ]; then
pid=$(cat "$BASE_DIR/run/obshell.pid")
kill -9 "$pid" 2>/dev/null || true
case "$pid" in
''|*[!0-9]*) exit 0 ;;
esac

if [ "$pid" -le 1 ] || ! kill -0 "$pid" 2>/dev/null; then
exit 0
fi

if [ -f "$BASE_DIR/run/seekdb.pid" ]; then
pid=$(cat "$BASE_DIR/run/seekdb.pid")
echo "Stopping seekdb process $pid"
kill -USR1 "$pid" 2>/dev/null || exit 0

elapsed=0
while kill -0 "$pid" 2>/dev/null && [ "$elapsed" -lt "$STOP_TIMEOUT" ]; do
sleep 1
elapsed=$((elapsed + 1))
done

if kill -0 "$pid" 2>/dev/null; then
echo "SeekDB did not stop within ${STOP_TIMEOUT}s, forcing shutdown"
kill -9 "$pid" 2>/dev/null || true
fi

systemd-notify "STATUS=seekdb is down"
Loading