mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-13 20:12:14 +00:00
Honor $JENKINS_HOME.
Honor $JENKINS_HOME (just like we used to do $HUDSON_HOME) We still fall back to $HUDSON_HOME every step of the way for maximum backward compatibility. I wasn't initially planning to do this for the first version, but working on native packages made me think we should deliver this.
This commit is contained in:
1 parent
62100264ac
commit
8ea876faa4
13 files changed
+65
-48
No files matched your search
@@ -64,7 +64,7 @@ public class Main {
|
||||
public static int run(String[] args) throws Exception {
|
||||
String home = getHudsonHome();
|
||||
if (home==null) {
|
||||
System.err.println("HUDSON_HOME is not set.");
|
||||
System.err.println("JENKINS_HOME is not set.");
|
||||
return -1;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
@@ -76,7 +76,9 @@ public class Main {
|
||||
}
|
||||
|
||||
private static String getHudsonHome() {
|
||||
return EnvVars.masterEnvVars.get("HUDSON_HOME");
|
||||
String home = EnvVars.masterEnvVars.get("JENKINS_HOME");
|
||||
if (home!=null) return home;
|
||||
return EnvVars.masterEnvVars.get("JENKINS_HOME");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -261,36 +261,46 @@ public final class WebAppMain implements ServletContextListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the home directory for Hudson.
|
||||
* Determines the home directory for Jenkins.
|
||||
*
|
||||
* <p>
|
||||
* We look for a setting that affects the smallest scope first, then bigger ones later.
|
||||
*
|
||||
* <p>
|
||||
* People makes configuration mistakes, so we are trying to be nice
|
||||
* with those by doing {@link String#trim()}.
|
||||
*/
|
||||
private File getHomeDir(ServletContextEvent event) {
|
||||
// check JNDI for the home directory first
|
||||
try {
|
||||
InitialContext iniCtxt = new InitialContext();
|
||||
Context env = (Context) iniCtxt.lookup("java:comp/env");
|
||||
String value = (String) env.lookup("HUDSON_HOME");
|
||||
if(value!=null && value.trim().length()>0)
|
||||
return new File(value.trim());
|
||||
// look at one more place. See issue #1314
|
||||
value = (String) iniCtxt.lookup("HUDSON_HOME");
|
||||
if(value!=null && value.trim().length()>0)
|
||||
return new File(value.trim());
|
||||
} catch (NamingException e) {
|
||||
// ignore
|
||||
for (String name : HOME_NAMES) {
|
||||
try {
|
||||
InitialContext iniCtxt = new InitialContext();
|
||||
Context env = (Context) iniCtxt.lookup("java:comp/env");
|
||||
String value = (String) env.lookup(name);
|
||||
if(value!=null && value.trim().length()>0)
|
||||
return new File(value.trim());
|
||||
// look at one more place. See issue #1314
|
||||
value = (String) iniCtxt.lookup(name);
|
||||
if(value!=null && value.trim().length()>0)
|
||||
return new File(value.trim());
|
||||
} catch (NamingException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// next the system property
|
||||
for (String name : HOME_NAMES) {
|
||||
String sysProp = System.getProperty(name);
|
||||
if(sysProp!=null)
|
||||
return new File(sysProp.trim());
|
||||
}
|
||||
|
||||
// finally check the system property
|
||||
String sysProp = System.getProperty("HUDSON_HOME");
|
||||
if(sysProp!=null)
|
||||
return new File(sysProp.trim());
|
||||
|
||||
// look at the env var next
|
||||
String env = EnvVars.masterEnvVars.get("HUDSON_HOME");
|
||||
if(env!=null)
|
||||
return new File(env.trim()).getAbsoluteFile();
|
||||
for (String name : HOME_NAMES) {
|
||||
String env = EnvVars.masterEnvVars.get(name);
|
||||
if(env!=null)
|
||||
return new File(env.trim()).getAbsoluteFile();
|
||||
}
|
||||
|
||||
// otherwise pick a place by ourselves
|
||||
|
||||
@@ -304,8 +314,11 @@ public final class WebAppMain implements ServletContextListener {
|
||||
return ws;
|
||||
}
|
||||
|
||||
// if for some reason we can't put it within the webapp, use home directory.
|
||||
return new File(new File(System.getProperty("user.home")),".hudson");
|
||||
File legacyHome = new File(new File(System.getProperty("user.home")), ".hudson");
|
||||
if (legacyHome.exists())
|
||||
return legacyHome; // before rename, this is where it was stored
|
||||
|
||||
return new File(new File(System.getProperty("user.home")), ".jenkins");
|
||||
}
|
||||
|
||||
public void contextDestroyed(ServletContextEvent event) {
|
||||
@@ -320,4 +333,6 @@ public final class WebAppMain implements ServletContextListener {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(WebAppMain.class.getName());
|
||||
|
||||
|
||||
private static final String[] HOME_NAMES = {"JENKINS_HOME","HUDSON_HOME"};
|
||||
}
|
||||
@@ -31,7 +31,7 @@ import org.jvnet.animal_sniffer.IgnoreJRERequirement;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Periodically checks the disk usage of <tt>HUDSON_HOME</tt>,
|
||||
* Periodically checks the disk usage of <tt>JENKINS_HOME</tt>,
|
||||
* and activate {@link HudsonHomeDiskUsageMonitor} if necessary.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
@@ -49,12 +49,12 @@ public class HudsonHomeDiskUsageChecker extends PeriodicWork {
|
||||
long total = Hudson.getInstance().getRootDir().getTotalSpace();
|
||||
if(free<=0 || total<=0) {
|
||||
// information unavailable. pointless to try.
|
||||
LOGGER.info("HUDSON_HOME disk usage information isn't available. aborting to monitor");
|
||||
LOGGER.info("JENKINS_HOME disk usage information isn't available. aborting to monitor");
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.fine("Monitoring disk usage of HUDSON_HOME. total="+total+" free="+free);
|
||||
LOGGER.fine("Monitoring disk usage of JENKINS_HOME. total="+total+" free="+free);
|
||||
|
||||
|
||||
// if it's more than 90% full and less than the minimum, activate
|
||||
@@ -63,7 +63,7 @@ public class HudsonHomeDiskUsageChecker extends PeriodicWork {
|
||||
HudsonHomeDiskUsageMonitor.get().activated = (total/free>10 && free< FREE_SPACE_THRESHOLD);
|
||||
} catch (LinkageError _) {
|
||||
// pre Mustang
|
||||
LOGGER.info("Not on JDK6. Cannot monitor HUDSON_HOME disk usage");
|
||||
LOGGER.info("Not on JDK6. Cannot monitor JENKINS_HOME disk usage");
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Monitors the disk usage of <tt>HUDSON_HOME</tt>, and if it's almost filled up, warn the user.
|
||||
* Monitors the disk usage of <tt>JENKINS_HOME</tt>, and if it's almost filled up, warn the user.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
@@ -90,13 +90,13 @@ public final class HudsonHomeDiskUsageMonitor extends AdministrativeMonitor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension point for suggesting solutions for full HUDSON_HOME.
|
||||
* Extension point for suggesting solutions for full JENKINS_HOME.
|
||||
*
|
||||
* <h3>Views</h3>
|
||||
* <dl>
|
||||
* <dt>message.jelly</dt>
|
||||
* <dd>
|
||||
* This view is rendered inside an LI tag as a possible solution to the full HUDSON_HOME problem.
|
||||
* This view is rendered inside an LI tag as a possible solution to the full JENKINS_HOME problem.
|
||||
* </dd>
|
||||
* </dl>
|
||||
*/
|
||||
|
||||
@@ -32,7 +32,7 @@ public class InitStrategy {
|
||||
* Returns the list of *.hpi and *.hpl to expand and load.
|
||||
*
|
||||
* <p>
|
||||
* Normally we look at {@code $HUDSON_HOME/plugins/*.hpi} and *.hpl.
|
||||
* Normally we look at {@code $JENKINS_HOME/plugins/*.hpi} and *.hpl.
|
||||
*
|
||||
* @return
|
||||
* never null but can be empty. The list can contain different versions of the same plugin,
|
||||
|
||||
@@ -2363,7 +2363,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
|
||||
pluginManager.stop();
|
||||
|
||||
if(getRootDir().exists())
|
||||
// if we are aborting because we failed to create HUDSON_HOME,
|
||||
// if we are aborting because we failed to create JENKINS_HOME,
|
||||
// don't try to save. Issue #536
|
||||
getQueue().save();
|
||||
|
||||
@@ -2917,7 +2917,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds /userContent/... to $HUDSON_HOME/userContent.
|
||||
* Binds /userContent/... to $JENKINS_HOME/userContent.
|
||||
*/
|
||||
public DirectoryBrowserSupport doUserContent() {
|
||||
return new DirectoryBrowserSupport(this,getRootPath().child("userContent"),"User content","folder.gif",true);
|
||||
|
||||
@@ -1771,8 +1771,8 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
|
||||
env.put("JOB_URL", rootUrl+getParent().getUrl());
|
||||
}
|
||||
|
||||
if(!env.containsKey("HUDSON_HOME"))
|
||||
env.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath() );
|
||||
env.put("JENKINS_HOME", Hudson.getInstance().getRootDir().getPath() );
|
||||
env.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath() ); // legacy compatibility
|
||||
|
||||
Thread t = Thread.currentThread();
|
||||
if (t instanceof Executor) {
|
||||
|
||||
@@ -62,14 +62,14 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Encourages the user to migrate HUDSON_HOME on a ZFS file system.
|
||||
* Encourages the user to migrate JENKINS_HOME on a ZFS file system.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @since 1.283
|
||||
*/
|
||||
public class ZFSInstaller extends AdministrativeMonitor implements Serializable {
|
||||
/**
|
||||
* True if $HUDSON_HOME is a ZFS file system by itself.
|
||||
* True if $JENKINS_HOME is a ZFS file system by itself.
|
||||
*/
|
||||
private final boolean active = shouldBeActive();
|
||||
|
||||
@@ -302,7 +302,7 @@ public class ZFSInstaller extends AdministrativeMonitor implements Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates $HUDSON_HOME to a new ZFS file system.
|
||||
* Migrates $JENKINS_HOME to a new ZFS file system.
|
||||
*
|
||||
* TODO: do this in a separate JVM to elevate the privilege.
|
||||
*
|
||||
|
||||
@@ -42,7 +42,7 @@ import java.lang.management.ManagementFactory;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Makes sure that no other Hudson uses our <tt>HUDSON_HOME</tt> directory,
|
||||
* Makes sure that no other Hudson uses our <tt>JENKINS_HOME</tt> directory,
|
||||
* to forestall the problem of running multiple instances of Hudson that point to the same data directory.
|
||||
*
|
||||
* <p>
|
||||
|
||||
Reference in new issue
Block a user