Skip to content

Commit

Permalink
Override the JNA temporary directory to point to var/data/tmp (#1673)
Browse files Browse the repository at this point in the history
Override the JNA temporary directory to point to var/data/tmp
  • Loading branch information
SerialVelocity authored Jul 31, 2024
1 parent 1004513 commit 27a49b2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1673.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: feature
feature:
description: Override the JNA temporary directory to point to var/data/tmp
links:
- https://github.com/palantir/sls-packaging/pull/1673
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public final class LaunchConfig {
private static final ImmutableList<String> alwaysOnJvmOptions = ImmutableList.of(
"-XX:+CrashOnOutOfMemoryError",
"-Djava.io.tmpdir=var/data/tmp",
"-Djna.tmpdir=var/data/tmp",
"-XX:ErrorFile=var/log/hs_err_pid%p.log",
"-XX:HeapDumpPath=var/log",
// Set DNS cache TTL to 10s to account for systems such as RDS and other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
buildFile << '''
task createConfigurationYml {
outputs.file('build/some-place/configuration.yml')
doFirst {
file('build/some-place/configuration.yml').text = 'custom: yml'
}
}
distribution {
configurationYml.fileProvider(tasks.named('createConfigurationYml').map { it.outputs.files.singleFile })
configurationYml.fileProvider(tasks.named('createConfigurationYml').map { it.outputs.files.singleFile })
}
'''.stripIndent(true)

Expand All @@ -395,14 +395,14 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
buildFile << '''
task createConfigurationYml {
outputs.file('build/some-place/something-else.yml')
doFirst {
file('build/some-place/something-else.yml').text = 'custom: yml'
}
}
distribution {
configurationYml.fileProvider(tasks.named('createConfigurationYml').map { it.outputs.files.singleFile })
configurationYml.fileProvider(tasks.named('createConfigurationYml').map { it.outputs.files.singleFile })
}
'''.stripIndent(true)

Expand Down Expand Up @@ -455,6 +455,7 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
.jvmOpts([
'-XX:+CrashOnOutOfMemoryError',
'-Djava.io.tmpdir=var/data/tmp',
'-Djna.tmpdir=var/data/tmp',
'-XX:ErrorFile=var/log/hs_err_pid%p.log',
'-XX:HeapDumpPath=var/log',
'-Dsun.net.inetaddr.ttl=10',
Expand Down Expand Up @@ -485,6 +486,7 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
.jvmOpts([
'-XX:+CrashOnOutOfMemoryError',
'-Djava.io.tmpdir=var/data/tmp',
'-Djna.tmpdir=var/data/tmp',
'-XX:ErrorFile=var/log/hs_err_pid%p.log',
'-XX:HeapDumpPath=var/log',
'-Dsun.net.inetaddr.ttl=10',
Expand Down Expand Up @@ -537,6 +539,7 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
.jvmOpts([
'-XX:+CrashOnOutOfMemoryError',
'-Djava.io.tmpdir=var/data/tmp',
'-Djna.tmpdir=var/data/tmp',
'-XX:ErrorFile=var/log/hs_err_pid%p.log',
'-XX:HeapDumpPath=var/log',
'-Dsun.net.inetaddr.ttl=10',
Expand Down Expand Up @@ -567,6 +570,7 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
.jvmOpts([
'-XX:+CrashOnOutOfMemoryError',
'-Djava.io.tmpdir=var/data/tmp',
'-Djna.tmpdir=var/data/tmp',
'-XX:ErrorFile=var/log/hs_err_pid%p.log',
'-XX:HeapDumpPath=var/log',
'-Dsun.net.inetaddr.ttl=10',
Expand Down Expand Up @@ -610,6 +614,7 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
.jvmOpts([
'-XX:+CrashOnOutOfMemoryError',
'-Djava.io.tmpdir=var/data/tmp',
'-Djna.tmpdir=var/data/tmp',
'-XX:ErrorFile=var/log/hs_err_pid%p.log',
'-XX:HeapDumpPath=var/log',
'-Dsun.net.inetaddr.ttl=10',
Expand Down Expand Up @@ -1516,11 +1521,11 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
id 'com.palantir.consistent-versions' version '${Versions.GRADLE_CONSISTENT_VERSIONS}'
id 'com.palantir.sls-java-service-distribution'
}
repositories {
mavenCentral()
}
version '0.0.1'
distribution {
serviceName 'service-name'
Expand Down
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ com.palantir.foo:foo-service ($projectVersion, 1.x.x)

_The `$projectVersion` string is a placeholder that will appear if your repo publishes multiple services, and one of them depends on another. The actual manifest will contain a concrete version._

The suffix `optional` will be added for `optional = true` in the `productDependency` declaration. All dependencies are required by default.
The suffix `optional` will be added for `optional = true` in the `productDependency` declaration. All dependencies are required by default.

It's possible to further restrict the acceptable version range for a dependency by declaring a tighter constraint in a
`productDependency` block - this will be merged with any constraints detected from other jars.
Expand Down Expand Up @@ -208,7 +208,7 @@ Apply the plugin using standard Gradle convention:
Additionally, declare the version of [go-java-launcher](https://github.com/palantir/go-java-launcher) to use:

```
# Add to 'versions.props'
# Add to 'versions.props'
com.palantir.launching:* = 1.18.0
```

Expand Down Expand Up @@ -263,7 +263,7 @@ And the complete list of configurable properties:
* (optional) `javaHome` a fixed override for the `JAVA_HOME` environment variable that will
be applied when `init.sh` is run. When your `targetCompatibility` is Java 8 or less, this value will be blank. For
Java 9 or higher will default to `$JAVA_<majorversion>_HOME` ie for Java 11 this would be `$JAVA_11_HOME`.
* (optional) `gc` override the default GC settings. Available GC settings: `throughput` (default for Java 14 and lower), `hybrid` (default for Java 15 and higher) and `response-time`. Additionally, there is also `dangerous-no-profile` which does not apply any additional JVM flags and allows you to fully configure any GC settings through JVM options (not recommended for normal usage!).
* (optional) `gc` override the default GC settings. Available GC settings: `throughput` (default for Java 14 and lower), `hybrid` (default for Java 15 and higher) and `response-time`. Additionally, there is also `dangerous-no-profile` which does not apply any additional JVM flags and allows you to fully configure any GC settings through JVM options (not recommended for normal usage!).
* (optional) `addJava8GcLogging` add java 8 specific gc logging options.

#### JVM Options
Expand All @@ -275,6 +275,8 @@ concatenating the following list of hard-coded *required options* and the list o
Hard-coded required JVM options:
- `-Djava.io.tmpdir=var/data/tmp`: Allocates temporary files inside the application installation folder rather than on
`/tmp`; the latter is often space-constrained on cloud hosts.
- `-Djna.tmpdir=var/data/tmp`: Allocates temporary JNA files inside the application installation folder rather than on
`${USER}/.cache`; the latter is often space-constrained on cloud hosts and filling it up can result in users not being able to login.

The `go-java-launcher` and `init.sh` launchers additionally append the list of JVM options specified in the
`var/conf/launcher-custom.yml` [configuration file](https://github.com/palantir/go-java-launcher). Note that later
Expand Down

0 comments on commit 27a49b2

Please sign in to comment.