Troubleshooting Play Framework 2 apps on Openshift

Troubleshooting Openshift
 

With the do-it-yourself application type you really get a lot of freedom to support almost any framework or server that can be built and run on a linux box. But you do have to make your homework, and do some research. 
So in this article I’ll show you a couple of tips I learnt playing around with Openshift and Play Framework
Comments are more than welcome, so I hope you can also provide me some more tips to help us all get our apps running on the cloud. 
Providing native support for play framework application
 
Right now, the solution we found for deploying Play 2.0 apps on openshift is quite handy, but we could make it a little better..
The problem is that we have to compile the app locally (issuing play stage) and then push 30 MB of libraries to Openshift. The ideal thing, and that’s what we did with the Play 1.x quickstart and with the latest version of Openshift module for Play Framework 1.x, would be to just upload our sources and then let Openshift download and install Play, compile our app, and start it. 
Unfortunately we’ve ran with some memory constraints (seems like compiling Play 2 apps is a bit memory demanding) that eventually raised some issues. We are trying to work them out, but perhaps, with this tips, you could help has troubleshoot it. 
With the opensourcing of Openshift and the new Origin livecd we have more tools available for us to further investigate what’s going on, I just didn’t have time yet to start playing with it. 
So, enought chatter, and let’s get our hands dirty. 
Houston, we have a problem
 
All right, you’ve just read this guide or followed our steps on the Play Framework webinar using this Play 2.0 quickstart (in fact, some of this tips will help trouble shoot any app running on Openshift) and something went wrong. 
First of all, have a look at the logs. Just issue
rhc app tail -a myapp -l mylogin@openshift.com -p mysecretpass
Leave that window open, it will become quite handy later. 
Then we’ll ssh into our remote machine. Just issue:
rhc app show -a myapp -l mylogin@openshift.com -p mysecretpass
and you’ll get something like
Application Info
================
contacts
    Framework: diy-0.1
     Creation: 2012-04-19T14:20:16-04:00
         UUID: 0b542570e41b42e5ac2a255c316871bc
      Git URL: ssh://0b542570e41b42e5ac2a255c316871bc@myapp-mylogin.rhcloud.com/~/git/myapp.git/
   Public URL: http://myapp-mylogin.rhcloud.com/

 Embedded: 
      None
Take the part after the ssh of the Git URL stuff, and log into you openshift machine:
ssh 96e487d1d4a042f8833efc696604f1e7@myapp-mylogin.rhcloud.com
(If you are lazy like me, go on and vote for an easier way to ssh into openshift
It’s also a good idea to open another command window, ssh into openshift, and run something like “top” or “watch -n 2 free -m” to keep an eye on memory usage. 
Troubleshooting Play
 
You know the old motto, “write once, run everywhere”… well it just “should” work, but just in case you could try compiling your app with the same JDK version as the one running on openshift. 
Just run
java -version
java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.6) (rhel-1.43.1.10.6.el6_2-i386)
OpenJDK Server VM (build 20.0-b11, mixed mode)
And install the same jdk version on your box. Then compile your app and redeploy (you can use the convenience script openshift_deploy
If that doesn’t work, try to do the whole process manually on Openshift. You should do something like this:
# download play
cd ${OPENSHIFT_DATA_DIR} 
curl -o play-2.0.1.zip http://download.playframework.org/releases/play-2.0.1.zip
unzip play-2.0.1.zip
cd ${OPENSHIFT_REPO_DIR}

#stop app
.openshift/action_hooks/stop

#clean everything - watch for errors, if it fails retry a couple more times
${OPENSHIFT_DATA_DIR}play-2.0.1/play clean 
if you get something like:
/var/lib/stickshift/0b542570e41b42e5ac2a255c316871bc/myapp/data/play-2.0.1/framework/build: line 11: 27439 Killed 
It means it failed miserably (that’s the memory problem I told you about) 
And it’s such a bad tempered error that you’ll also loose you command prompt. Just blindily type “reset” and hit enter, you’ll get your prompt back. 
And then just try again… 
You might also get this message:
This project uses Play 2.0!
Update the Play sbt-plugin version to 2.0.1 (usually in project/plugins.sbt)
That means you created the app with Play 2.0 and you are now trying to compile it with a different version. 
Just update project/plugins.sbt file or download the appropiate version. 
Now compile and stage your app.
#compile everything - watch for errors, if it fails retry a couple more times
${OPENSHIFT_DATA_DIR}play-2.0.1/play compile

#stage - watch for errors, if it fails retry a couple more times
${OPENSHIFT_DATA_DIR}play-2.0.1/play stage
Then run it (don’t be shy and have a look at the action hooks scripts on the quickstart repo).
target/start -Dhttp.port=8080 -Dhttp.address=${OPENSHIFT_INTERNAL_IP} -Dconfig.resource=openshift.conf
Go check it at https://myapp-mylogin.rhcloud.com 
If everything works ok, just stop it with ctrl-c, and then run:
.openshift/action_hooks/start
You should see your app starting in the console with the logs files 
Now you can log out from the ssh session with ctrl-d, and issue:
rhc app restart -a myapp -l mylogin@openshift.com -p mysecretpass
and you should see something like
Stopping play application
Trying to kill proccess, attempt number 1
kill -SIGTERM 19128
/var/lib/stickshift/0b542570e41b42e5ac2a255c316871bc/openbafici/repo/target/start "-DapplyEvolutions.default=true" -Dhttp.port=8080 -Dhttp.address=127.11.189.129 -Dconfig.resource=openshift.conf
Play server process ID is 21226
[info] play - Application started (Prod)
[info] play - Listening for HTTP on port 8080...
I hope this tips will become useful. As I told, I’m looking forward to start playing with the Openshift Origin livecd, and then I’ll tell you about. 
In the meantime I’ll leave you with the company of the good old Openshift Rocket Bear, I know you miss him too, so why not get him back?
Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

3 Responses to "Troubleshooting Play Framework 2 apps on Openshift"

  1. Thanks for sharing with this detailed post.

  2. TheSteve0 says:

    This is awesome – thanks so much for putting this out there.

  3. opensas says:

    You might also find this post interesting: http://playlatam.wordpress.com/2012/05/01/deploying-play-framework-2-apps-with-java-and-scala-to-openshift/

    it’s a screencast showing a step-by-step development of a play framework 2 app, with java AND scala, being deployed to Openshift

Leave a Reply


3 × = twenty seven



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books
Get tutored by the Geeks! JCG Academy is a fact... Join Now
Hello. Add your message here.