Deploying from grails to tomcat
I’ve set up my grails build on Hudson, and now I want to deploy to my Tomcat server. Every time my tests complete, I want a new deploy. And I want to be completely automatic too.
First step is to navigate to your grails app and try:
grails install-plugin tomcat
It’s probably already installed, as it’s the default for grails these days.
Then we need to install Tomcat if you don’t have it already.
First, make sure it’s the Sun JDK, argh, I mean Oracle, but the Ubuntu packages still say Sun. The OpenJDK doesn’t really work well with grails and tomcat.
sudo aptitude install sun-java6-jdk
Then install tomcat:
sudo aptitude install tomcat6
Then edit the tomcat user file to enable some users:
sudo nano /etc/tomcat6/tomcat-users.xml
I suggest you have the following lines active, but please change the passwords:
<role rolename=”manager”/>
<user username=”manager” password=”manager” roles=”standard,manager”/>
<user username=”grails” password=”grails” roles=”standard,manager”/>
Restart tomcat to activate the changes.
sudo /etc/init.d/tomcat6 restart
Test by going to:
http://<hostname>:8080/manager
You should now specify the username/password and url for the to) in your grails project. Open the grails-app/conf/Config.groovy file and add this at the bottom of the file:
tomcat.deploy.username=”grails”
tomcat.deploy.password=”grails”
tomcat.deploy.url=”http://<hostname>:8080/manager”
That should set up easy deployment directly from grails. We’ll simply be using grails’ own plugin for deployment, so we’ll have no real need to understand how ant or tomcat handles it. It’s all nicely camouflaged by grails.
The deployment sequence is like this: First you need to undeploy the app from tomcat (not needed the first time)
grails tomcat undeploy
And then deploy the app
grails tomcat deploy
You should now be able to use your app on your testserver.
To add them to your Hudson project just add those two lines as a post-build shell script (or batch command if you’re on windows) and you’re good to go.
If undeployment fails, there may be some file locks. I experienced that on windows, but not on the Ubuntu 10.10 server. If (and only if) you have this problem, you can edit the
sudo nano /etc/tomcat6/context.xml
And change the <context> line to:
<Context antiJARLocking=”true” antiResourceLocking=”true” >
That fixed the issue for me.
PS: To control tomcat use these commands:
sudo /etc/init.d/tomcat6 stop
sudo /etc/init.d/tomcat6 start
sudo /etc/init.d/tomcat6 restart