diff --git a/core/src/main/java/hudson/WebAppMain.java b/core/src/main/java/hudson/WebAppMain.java index f2682e4b46..b17f01f1cf 100644 --- a/core/src/main/java/hudson/WebAppMain.java +++ b/core/src/main/java/hudson/WebAppMain.java @@ -8,6 +8,7 @@ import hudson.triggers.Trigger; import hudson.util.IncompatibleServletVersionDetected; import hudson.util.IncompatibleVMDetected; import hudson.util.RingBufferLogHandler; +import hudson.util.NoHomeDir; import javax.naming.Context; import javax.naming.InitialContext; @@ -40,11 +41,17 @@ public class WebAppMain implements ServletContextListener { public void contextInitialized(ServletContextEvent event) { installLogger(); + ServletContext context = event.getServletContext(); + File home = getHomeDir(event); home.mkdirs(); System.out.println("hudson home directory: "+home); - ServletContext context = event.getServletContext(); + // check that home exists (as mkdirs could have failed silently), otherwise throw a meaningful error + if (! home.exists()) { + context.setAttribute("app",new NoHomeDir(home)); + return; + } // make sure that we are using XStream in the "enhanced" (JVM-specific) mode if(new JVM().bestReflectionProvider().getClass()==PureJavaReflectionProvider.class) { diff --git a/core/src/main/java/hudson/util/NoHomeDir.java b/core/src/main/java/hudson/util/NoHomeDir.java new file mode 100644 index 0000000000..f851c35625 --- /dev/null +++ b/core/src/main/java/hudson/util/NoHomeDir.java @@ -0,0 +1,20 @@ +package hudson.util; + +import java.io.File; + +/** + * Model object used to display the error top page if + * we couldn't create the home directory. + * + *
+ * index.jelly would display a nice friendly error page.
+ *
+ * @author Kohsuke Kawaguchi
+ */
+public class NoHomeDir {
+ public final File home;
+
+ public NoHomeDir(File home) {
+ this.home = home;
+ }
+}
diff --git a/core/src/main/resources/hudson/util/NoHomeDir/index.jelly b/core/src/main/resources/hudson/util/NoHomeDir/index.jelly
new file mode 100644
index 0000000000..8320b91372
--- /dev/null
+++ b/core/src/main/resources/hudson/util/NoHomeDir/index.jelly
@@ -0,0 +1,16 @@
+
+ Unable to create the home directory '${it.home}'. This is most likely a permission problem.
+
+ To change the home directory, use HUDSON_HOME environment variable or set the
+ HUDSON_HOME system property. See
+ Container-specific documentation for more details of how to do this.
+
+ ![[!]](${rootURL}/images/48x48/error.gif)