Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2746 from oleg-nenashev/bug/JENKINS-32820
[JENKINS-32820, JENKINS-42164] - Windows service restart does not retain the build queue
(cherry picked from commit 4ab6938)
  • Loading branch information
oleg-nenashev authored and olivergondza committed Mar 15, 2017
1 parent e2a8c0e commit 5f655a5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
12 changes: 9 additions & 3 deletions core/src/main/java/hudson/WebAppMain.java
Expand Up @@ -375,10 +375,16 @@ public FileAndDescription getHomeDir(ServletContextEvent event) {

public void contextDestroyed(ServletContextEvent event) {
try (ACLContext old = ACL.as(ACL.SYSTEM)) {
terminated = true;
Jenkins instance = Jenkins.getInstanceOrNull();
if (instance != null)
instance.cleanUp();
try {
if (instance != null) {
instance.cleanUp();
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to clean up. Restart will continue.", e);
}

terminated = true;
Thread t = initThread;
if (t != null && t.isAlive()) {
LOGGER.log(Level.INFO, "Shutting down a Jenkins instance that was still starting up", new Throwable("reason"));
Expand Down
15 changes: 12 additions & 3 deletions core/src/main/java/hudson/lifecycle/SolarisSMFLifecycle.java
Expand Up @@ -26,6 +26,8 @@
import jenkins.model.Jenkins;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* {@link Lifecycle} for Hudson installed as SMF service.
Expand All @@ -38,9 +40,16 @@ public class SolarisSMFLifecycle extends Lifecycle {
*/
@Override
public void restart() throws IOException, InterruptedException {
Jenkins h = Jenkins.getInstanceOrNull(); // guard against repeated concurrent calls to restart
if (h != null)
h.cleanUp();
Jenkins jenkins = Jenkins.getInstanceOrNull(); // guard against repeated concurrent calls to restart
try {
if (jenkins != null) {
jenkins.cleanUp();
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to clean up. Restart will continue.", e);
}
System.exit(0);
}

private static final Logger LOGGER = Logger.getLogger(SolarisSMFLifecycle.class.getName());
}
15 changes: 12 additions & 3 deletions core/src/main/java/hudson/lifecycle/UnixLifecycle.java
Expand Up @@ -28,6 +28,8 @@
import com.sun.jna.StringArray;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import static hudson.util.jna.GNUCLibrary.*;

Expand Down Expand Up @@ -65,9 +67,14 @@ public UnixLifecycle() throws IOException {

@Override
public void restart() throws IOException, InterruptedException {
Jenkins h = Jenkins.getInstanceOrNull(); // guard against repeated concurrent calls to restart
if (h != null)
h.cleanUp();
Jenkins jenkins = Jenkins.getInstanceOrNull(); // guard against repeated concurrent calls to restart
try {
if (jenkins != null) {
jenkins.cleanUp();
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to clean up. Restart will continue.", e);
}

// close all files upon exec, except stdin, stdout, and stderr
int sz = LIBC.getdtablesize();
Expand Down Expand Up @@ -96,4 +103,6 @@ public void verifyRestartable() throws RestartNotSupportedException {
if (args==null)
throw new RestartNotSupportedException("Failed to obtain the command line arguments of the process",failedToObtainArgs);
}

private static final Logger LOGGER = Logger.getLogger(UnixLifecycle.class.getName());
}
Expand Up @@ -117,6 +117,15 @@ public void rewriteHudsonWar(File by) throws IOException {

@Override
public void restart() throws IOException, InterruptedException {
Jenkins jenkins = Jenkins.getInstanceOrNull();
try {
if (jenkins != null) {
jenkins.cleanUp();
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to clean up. Restart will continue.", e);
}

File me = getHudsonWar();
File home = me.getParentFile();

Expand Down

0 comments on commit 5f655a5

Please sign in to comment.