Java Play 2 - Deployment
Asked Answered
D

4

0

Updated 08.18.2012

I am using Play 2.0.2 and I want to deploy my app to Amazon Webservices. I think the easiest way to do this is via Elasticbeanstalk.

I used Play2war to package my app https://github.com/dlecan/play2-war-plugin/

I was able to package it with

play war

According to the usage guide of play2war, I renamed my file to ROOT.war because i used Linux 32bit Tomcat7.

I also used the servlet 3.0 as described in the tutorial on play2war. (tomcat 7 -> servlet 3.0).

The file size is 31mb.

Every time I use Elasticbeanstalk, I get the same log.

2012-08-18 00:25 GMT+0200
WARN
Environment health has been set to RED
2012-08-18 00:25 GMT+0200
INFO
Launched environment: elosource. However, there were issues during launch. See event log for details.
2012-08-18 00:25 GMT+0200
INFO
Your health check URL may be misconfigured. If your application does not respond to requests at http://elosource.elasticbeanstalk.com:80/, modify the health check URL to a valid path.

I tested it with Linux 32/64 bit , Tomcat7(servlet 3) and Tomcat6(servlet2.5). I always get the same result.

I also tried adding an extra html file for the health checker.

  • What would you recommend me to do?

  • What alternatives do I have to get my app running on ec2?

  • Is there a guide that explains how I manually deploy my app to ec2 with all the needed dependcies, like mongodb, play etc?

  • Also WAR files are relatively huge ~30mb, with my dsl 1k it is a real pain to upload such a lage file. Is there a way to only upload the changes with Elasticbeanstalk?

Deteriorate answered 12/8, 2012 at 0:32 Comment(2)
I don't undrstand there's no any error in your log, do why do you cało it error log ?Twelvemo
Sorry I was really tired yesterday. It should have been "Always the same error in the log"Deteriorate
T
5

Ok, I know this is not the straight answer to your question as I am not using beanstalk, but as you asked for it in one of the comments:

Here is how I run my play2 app on a linux EC2 instance with a jvm installed:

  1. on your local machine, in your project directory, run play dist
  2. send the dist/yourapp-1.0-SNAPSHOT.zip file (or whatever dist name you have configured) to the EC2 instance
  3. ssh to your instance
  4. unzip the dist file in the directory you want and cd there
  5. run chmod +x start
  6. run nohup ./start &

you now have your play2 application running natively on EC2, with websocket and all the cool stuff. I didn't have to configure anything special in play for that to work. I am using an RDS database configured as any other DB in play.

Clearly, it's a bit more hassle than beanstalk as you have to configure the server on your own and set up the autoscaling manually. But this is the best way that I have found to run play2 with all the features on AWS for now.

I hope this helps.

Thyrsus answered 21/8, 2012 at 20:15 Comment(5)
Thanks this is what I am looking for. One question, I am using MongoDB do I have to manually install the dependencies on my linux instance or does play do everything for me?Deteriorate
I have to say that I haven't used MongoDB, so I can't be sure. Play should take care of getting the right libraries to compile and run, but you will have to have a mongoDB server running somewhere. If you plan to run this on EC2 too, then you will have to launch the server manually too (from what I understand, you can't run a mongoDB server on beanstalk anyway). However, you can get a hosted mongoDB server (e.g. mongolab), or you could just use amazon's own RDS, SimpleDB or Dynamo instead.Thyrsus
Also, I just found this: eugenedvorkin.com/… It's clearly about play1 and the deploy of play2 might be different than for play1, but it might help you.Thyrsus
and, MongoDB has a page focused on installing on EC2: mongodb.org/display/DOCS/Amazon+EC2Thyrsus
activator universal:packageZipTarball removes step 5Toughminded
R
3

You should not package your application as a war, unless you are obligated to do or have a very good reason, as you will loose great features of the framework (even with servlet 3.0 you will miss websocket support).

An option is to deploy your app through dotCloud service. The service runs on top of Amazon EC2 and enables you to choose your stack and scale vertically easily. Of course you have to decide if it is worth the price, but you could test for free.

There as well other PaaS providers, that let you deploy play 2 applications:

Redintegration answered 18/8, 2012 at 9:58 Comment(1)
Yes thanks, atm I am using heroku, but i have one question, will servlet 3.1 fix ALL problems? Or will a native play2 client always be better? I would like to see something how to deploy a native play2 app to ec2. Could you recommend me some resources?Deteriorate
O
2

INFO: The APR based Apache Tomcat Native... is not the important part. Tomcat will start without it, and compiling it won't make your instance healthy. In fact, your catalina.out logging looks totally normal.

My guess would be Beanstalk's error messages are accurate: You've got a misconfigured health check URL. For whatever reason, you application just isn't returning a root document on port 80, a problem that could arise in a few ways. Try adding a static html or simple jsp page to your app's root directory (top-level in the WAR), and have Beanstalk check for that. Beanstalk's default port configuration should work (if I recall correctly it passes traffic via apache to tomcat and back, but I haven't looked in a while), but it couldn't hurt to check $CATALINA_HOME/conf/server.xml anyway just to see what's up.

Obel answered 12/8, 2012 at 3:54 Comment(2)
Thanks I will look into it. But I am still very new to webserver so it will take some time until I response again.Deteriorate
Just try an HTML page that says nothing more than "ok". That will at least isolate it to the health check or Tomcat.Obel
D
1

If you are willing to upgrade to Play 2.3.x or newer, Boxfuse has native Play 2 support to address this.

You can now simply do boxfuse run my-play-app-1.0.zip -env=prod and this will automatically:

  • create a minimal AMI tailor-made for your Play 2 app
  • create an elastic IP
  • create a security group with the correct permissions
  • launch an instance of your app

All future updates are performed as blue/green deployments with zero downtime.

This also works with Elastic Load Balancers and Auto-Scaling Groups and the Boxfuse free tier is designed to fit the AWS free tier.

You can read more about it here: https://boxfuse.com/blog/playframework-aws

Disclaimer: I'm the founder and CEO of Boxfuse

Dermoid answered 10/12, 2015 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.