提交 4f857bcc 编写于 作者: J Jerome Lacoste

JENKINS-8658 let getHomeDir gather information about where it finds its...

JENKINS-8658 let getHomeDir gather information about where it finds its location. Useful for troubleshooting.
上级 8e432f8f
...@@ -113,9 +113,10 @@ public final class WebAppMain implements ServletContextListener { ...@@ -113,9 +113,10 @@ public final class WebAppMain implements ServletContextListener {
installLogger(); installLogger();
final File home = getHomeDir(event).getAbsoluteFile(); final FileAndDescription describedHomeDir = getHomeDir(event);
final File home = describedHomeDir.file.getAbsoluteFile();
home.mkdirs(); home.mkdirs();
System.out.println("hudson home directory: "+home); System.out.println("hudson home directory: "+home+" found at: "+describedHomeDir.description);
// check that home exists (as mkdirs could have failed silently), otherwise throw a meaningful error // check that home exists (as mkdirs could have failed silently), otherwise throw a meaningful error
if (! home.exists()) { if (! home.exists()) {
...@@ -260,6 +261,16 @@ public final class WebAppMain implements ServletContextListener { ...@@ -260,6 +261,16 @@ public final class WebAppMain implements ServletContextListener {
Logger.getLogger("hudson").addHandler(handler); Logger.getLogger("hudson").addHandler(handler);
} }
/** Add some metadata to a File, allowing to trace setup issues */
private class FileAndDescription {
File file;
String description;
public FileAndDescription(File file,String description) {
this.file = file;
this.description = description;
}
}
/** /**
* Determines the home directory for Jenkins. * Determines the home directory for Jenkins.
* *
...@@ -269,8 +280,11 @@ public final class WebAppMain implements ServletContextListener { ...@@ -269,8 +280,11 @@ public final class WebAppMain implements ServletContextListener {
* <p> * <p>
* People makes configuration mistakes, so we are trying to be nice * People makes configuration mistakes, so we are trying to be nice
* with those by doing {@link String#trim()}. * with those by doing {@link String#trim()}.
*
* <p>
* @return the File alongside with some description to help the user troubleshoot issues
*/ */
private File getHomeDir(ServletContextEvent event) { private FileAndDescription getHomeDir(ServletContextEvent event) {
// check JNDI for the home directory first // check JNDI for the home directory first
for (String name : HOME_NAMES) { for (String name : HOME_NAMES) {
try { try {
...@@ -278,11 +292,11 @@ public final class WebAppMain implements ServletContextListener { ...@@ -278,11 +292,11 @@ public final class WebAppMain implements ServletContextListener {
Context env = (Context) iniCtxt.lookup("java:comp/env"); Context env = (Context) iniCtxt.lookup("java:comp/env");
String value = (String) env.lookup(name); String value = (String) env.lookup(name);
if(value!=null && value.trim().length()>0) if(value!=null && value.trim().length()>0)
return new File(value.trim()); return new FileAndDescription(new File(value.trim()),"JNDI/java:comp/env/"+name);
// look at one more place. See issue #1314 // look at one more place. See issue #1314
value = (String) iniCtxt.lookup(name); value = (String) iniCtxt.lookup(name);
if(value!=null && value.trim().length()>0) if(value!=null && value.trim().length()>0)
return new File(value.trim()); return new FileAndDescription(new File(value.trim()),"JNDI/"+name);
} catch (NamingException e) { } catch (NamingException e) {
// ignore // ignore
} }
...@@ -292,14 +306,14 @@ public final class WebAppMain implements ServletContextListener { ...@@ -292,14 +306,14 @@ public final class WebAppMain implements ServletContextListener {
for (String name : HOME_NAMES) { for (String name : HOME_NAMES) {
String sysProp = System.getProperty(name); String sysProp = System.getProperty(name);
if(sysProp!=null) if(sysProp!=null)
return new File(sysProp.trim()); return new FileAndDescription(new File(sysProp.trim()),"System.getProperty(\""+name+"\")");
} }
// look at the env var next // look at the env var next
for (String name : HOME_NAMES) { for (String name : HOME_NAMES) {
String env = EnvVars.masterEnvVars.get(name); String env = EnvVars.masterEnvVars.get(name);
if(env!=null) if(env!=null)
return new File(env.trim()).getAbsoluteFile(); return new FileAndDescription(new File(env.trim()).getAbsoluteFile(),"EnvVars.masterEnvVars.get(\""+name+"\")");
} }
// otherwise pick a place by ourselves // otherwise pick a place by ourselves
...@@ -311,14 +325,16 @@ public final class WebAppMain implements ServletContextListener { ...@@ -311,14 +325,16 @@ public final class WebAppMain implements ServletContextListener {
// Hudson <1.42 used to prefer this before ~/.hudson, so // Hudson <1.42 used to prefer this before ~/.hudson, so
// check the existence and if it's there, use it. // check the existence and if it's there, use it.
// otherwise if this is a new installation, prefer ~/.hudson // otherwise if this is a new installation, prefer ~/.hudson
return ws; return new FileAndDescription(ws,"getServletContext().getRealPath(\"/WEB-INF/workspace\")");
} }
File legacyHome = new File(new File(System.getProperty("user.home")), ".hudson"); File legacyHome = new File(new File(System.getProperty("user.home")),".hudson");
if (legacyHome.exists()) if (legacyHome.exists()) {
return legacyHome; // before rename, this is where it was stored return new FileAndDescription(legacyHome,"$user.home/.hudson"); // before rename, this is where it was stored
}
return new File(new File(System.getProperty("user.home")), ".jenkins"); File newHome = new File(new File(System.getProperty("user.home")),".jenkins");
return new FileAndDescription(newHome,"$user.home/.jenkins");
} }
public void contextDestroyed(ServletContextEvent event) { public void contextDestroyed(ServletContextEvent event) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册