diff --git a/tools/systemd/profile/seekdb.cnf b/tools/systemd/profile/seekdb.cnf index d1641fd8c..59b60df21 100644 --- a/tools/systemd/profile/seekdb.cnf +++ b/tools/systemd/profile/seekdb.cnf @@ -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 diff --git a/tools/systemd/profile/seekdb.service b/tools/systemd/profile/seekdb.service index a7c738bf4..7fb340473 100644 --- a/tools/systemd/profile/seekdb.service +++ b/tools/systemd/profile/seekdb.service @@ -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 diff --git a/tools/systemd/profile/seekdb_systemd_start b/tools/systemd/profile/seekdb_systemd_start index 3a011cbd0..a8664cbc5 100644 --- a/tools/systemd/profile/seekdb_systemd_start +++ b/tools/systemd/profile/seekdb_systemd_start @@ -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 @@ -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 \ No newline at end of file +exec $CMD diff --git a/tools/systemd/profile/seekdb_systemd_stop b/tools/systemd/profile/seekdb_systemd_stop index be5932327..0d65914a0 100644 --- a/tools/systemd/profile/seekdb_systemd_stop +++ b/tools/systemd/profile/seekdb_systemd_stop @@ -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() { @@ -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" \ No newline at end of file