29 Aug 2013

Restarting an AWS EC2 Instance

I find that I will shutdown EC2 instances that I don't need for some period of time. However, on restart, some of the settings are dynamically assigned, requiring additional steps to enable access.

On restart of the EC2 instance, a new public DNS and IP address.


Before you can connect to your re-started server with it's new name and IP address using ssh, you'll also need to know the public DNS name for your EC2 instance.
- Go to the EC2 console
- Click on the name associated with the app you just created
- Scroll down to the bottom of the page and you'll find the Public DNS field. It will be something like

Now that you know the name of your server, you can connect to it with ssh using that name and the key pair you downloaded earlier. I'm using the Linux ssh command but you could also use putty. Here's the Linux command to login:

ssh -i ~/myssh.pem


To install and start Tomcat, SSH into the server and enter the commands:

sudo yum install tomcat7 tomcat7-webapps mcat7-docs-webapp tomcat7-admin-webapps
sudo service tomcat7 start

You should now be able to browse to your Tomcat server at http://<public DNS>:8080. You're public DNS address can be found under the Instances tab.

Tomcat Administration

You'll find the Tomcat logs in the directory


To restart Tomcat:

sudo service tomcat7 restart
sudo chkconfig tomcat7 on

To access the Tomcat server from your web browser

http://<public DNS>:8080

To access your Grails app hosted on the server:

http://<public DNS>:8080/<appname>

Build & Re-Deploy Your Grails App

If you've been deploying to a local server, you may have to change your config.groovy settings:


and your datasource.groovy settings:

username = "root"
 password = "password"
 pooled = true
 dbCreate = "create-drop"
 driverClassName = "com.mysql.jdbc.Driver"
 url = "jdbc:mysql://"
 dialect = org.hibernate.dialect.MySQL5InnoDBDialect
 properties {
 validationQuery = "SELECT 1"
 testOnBorrow = true
 testOnReturn = true
 testWhileIdle = true
 timeBetweenEvictionRunsMillis = 1000 * 60 * 30
 numTestsPerEvictionRun = 3
 minEvictableIdleTimeMillis = 1000 * 60 * 30

With the Tomcat plugin installed, the following command will build and deploy the war file to your Tomcat server:

grails prod tomcat undeploy
grails prod tomcat deploy