Deploying Multiple Grails Apps to Tomcat7

Lately I pushed my second grails app to my production tomcat server. The second app failed to startup. /var/lib/tomcat7/logs/catalina.out gave a long list of errors the first of which was…

 Database may be already in use: “Locked by another process”. Possible solutions: close all other connection(s); use the server mode [90020-173].

It turns out that the databases were named the same in the grails-app/conf/DataSource.groovy file.

The fix is to make the names of the production databases to be meaningful and thus different. For instance, change  the bold part to something different.

 

environment {
  production { 
    dataSource { 
    dbCreate = "update" 
    url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" 

Of course after this, you’ll need to redeploy (you’ll need to replace *.war with the specific version you want to deploy).

path/to/your/grails/project $ grails war
$ cp target/*.war /var/lib/tomcat7/webapps
path/to/OTHER/grails/project $ grails war
$ cp target/*.war /var/lib/tomcat7/webapps
$ sudo /etc/init.d/tomcat7 restart

Apache2 proxy for Tomcat7

 

Tomcat runs on port 8080 by default

You’ll put the following 2 lines in your /etc/apache2/sites-available/example.com file

ProxyPass /logger http://localhost:8080/logger
ProxyPassReverse /logger http://localhost:8080/logger

Make sure that the folder and the tomcat deployment are the same name or it won’t serve static content correctly.