diff --git a/scripts/sbin/start-edge.sh b/scripts/sbin/start-edge.sh index be1a70ea6f79..48fca53befda 100644 --- a/scripts/sbin/start-edge.sh +++ b/scripts/sbin/start-edge.sh @@ -21,8 +21,16 @@ # Start IoTDB Edge: ConfigNode + DataNode in one JVM process. if [ -z "${IOTDB_HOME}" ]; then - export IOTDB_HOME="$(cd "$(dirname "$0")"/.. && pwd)" + IOTDB_HOME="$(dirname "$0")/.." fi +# Normalise to a physical absolute path. This value is handed to the JVM as +# -DIOTDB_HOME and is what stop-edge.sh matches on, so it has to identify the +# installation on its own, independently of the path used to launch. +IOTDB_HOME_PHYSICAL="$(cd -P -- "${IOTDB_HOME}" 2>/dev/null && pwd -P)" +if [ -n "${IOTDB_HOME_PHYSICAL}" ]; then + IOTDB_HOME="${IOTDB_HOME_PHYSICAL}" +fi +export IOTDB_HOME if [ -z "${IOTDB_CONF}" ]; then export IOTDB_CONF=${IOTDB_HOME}/conf fi diff --git a/scripts/sbin/stop-edge.sh b/scripts/sbin/stop-edge.sh index 8f8f98ac64b1..0d1cb0bef9ef 100644 --- a/scripts/sbin/stop-edge.sh +++ b/scripts/sbin/stop-edge.sh @@ -20,7 +20,19 @@ # Stop IoTDB Edge (the merged ConfigNode + DataNode process). -IOTDB_HOME="$(cd "$(dirname "$0")"/.. && pwd)" +if [ -z "${IOTDB_HOME}" ]; then + IOTDB_HOME="$(cd "$(dirname "$0")"/.. && pwd)" +fi + +# Resolve to a physical absolute path so that the same installation reached +# through a different path still compares equal. "cd -P" is required: a plain +# "cd" collapses ".." logically, which would resolve "/../x" against the +# symlink's parent instead of its target. +resolve_home() { + (cd -P -- "$1" 2>/dev/null && pwd -P) || printf '%s' "$1" +} + +IOTDB_HOME_RESOLVED="$(resolve_home "${IOTDB_HOME}")" PID_FILE="${IOTDB_HOME}/edge.pid" @@ -31,9 +43,27 @@ is_same_edge_home() { return 0 ;; *) - return 1 ;; esac + # Fall back to comparing resolved paths, so that a start-edge.sh invoked with + # IOTDB_HOME pointing at a symlink is still recognised here. The value is + # delimited by the next " -D", which start-edge.sh always emits after + # -DIOTDB_HOME. If a hand-built command line ends with -DIOTDB_HOME, the + # extraction keeps the trailing arguments, the resolution below fails and the + # process is simply not matched -- never matched to the wrong installation. + local home="${command_line#*-DIOTDB_HOME=}" + home="${home%% -D*}" + [ -n "$home" ] && [ "$home" != "$command_line" ] || return 1 + # Only absolute values can be resolved from here. A relative one such as "." + # is meaningful in the started process's working directory, not in ours, so + # resolving it here could match an unrelated installation. The emptiness check + # above matters for the same reason: "cd" succeeds on an empty argument and + # yields our own working directory. + case "$home" in + /*) ;; + *) return 1 ;; + esac + [ "$(resolve_home "$home")" = "${IOTDB_HOME_RESOLVED}" ] } is_edge_process() {