Monday, November 26, 2012

Creating Tomcat application on OpenShift - Take two

So..., my first post on creating Tomcat installation on OpenShift had some "bugs". In this post I will describe better way of initializing Tomcat.

First change is that I installed client tools as instructed in this link. While installing GIT I choose using ssh2 and not Putty plink.

Second change is that I used template from GitHub  (https://github.com/lulinqing/openshift-tomcat-quickstart)

So this is the steps that I used:
  • Creating DIY application: rhc app create -a tomcat -t diy-0.1
You should be positioned in directory where you want local git repo to be.
  • Go into created directory: cd tomcat
  • Add another remote git repo: git remote add upstream -m master git://github.com/lulinqing/openshift-tomcat-quickstart.git
  • Pull changes from repo: git pull -s recursive -X theirs upstream master
After I pulled configuration I have changed file /.openshift/action_hooks/deploy. This file is script that executes every time that you push to OpenShift repo. Default script will only copy files if tomcat directory doesn't exist, I have changed script to copy complete tomcat on every git push.

/.openshift/action_hooks/deploy:
 #!/bin/bash   
 # This deploy hook gets executed after dependencies are resolved and the   
 # build hook has been run but before the application has been started back   
 # up again. This script gets executed directly, so it could be python, php,   
 # ruby, etc.   
 set -x   
 if [ -d $OPENSHIFT_DATA_DIR/tomcat ] then   
    rm -rf $OPENSHIFT_DATA_DIR/tomcat/   
 fi   
 cp -rf $OPENSHIFT_REPO_DIR/diy/tomcat $OPENSHIFT_DATA_DIR   
 cd $OPENSHIFT_DATA_DIR/tomcat   
 rm -rf logs   
 ln -s $OPENSHIFT_DIY_LOG_DIR logs   
 sed -ig 's/OPENSHIFT_APP_DNS/'$OPENSHIFT_APP_DNS'/' conf/server.xml   

I have also changed password in file tomcat-users.xml.

That's it, now you can commit changes and push them to Openshift: git push
And wait few moments to propagate changes and you can log in to your new tomcat installation.

I have created GitHub fork with my changes at https://github.com/McNullty/openshift-tomcat-quickstart so you can use this repo as remote stream if you don't want to manually change anything.

Next post will be on connecting to database, I promise :-).

No comments:

Post a Comment