diff --git a/doctest/build.gradle b/doctest/build.gradle index b062a57d5d0..08d5c43b7d2 100644 --- a/doctest/build.gradle +++ b/doctest/build.gradle @@ -42,6 +42,19 @@ task bootstrap(type: Exec, dependsOn: ['cloneSqlCli']) { commandLine 'sh', "$projectDir/bootstrap.sh" } +def isPrometheusRunning = { -> + try { + def process = "pgrep -f prometheus".execute() + def output = process.text + def result = !output.trim().isEmpty() + println "Prometheus running status: ${result}" + return result + } catch (Exception e) { + println "Error checking Prometheus process: ${e.message}" + return false + } +} + task startPrometheus(type: SpawnProcessTask) { doFirst { download.run { @@ -62,7 +75,7 @@ task startPrometheus(type: SpawnProcessTask) { command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' pidLockFileName ".prom.pid.lock" - onlyIf { !ignorePrometheus && getOSFamilyType() != "windows" } + onlyIf { !ignorePrometheus && getOSFamilyType() != "windows" && !isPrometheusRunning() } } diff --git a/integ-test/build.gradle b/integ-test/build.gradle index 481eb7fe9d9..197eddf7495 100644 --- a/integ-test/build.gradle +++ b/integ-test/build.gradle @@ -283,6 +283,19 @@ testClusters { } } +def isPrometheusRunning() { + try { + def process = "pgrep -f prometheus".execute() + def output = process.text + def result = !output.trim().isEmpty() + println "Prometheus running status: ${result}" + return result + } catch (Exception e) { + println "Error checking Prometheus process: ${e.message}" + return false + } +} + task startPrometheus(type: SpawnProcessTask) { mustRunAfter ':doctest:doctest' @@ -304,7 +317,7 @@ task startPrometheus(type: SpawnProcessTask) { } command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' - onlyIf { !ignorePrometheus } + onlyIf { !ignorePrometheus && !isPrometheusRunning() } } task stopPrometheus(type: KillProcessTask) {