Skip to content

Commit 52d38da

Browse files
committed
[jmx-scraper] Package jmx scraper as a deb/rpm/tar.gz package #1964
- #1964 - added copyJarForPackage for gradle to copy jar for packaging - added createTarBall to create a packaged tar.gz - added systemd service file
1 parent 89c1afb commit 52d38da

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

jmx-scraper/build.gradle.kts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
plugins {
22
application
33
id("com.gradleup.shadow")
4-
54
id("otel.java-conventions")
6-
75
id("otel.publish-conventions")
86
}
97

@@ -92,6 +90,39 @@ tasks {
9290
}
9391
}
9492

93+
// This task copies the jar to a package dir for packaging.
94+
val copyJarForPackage by tasks.registering(Copy::class) {
95+
dependsOn(tasks.jar)
96+
97+
// Clean target directory before copying
98+
doFirst {
99+
val targetDir = file("package/usr/local/bin")
100+
if (targetDir.exists()) {
101+
targetDir.deleteRecursively()
102+
}
103+
}
104+
105+
from(tasks.jar.get().outputs.files)
106+
into("package/usr/local/bin")
107+
rename { "jmx-scraper.jar" }
108+
}
109+
110+
// This task creates a tarball of the package directory.
111+
val createTarball by tasks.registering(Tar::class) {
112+
dependsOn(copyJarForPackage)
113+
archiveBaseName.set("opentelemetry-jmx-scraper")
114+
archiveVersion.set(project.version.toString())
115+
archiveExtension.set("tar.gz")
116+
compression = Compression.GZIP
117+
// simply put it at the project root
118+
destinationDirectory.set(file("./"))
119+
120+
from("package") {
121+
// preserve directory structure relative to package/
122+
into("/")
123+
}
124+
}
125+
95126
// Don't publish non-shadowed jar (shadowJar is in shadowRuntimeElements)
96127
with(components["java"] as AdhocComponentWithVariants) {
97128
configurations.forEach {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=OpenTelemetry JMX Scraper
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
User=jmxscraper
8+
Group=jmxscraper
9+
ExecStart=/usr/bin/java -jar /usr/local/bin/jmx-scraper.jar
10+
Restart=on-failure
11+
RestartSec=10
12+
WorkingDirectory=/usr/local/bin
13+
14+
[Install]
15+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)