Replace attribute by marker file for Jenkins startup
Goal is to be especially more compatible with tools like JCasC that will
rewrite the config.xml and hence likely remove the freshStartup attribute.
So we store this information as a separate marker file at the end of the
Jenkins startup process to avoid losing it.
@@ -444,7 +444,17 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
private transient volatile boolean terminating;
@GuardedBy("Jenkins.class")
private transient boolean cleanUpStarted;
- private boolean freshStartUp = true;
+
+ /**
+ * Use this to know during startup if this is a fresh one, aka first-time, startup, or a later one.
+ * A file will be created at the very end of the Jenkins initialization process.
+ * I.e. if the file is present, that means this is *NOT* a fresh startup.
+ *
+ * <code>
+ * STARTUP_MARKER_FILE.get(); // returns false if we are on a fresh startup. True for next startups.
+ * </code>
+ */
+ private transient static FileBoolean STARTUP_MARKER_FILE;
private volatile List<JDK> jdks = new ArrayList<JDK>();
@@ -839,7 +849,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
oldJenkinsJVM = JenkinsJVM.isJenkinsJVM(); // capture to restore in cleanUp()
JenkinsJVMAccess._setJenkinsJVM(true); // set it for unit tests as they will not have gone through WebAppMain
long start = System.currentTimeMillis();
-
+ STARTUP_MARKER_FILE = new FileBoolean(new File(root, ".lastStarted"));
// As Jenkins is starting, grant this process full control
ACL.impersonate(ACL.SYSTEM);
try {
@@ -985,6 +995,8 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
if (LOG_STARTUP_PERFORMANCE)
LOGGER.info(String.format("Took %dms for complete Jenkins startup",
System.currentTimeMillis()-start));
+
+ STARTUP_MARKER_FILE.on();
} finally {
SecurityContextHolder.clearContext();
}
@@ -3022,10 +3034,11 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
private void setBuildsAndWorkspacesDir() throws IOException, InvalidBuildsDir {
boolean mustSave = false;
String newBuildsDir = SystemProperties.getString(BUILDS_DIR_PROP);
+ boolean freshStartup = STARTUP_MARKER_FILE.isOff();
if (newBuildsDir != null && !buildsDir.equals(newBuildsDir)) {
checkRawBuildsDir(newBuildsDir);
- Level level = freshStartUp ? Level.INFO : Level.WARNING;
+ Level level = freshStartup ? Level.INFO : Level.WARNING;
LOGGER.log(level, "Changing builds directories from {0} to {1}. Beware that no automated data migration will occur.",
new String[]{buildsDir, newBuildsDir});
buildsDir = newBuildsDir;
@@ -3036,7 +3049,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
String newWorkspacesDir = SystemProperties.getString(WORKSPACES_DIR_PROP);
if (newWorkspacesDir != null && !workspaceDir.equals(newWorkspacesDir)) {
- Level level = freshStartUp ? Level.INFO : Level.WARNING;
+ Level level = freshStartup ? Level.INFO : Level.WARNING;
LOGGER.log(level, "Changing workspaces directories from {0} to {1}. Beware that no automated data migration will occur.",
new String[]{workspaceDir, newWorkspacesDir});
workspaceDir = newWorkspacesDir;
@@ -3045,8 +3058,6 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
LOGGER.log(Level.INFO, "Using non default workspaces directories: {0}.", workspaceDir);
}
- freshStartUp = false;
-
if (mustSave) {
save();
}
