Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-31181

setting slave temporally offline/online not persisted to disk

      Setting a node temporarily to offline or online is not persisted to disk. Normally this is not an issue but each time I have to restart Jenkins this a big issue. Nodes that should be offiline after a restart is not and nodes that should be online is offiline. The only way to update the temporarily offline status is to change something in the node configuration and save.

      I believed this worked in the past I do not know the version. I do not restart often and it took me some time to notice this.

          [JENKINS-31181] setting slave temporally offline/online not persisted to disk

          Asmund Ostvold added a comment - - edited

          I have found a solution that works for jenkins-1.635.

          diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java
          index a3ddb20..e76dfdd 100644
          --- a/core/src/main/java/hudson/model/Computer.java
          +++ b/core/src/main/java/hudson/model/Computer.java
          @@ -694,6 +694,14 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
                   Node node = getNode();
                   if (node != null) {
                       node.setTemporaryOfflineCause(offlineCause);
          +           try {
          +               node.save();
          +           } catch (IOException e) {
          +                LogRecord lr = new LogRecord(Level.WARNING, "Failed to save temporary offline state change");
          +                lr.setThrown(e);
          +                LOGGER.log(lr);
          +            }
          +
                   }
                   synchronized (statusChangeLock) {
                       statusChangeLock.notifyAll();
          
          

          Probably not the correct fix but it works for me. Please feel free to derive work from my diff. I am a long time user of Jenkins but NO Java programmer. Hope this helps.

          I have not had the opportunity to test this in the production environment yet. So I do not know if this works for 1.625.1.

          Asmund Ostvold added a comment - - edited I have found a solution that works for jenkins-1.635. diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index a3ddb20..e76dfdd 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -694,6 +694,14 @@ public /* transient */ abstract class Computer extends Actionable implements Acces Node node = getNode(); if (node != null ) { node.setTemporaryOfflineCause(offlineCause); + try { + node.save(); + } catch (IOException e) { + LogRecord lr = new LogRecord(Level.WARNING, "Failed to save temporary offline state change" ); + lr.setThrown(e); + LOGGER.log(lr); + } + } synchronized (statusChangeLock) { statusChangeLock.notifyAll(); Probably not the correct fix but it works for me. Please feel free to derive work from my diff. I am a long time user of Jenkins but NO Java programmer. Hope this helps. I have not had the opportunity to test this in the production environment yet. So I do not know if this works for 1.625.1.

          My testing was wrong this was fixed with https://issues.jenkins-ci.org/browse/JENKINS-31055

          Asmund Ostvold added a comment - My testing was wrong this was fixed with https://issues.jenkins-ci.org/browse/JENKINS-31055

            kohsuke Kohsuke Kawaguchi
            asmundo Asmund Ostvold
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: