diff --git a/doctest/build.gradle b/doctest/build.gradle index f01d457a59f..d758a6de4b8 100644 --- a/doctest/build.gradle +++ b/doctest/build.gradle @@ -43,6 +43,19 @@ task bootstrap(type: Exec, dependsOn: ['cloneSqlCli']) { } +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 { @@ -63,7 +76,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() } } //evaluationDependsOn(':') diff --git a/integ-test/build.gradle b/integ-test/build.gradle index 8578d882844..8a55e4c47c3 100644 --- a/integ-test/build.gradle +++ b/integ-test/build.gradle @@ -295,6 +295,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' @@ -319,7 +332,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) {