Skip to content

Commit b2ff0d2

Browse files
committed
chore: improve jdk detect and process detect
1 parent 3bdac5e commit b2ff0d2

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

dist/src/bin/start-dongting.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ if ($env:JAVA_HOME -and (Test-Path (Join-Path $env:JAVA_HOME "bin\java.exe"))) {
3131
$Java = "java"
3232
}
3333

34-
# Get Java major version
34+
# Get Java major version (handles both Java 8 "1.8.x" and Java 9+ "11.x" formats)
3535
try {
3636
$versionOutput = & $Java -version 2>&1 | Select-Object -First 1
37-
if ($versionOutput -match 'version "(\d+)') {
38-
$JavaVersion = [int]$Matches[1]
37+
if ($versionOutput -match 'version "(1\.)?(\d+)') {
38+
$JavaVersion = [int]$Matches[2]
3939
} else {
4040
Write-Error "Failed to detect Java version"
4141
exit 1

dist/src/bin/start-dongting.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ else
3232
JAVA="java"
3333
fi
3434

35-
# Get Java major version
36-
JAVA_VERSION=$($JAVA -version 2>&1 | head -1 | sed -E 's/.*version "([0-9]+).*/\1/')
35+
# Get Java major version (handles both Java 8 "1.8.x" and Java 9+ "11.x" formats)
36+
JAVA_VERSION=$($JAVA -version 2>&1 | head -1 | sed -E 's/.*version "(1\.)?([0-9]+).*/\2/')
3737
if [ -z "$JAVA_VERSION" ] || ! [ "$JAVA_VERSION" -gt 0 ] 2>/dev/null; then
3838
echo "Failed to detect Java version" >&2
3939
exit 1
@@ -116,11 +116,15 @@ if ! kill -0 "$NEW_PID" 2>/dev/null; then
116116
fi
117117

118118
# Verify it's the expected Java process
119-
if ! ps -p "$NEW_PID" -o args= 2>/dev/null | grep -q "dongting.dist/com.github.dtprj.dongting.dist.Bootstrap"; then
120-
echo "Failed to start dongting: PID $NEW_PID is not a dongting process" >&2
121-
kill "$NEW_PID" 2>/dev/null || true
122-
exit 1
123-
fi
119+
CMDLINE=$(ps -p "$NEW_PID" -o args= 2>/dev/null) || CMDLINE=""
120+
case "$CMDLINE" in
121+
*"dongting.dist/com.github.dtprj.dongting.dist.Bootstrap"*) ;;
122+
*)
123+
echo "Failed to start dongting: PID $NEW_PID is not a dongting process" >&2
124+
kill "$NEW_PID" 2>/dev/null || true
125+
exit 1
126+
;;
127+
esac
124128

125129
echo "$NEW_PID" >"$PID_FILE" || {
126130
echo "Failed to write PID file $PID_FILE" >&2

0 commit comments

Comments
 (0)