Skip to content

Commit f7eeb30

Browse files
authored
Warning added for embedded = true mode (#1084)
* Warning added for embedded = true mode * correcting runtime * updating runtimeUrl to later version * updating runtimeUrl to later version
1 parent 5566c59 commit f7eeb30

6 files changed

Lines changed: 28 additions & 8 deletions

File tree

docs/libertyExtensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The following properties are supported for server configuration.
3636
| clean | boolean | 1.0 | Clean all cached information on server start up. It deletes every file in the `${wlp_output_dir}/logs`, `${wlp_output_dir}/workarea`, `${wlp_user_dir}/dropins` or `${wlp_user_dir}/apps`. The default value is `false`. Only used with the `libertyStart` and `libertyRun` tasks. | No |
3737
| configDirectory| File | 2.0 | Location of a server configuration directory to be used by the server instance. Configuration files and folder structure will be copied to the server instance. Files specified by other server extension properties will take precedence over files located in the configDirectory. The default value is `/src/main/liberty/config`. | No|
3838
| defaultVar | Properties | 3.0 | Inline server variables that are written to the `configDropins/defaults/liberty-plugin-variable-config.xml` file in the server directory. The property name is used for the variable `name`, and the property value is used for the variable `defaultValue`. If you are using [dev container mode](libertyDev.md#libertydevc-task-container-mode), ensure to copy the configDropins/defaults folder into your container image.| No|
39-
| embedded | boolean | 2.7 | Whether the server is [embedded](https://www.ibm.com/support/knowledgecenter/SSD28V_9.0.0/com.ibm.websphere.wlp.core.doc/ae/twlp_extend_embed.html) in the Gradle JVM. If not, the server will run as a separate process. The default value is `false`. Only used with the `libertyStart`, `libertyRun` and `libertyStop` tasks. | No |
39+
| embedded | boolean | 2.7 | Whether the server is [embedded](https://www.ibm.com/support/knowledgecenter/SSD28V_9.0.0/com.ibm.websphere.wlp.core.doc/ae/twlp_extend_embed.html) in the Gradle JVM. If not, the server will run as a separate process. The default value is `false`. Only used with the `libertyStart`, `libertyRun` and `libertyStop` tasks. **Note:** When using embedded mode with the Gradle daemon and `libertyRun`, the server will continue running in the daemon JVM after pressing Ctrl+C. Use `gradle libertyStop` or `gradle --stop` to stop the server. See [libertyRun](libertyRun.md#embedded-server-mode-with-gradle-daemon) for more details. | No |
4040
| env | Properties | 3.0 | Inline server environment variables that are written to the server.env file in the server directory. These properties take precedence over a specified server.env file. | No|
4141
| jvmOptions| List | 2.0 | Inline `List` of jvm options that is written to the jvm.options file in the server directory. These properties take precedence over a specified jvm.options file. | No|
4242
| jvmOptionsFile| File | 2.0 | Location of the file containing JVM options to copy to the jvm.options file in the server instance. | No|

docs/libertyRun.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,22 @@ gradle libertyRun --no-daemon
1010
`libertyRun` also depends on `deploy` if configured.
1111

1212
### What is the Gradle Daemon and why --no-daemon?
13-
The Gradle Daemon is a long-running background process designed to help speed up the build process. It does so by caching project information and staying alive, avoiding constant JVM startup costs. This behavior is default until specified otherwise.
14-
Gradle's current daemon design makes it difficult to use a `run` task, as a Ctrl-C would kill the daemon while simultaneously leaving the application running in the background. Therefore, we need `--no-daemon` so that the signal can be received and properly handled.
15-
In the event that a user does run a `libertyRun` with a daemon (default), an external `libertyStop` must be called in order to properly shut down the server. A Ctrl-C while the Gradle process is running will not stop the server. Use `libertyStatus` to confirm the state of your server.
13+
The Gradle Daemon is a long-running background process designed to help speed up the build process. It does so by caching project information and staying alive, avoiding constant JVM startup costs. This behavior is default until specified otherwise.
14+
Gradle's current daemon design makes it difficult to use a `run` task, as a Ctrl-C would kill the daemon while simultaneously leaving the application running in the background. Therefore, we need `--no-daemon` so that the signal can be received and properly handled.
15+
In the event that a user does run a `libertyRun` with a daemon (default), an external `libertyStop` must be called in order to properly shut down the server. A Ctrl-C while the Gradle process is running will not stop the server. Use `libertyStatus` to confirm the state of your server.
16+
17+
### Embedded Server Mode with Gradle Daemon
18+
When using `embedded = true` in the Liberty server configuration along with the Gradle daemon, the Liberty server runs within the daemon JVM. This creates an additional complication:
19+
- Pressing Ctrl-C terminates the client connection but **not** the daemon JVM
20+
- The embedded Liberty server continues running in the daemon JVM
21+
- The shutdown hook registered by the plugin does not execute because the daemon JVM remains alive
22+
23+
**Workarounds:**
24+
1. Use `gradle libertyStop` to stop the embedded server
25+
2. Use `gradle --stop` to stop the entire Gradle daemon (which will also stop the embedded server)
26+
3. Use `--no-daemon` flag when running `libertyRun` to avoid this issue entirely
27+
28+
**Recommendation:** For embedded server mode, it is strongly recommended to use `--no-daemon` or avoid using embedded mode with the daemon.
1629

1730
### 0% or 66% Executing?
1831
While running this task, Gradle will show something like:

src/main/groovy/io/openliberty/tools/gradle/tasks/RunTask.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class RunTask extends AbstractServerTask {
5252
ServerTask serverTaskRun = createServerTask(project, "run");
5353
serverTaskRun.setUseEmbeddedServer(server.embedded)
5454
serverTaskRun.setClean(server.clean)
55+
56+
// When using embedded mode with Gradle daemon, the shutdown hook may not execute on Ctrl+C
57+
// because the daemon JVM continues running. Warn the user about this limitation.
58+
logger.warn("Starting Liberty server in embedded mode. Note: When using the Gradle daemon, " +
59+
"the server may continue running after pressing Ctrl+C. " +
60+
"Use 'gradle libertyStop' to stop the server or 'gradle --stop' to stop the daemon.")
61+
5562
serverTaskRun.execute();
5663
} else {
5764
List<String> command = buildCommand("run")

src/test/groovy/io/openliberty/tools/gradle/InstallLiberty_runtimeUrl_upToDate_Test.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class InstallLiberty_runtimeUrl_upToDate_Test extends AbstractIntegrationTest{
4141

4242
@Test
4343
public void test_installLiberty_upToDate() {
44-
assert runTaskCheckForUpToDate(buildDir, 'installLiberty', "-PlibertyRuntimeUrl=https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/release/2021-01-13_1459/openliberty-javaee8-21.0.0.1.zip")
45-
assertFalse runTaskCheckForUpToDate(buildDir, 'installLiberty', "-PlibertyRuntimeUrl=https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/release/2021-02-09_1100/openliberty-javaee8-21.0.0.2.zip")
44+
assert runTaskCheckForUpToDate(buildDir, 'installLiberty', "-PlibertyRuntimeUrl=https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/release/25.0.0.12/openliberty-javaee8-25.0.0.12.zip")
45+
assertFalse runTaskCheckForUpToDate(buildDir, 'installLiberty', "-PlibertyRuntimeUrl=https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/release/26.0.0.3/openliberty-javaee8-26.0.0.3.zip")
4646
}
4747
}

src/test/resources/liberty-test/installLiberty_upToDate_runtimeUrl_Test.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ buildscript {
1414
apply plugin: 'liberty'
1515

1616
ext {
17-
libertyRuntimeUrl = project.hasProperty('libertyRuntimeUrl') ? project.getProperty('libertyRuntimeUrl') : "https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/release/2021-01-13_1459/openliberty-javaee8-21.0.0.1.zip"
17+
libertyRuntimeUrl = project.hasProperty('libertyRuntimeUrl') ? project.getProperty('libertyRuntimeUrl') : "https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/release/25.0.0.12/openliberty-javaee8-25.0.0.12.zip"
1818
}
1919

2020

src/test/resources/sample.springboot3/test_spring_boot_classifier_apps_30_no_feature.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ repositories {
3232
dependencies {
3333
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
3434
testImplementation('org.springframework.boot:spring-boot-starter-test')
35-
libertyRuntime group: 'com.ibm.websphere.appserver.runtime', name: 'wlp-jakartaee10', version: '23.0.0.10'
35+
libertyRuntime group: 'com.ibm.websphere.appserver.runtime', name: 'wlp-kernel', version: runtimeVersion
3636
}
3737

3838
bootJar {

0 commit comments

Comments
 (0)