Enterprise Java
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?
Reference: Troubleshooting Play Framework 2 apps on Openshift from our JCG partner Sebastian Scarano at the Having fun with Play framework! blog.





Thanks for sharing with this detailed post.
This is awesome – thanks so much for putting this out there.
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