diff --git a/Jenkinsfile b/Jenkinsfile index c2a0b3307b8..01cfb7c01ab 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -158,6 +158,7 @@ spec: PORT_ADMIN=4848 PORT_HTTP=8080 PORT_HTTPS=8181 + AS_RESTART_LOGFILES="true" } options { @@ -187,22 +188,19 @@ spec: container('maven') { dumpSysInfo() sh ''' - # Validate the structure in all submodules (especially version ids) - mvn -B -e -fae clean validate -Ptck,set-version-id,staging - # Until we fix ANTLR in cmp-support-sqlstore, broken in parallel builds. Just -Pfast after the fix. mvn -B -e install -Pfastest,staging -T4C - ./gfbuild.sh archive_bundles - ./gfbuild.sh archive_embedded - mvn -B -e clean -Pstaging - tar -c -C ${WORKSPACE}/appserver/tests common_test.sh gftest.sh appserv-tests quicklook | gzip --fast > ${WORKSPACE}/bundles/appserv_tests.tar.gz - ls -la ${WORKSPACE}/bundles - ls -la ${WORKSPACE}/embedded + mvn -B -e clean install -pl :admin-tests-parent -amd ''' } archiveArtifacts artifacts: 'bundles/*.zip', onlyIfSuccessful: true archiveArtifacts artifacts: 'embedded/*', onlyIfSuccessful: true stash includes: 'bundles/*', name: 'build-bundles' } + post { + always { + archiveArtifacts artifacts: "**/*.log*", onlyIfSuccessful: false + } + } } stage('mvn-tests') { steps { diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminLoggingITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminLoggingITest.java index 12682968db3..72deaf55b9f 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminLoggingITest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminLoggingITest.java @@ -16,6 +16,8 @@ package org.glassfish.main.admin.test; +import com.sun.enterprise.util.OS; + import java.io.File; import java.io.FileReader; import java.io.LineNumberReader; @@ -68,9 +70,13 @@ public class AsadminLoggingITest { private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin(); @BeforeAll - public static void fillUpServerLog() { + public static void fillUpServerLog() throws Exception { // Fill up the server log. AsadminResult result = ASADMIN.exec(60_000, "restart-domain"); + if (OS.isLinux()) { + new ProcessBuilder("ps", "-lAf").inheritIO().start().waitFor(); + } + assertThat(result, asadminOK()); } diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java index 26b40498e8e..5b86d0b0057 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java @@ -34,6 +34,8 @@ import java.time.Duration; import java.time.Instant; import java.util.Optional; +import java.util.concurrent.CancellationException; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -76,19 +78,21 @@ private ProcessUtils() { * @return true if the handle was not found or exited before timeout. False otherwise. */ public static boolean waitWhileIsAlive(final long pid, Duration timeout, boolean printDots) { - Optional handle = ProcessHandle.of(pid); - if (handle.isEmpty()) { + ProcessHandle handle = ProcessHandle.of(pid).orElse(null); + if (handle == null || !handle.isAlive() || handle.parent().isEmpty()) { + LOG.log(INFO, "Could not find the process with id " + pid + ", probably already died. Returning true."); return true; } final DotPrinter dotPrinter = DotPrinter.startWaiting(printDots); try { - handle.get().onExit().get(timeout.toSeconds(), TimeUnit.SECONDS); - return true; + final CompletableFuture onExit = handle.onExit(); + onExit.get(timeout.toSeconds(), TimeUnit.SECONDS); + return !handle.isAlive(); } catch (TimeoutException e) { - LOG.log(TRACE, "Timeout while waiting for exit of process with id " + pid + ". Returning false.", e); + LOG.log(INFO, "Timeout while waiting for exit of process with id " + pid + ". Returning false.", e); return false; - } catch (InterruptedException | ExecutionException e) { - LOG.log(TRACE, "Exception while waiting for exit of process with id " + pid + ". Returning true.", e); + } catch (CancellationException | InterruptedException | ExecutionException e) { + LOG.log(INFO, "Exception while waiting for exit of process with id " + pid + ". Returning true.", e); return true; } finally { DotPrinter.stopWaiting(dotPrinter); diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/RestartServer.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/RestartServer.java index 6214fe54d4f..a0c663715ce 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/RestartServer.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/RestartServer.java @@ -104,7 +104,6 @@ protected final void doExecute(AdminCommandContext context) { } scheduleReincarnation(); } - // else we just return a special int from System.exit() gfKernel.stop(); } catch (Exception e) { throw new Error(strings.get("restart.server.failure"), e); @@ -116,6 +115,7 @@ protected final void doExecute(AdminCommandContext context) { } else { restartType = debug ? RESTART_DEBUG_ON : RESTART_DEBUG_OFF; } + // return a special int from System.exit() System.exit(restartType); } diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/StartServerHook.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/StartServerHook.java index 43ae119d848..656e8386e7e 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/StartServerHook.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/StartServerHook.java @@ -217,10 +217,11 @@ private static ProcessBuilder prepareStartup(Instant now, String classpath, Stri // To avoid conflict of the debug port used both by old and new JVM, // we will force waiting for the end of the old JVM. outerCommand = new ArrayList<>(); + outerCommand.add("nohup"); outerCommand.add("bash"); outerCommand.add("-c"); - outerCommand.add("tail --pid=" + ProcessHandle.current().pid() + " -f /dev/null && " - + cmdline.stream().collect(Collectors.joining(" "))); + outerCommand.add("(waitpid -e " + ProcessHandle.current().pid() + " || sleep 1) && '" + + cmdline.stream().collect(Collectors.joining("' '")) + "'"); } final ProcessBuilder builder = new ProcessBuilder(outerCommand);