(refs #204)Add some way to configure data directory.

1) system property of JVM (e.g. -Dgitbucket.home=PATH_TO_DATADIR)
2) java -jar gitbucket.war --data=PATH_TO_DATADIR
3) Add context parameter "gitbucket.home" to web.xml
This commit is contained in:
takezoe
2013-11-30 05:18:15 +09:00
parent bbff75e037
commit b3669f6d66
4 changed files with 27 additions and 27 deletions

View File

@@ -27,6 +27,8 @@ public class JettyLauncher {
contextPath = dim[1]; contextPath = dim[1];
} else if(dim[0].equals("--https") && (dim[1].equals("1") || dim[1].equals("true"))) { } else if(dim[0].equals("--https") && (dim[1].equals("1") || dim[1].equals("true"))) {
forceHttps = true; forceHttps = true;
} else if(dim[0].equals("--data")){
System.setProperty("gitbucket.home", dim[1]);
} }
} }
} }

View File

@@ -87,7 +87,7 @@ object AutoUpdate {
/** /**
* The version file (GITBUCKET_HOME/version). * The version file (GITBUCKET_HOME/version).
*/ */
val versionFile = new File(GitBucketHome, "version") lazy val versionFile = new File(GitBucketHome, "version")
/** /**
* Returns the current version from the version file. * Returns the current version from the version file.
@@ -115,6 +115,10 @@ class AutoUpdateListener extends ServletContextListener {
private val logger = LoggerFactory.getLogger(classOf[AutoUpdateListener]) private val logger = LoggerFactory.getLogger(classOf[AutoUpdateListener])
override def contextInitialized(event: ServletContextEvent): Unit = { override def contextInitialized(event: ServletContextEvent): Unit = {
val datadir = event.getServletContext.getInitParameter("gitbucket.home")
if(datadir != null){
System.setProperty("gitbucket.home", datadir)
}
org.h2.Driver.load() org.h2.Driver.load()
event.getServletContext.setInitParameter("db.url", s"jdbc:h2:${DatabaseHome}") event.getServletContext.setInitParameter("db.url", s"jdbc:h2:${DatabaseHome}")

View File

@@ -8,9 +8,15 @@ import util.ControlUtil._
*/ */
object Directory { object Directory {
val GitBucketHome = (scala.util.Properties.envOrNone("GITBUCKET_HOME") match { val GitBucketHome = (System.getProperty("gitbucket.home") match {
case Some(env) => new File(env) // -Dgitbucket.home=<path>
case None => new File(System.getProperty("user.home"), "gitbucket") case path if(path != null) => new File(path)
case _ => scala.util.Properties.envOrNone("GITBUCKET_HOME") match {
// environment variable GITBUCKET_HOME
case Some(env) => new File(env)
// default is HOME/gitbucket
case None => new File(System.getProperty("user.home"), "gitbucket")
}
}).getAbsolutePath }).getAbsolutePath
val GitBucketConf = new File(GitBucketHome, "gitbucket.conf") val GitBucketConf = new File(GitBucketHome, "gitbucket.conf")

View File

@@ -27,28 +27,6 @@
<servlet-name>GitRepositoryServlet</servlet-name> <servlet-name>GitRepositoryServlet</servlet-name>
<url-pattern>/git/*</url-pattern> <url-pattern>/git/*</url-pattern>
</servlet-mapping> </servlet-mapping>
<!--
<filter>
<filter-name>TransactionFilter</filter-name>
<filter-class>servlet.TransactionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>TransactionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
<!--
<filter>
<filter-name>BasicAuthenticationFilter</filter-name>
<filter-class>servlet.BasicAuthenticationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>BasicAuthenticationFilter</filter-name>
<url-pattern>/git/*</url-pattern>
</filter-mapping>
-->
<!-- ===================================================================== --> <!-- ===================================================================== -->
<!-- H2 database configuration --> <!-- H2 database configuration -->
@@ -56,7 +34,7 @@
<listener> <listener>
<listener-class>servlet.AutoUpdateListener</listener-class> <listener-class>servlet.AutoUpdateListener</listener-class>
</listener> </listener>
<context-param> <context-param>
<param-name>db.user</param-name> <param-name>db.user</param-name>
<param-value>sa</param-value> <param-value>sa</param-value>
@@ -103,4 +81,14 @@
<session-timeout>1440</session-timeout> <session-timeout>1440</session-timeout>
</session-config> </session-config>
<!-- ===================================================================== -->
<!-- Optional configurations -->
<!-- ===================================================================== -->
<!--
<context-param>
<param-name>gitbucket.home</param-name>
<param-value>PATH_TO_DATADIR</param-value>
</context-param>
-->
</web-app> </web-app>