lazygun - building cool stuff for the web
« Back to blog

Deploying a Grails app to RackSpace Cloud Servers

Judging from the number of blog articles on the subject, Amazon's EC2 seems to be a pretty popular way of deploying Grails applications. Certainly, the tooling support is good: CloudFoundry provides Cloud Tools, which includes an Amazon EC2 Grails plugin and an Amazon Machine Image (AMI) pre-configured for running Grails; the CloudFoundry service itself makes deployment a breeze; also, if you're a SpringSource Tool Suite user, you can deploy to EC2 from within the IDE.
Despite the good support for Amazon EC2 deployment, there are a few gotchas to complicate matters.  Because of the ephemeral nature of EC2 instances, you'll need to use an Elastic Block Storage (EBS) volume to park your database on.  Also, if you want a static IP address for your app, your need to configure an EC2 Elastic IP Address.  These add to the cost of the deployment, as well as the complexity.  Running just one of the smallest available instances with persistent storage 24/7 will cost you just over $60/month.
The easy deployment and horizontal scalability of Amazon EC2 make it a great platform for running you're application once you're in production with a large number of users.  However, if you're in the prototyping/early development stages, it's probably overkill. This was the case with a project I'm currently bootstrapping.  I was looking for a solution that was simpler and cheaper to use now, but also easy to scale up once the app goes public.
After a bit of research, I decided to take RackSpace's Cloud Server service for a spin.  At 3¢/hour (under $22/month) for a Linux server with 512MB RAM and a 30GB disk, and data transfer prices at 22¢/GB in, 8¢/GB out, the price was certainly right.  Incredibly, included in this price is 24/7 support by email, phone or live chat.
I found the setup to be quick and painless; my application was up and running on the server within the hour - this includes five minutes spent on the phone on a courtesy call from RackSpace's support team (which was a nice touch!).
I've reproduced the steps from signup to deployment below:

  1. Sign up for RackSpace Cloud
  2. Spin up a server instance.  You'll need at least 512Mb RAM for Grails.  I chose the Debian (Lenny) distro, as setup for this distro is very well documented on the RackSpace wiki.
  3. Prepare server:
    1. Lock down your server, following the instructions at http://cloudservers.rackspacecloud.com/index.php/Debian_Lenny_-_Setup
    2. Install the Java SDK: sudo aptitude install sun-java6-jdk
    3. Install MySQL: sudo aptitude install mysql-server mysql-client
    4. Install Grails:
    5. Create and run a test app to make sure everything is correctly set up.
  4. Save a snapshot of this server to rollback to in the event of a catastrophe.
  5. If you need to do some admin to prep your database, I found the best way was to use MySQL Administrator, running on my local machine and connecting to the remote MySQL server through an SSH tunnel.  Instructions for doing this from a Windows client using Putty are here: http://realprogrammers.com/how_to/set_up_an_ssh_tunnel_with_putty.html
  6. You have a number of options for deploying your app, the simplest probably being rsync over SSH.  You can do this from your Windows development machine using cwrsync (remember to install rsync on your application server too).  An alternative, if you use source control for your project, is to install the source control client on your application server, and export a copy of the project from your code repository.  I use Mercurial, so this is as simple as running hg archive <repo URL>, which I execute on the application server via a script on my development machine.
Using this setup, I am able to run my app using the Tomcat server embedded in Grails.  I found that 512MB RAM was enough for this, but depending on the size of your app you may need to go for a 1024MB server instance.  Having said that, upgrading your server is just a matter of a couple of clicks on the Cloud Server control panel, so you can start of with 512Mb without worrying about scaling up.

So far, my experience with RackSpace Cloud Server has been great.  The price and simplicity are refreshing after working with EC2 instances.  However, as good as the service currently is, there is one significant limitation worth mentioning:  Although you can create any number of backup snapshots of your server instance, these will disappear with your server when you un-provision it.  As yet, it is not possible to create a persistent snapshot that may be copied to multiple instances, a la Amazon EC2 AMIs.  This means that if you want to take advantage of the hourly pricing and un-provision your server when not in use, you'll need to go through the set-up process from scratch when you spin-up a new instance.  It is possible to script the set-up process, however note that the Sun Java JDK install is interactive; this means that, even making use of the RackSpace Cloud Server API, a fully automated provisioning/un-provisioning of server instances is not trivial.  RackSpace say they are working on this; they hope to allow server snapshots to persist independently of the server instance in the near future.  On the other hand, with the service being so cheap, leaving the server running 24/7 is not a bad option.

One final point worth noting is that currently all Cloud Servers are based in the US, although RackSpace are planning to offer UK-based Cloud Servers "in the first half of 2010".  This means greater latency for European users, as well as European legislation issues around the export of personal data.

Apr 19, 2010
chanpory said...
Total newbie here. How did you set the environment variables in /etc/profile in step 3.4.2?
Apr 20, 2010
Ewan Dawson said...
@chanpory For general info on setting env vars in Linux, check out http://bit.ly/doegic. If you want a copy of my /etc/profile, let me know.
May 04, 2010
chanpory said...
Thanks, I got it to work! Yay :-)
Jul 01, 2010
Matthew Wallace said...
I am totally doing this ... I spent 2-3 weekends trying to get my app running on google appengine and there was always some limiting factor that would keep it from working.

This seems like a great solution. Thanks for the post.

Jul 02, 2010
Ewan Dawson said...
Hi Matthew, thanks for the comment and the subscribe. Glad you found the post useful. I can't recommend Rackspace cloud highly enough: their help docs are fantastic, and for any more obscure issues, the free phone support is simply superb.
Jul 03, 2010
Matthew Wallace said...
Ewan .... I took your set-up a bit further and installed tomcat 5.5 on the server so that I could deploy war files from my grails apps. Wondering if you have had any experience with this failing ?

Check out my issue here if you have time and let me know what you think. http://bit.ly/grails-tomcat-help

Jul 03, 2010
Ewan Dawson said...
Matthew, is there a reason you need to use a standalone instance of Tomcat, rather than simply running your app with the embedded instance (grails prod run-war)? This method works fine for me, and helps keep resource usage down.
Jul 03, 2010
Matthew Wallace said...
well main reason was I didn't want to have grails on the server at all. I develop local anyway and figured that was just one less thing I would have to worry about and configure ... bla bla bla