Jetty on OpenShift

Well I started to make my hands dirty with Redhat’s OpenShift, when i started doing so  sometime back i was left with options on using only JBoss AS7 or PHP or Perl etc.,  as a main platform which is called Cartridge in OpenShift terms.  Ideally this left me using JBoss AS7 as my default container for deploying my J2EE applications, well that’s OK if my application is leveraging all the J2EE features. When we want to deploy the applications that are pretty much a normal web applications that require only a Servlet Container then AS7 is bit too much though its fast but the main question was why do we need to look in to use or load unnecessary modules when we just need only a Servlet Container, this made me look for other options like using servers like Tomcat or Jetty.These thoughts made me try to see how I can do with OpenShift, but OpenShift was smart enough to provide us with a new Cartridge called Do It Yourself (DIY), here are the steps that I followed in setting up the Jetty server on OpenShift platform, I did use my OpenShift express account which is easy to setup and free.

  1. After creating a DIYourself (DIY) application on your OpenShift Express account
  2. I logged in to the application using SSH using the bash provided by OpenShift
  3. We need to download and install Jetty now, the real thing here is that we will not have write permissions on any folder other than “data”, “repo” and “tmp”.
  4. I preferred to use the “data” folder because its persistent folder across Git pushes, the Git pushes always refreshes the contents inside the “repo” folder, and “tmp” folder is wiped off in 7-10 days time if there is not modification so i resorted to “data” the best folder for us to install Jetty/Tomcat
  5. Do a curl or wget to download and install Jetty
  6. As per OpenShift rules/constraints we need to use $OPENSHIFT_INTERNAL_IP and 8080 as the port for the server to make our applications available over the internet
  7. For Jetty we need to edit the $JETTY_HOME/etc/jetty.xml and edit the Connectors as follows,

…..

<Set name="connectors">
  <Array type="org.mortbay.jetty.Connector">
    <Item>
      <New class="org.mortbay.jetty.nio.SelectChannelConnector">
        <Set name="host"><SystemProperty name="jetty.host" />$OPENSHIFT_INTERNAL_IP</Set>
        <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
        ...
      </New>
    </Item>
  </Array>
</Set>

….

8.  I then made a small startJetty.sh script where I added a JVM arg as shown below,

java -DSTOP.PORT=$STOP_PORT -jar $JETTY_HOME/start.jar

$STOP_PORT – for now can have only few port values that OpenShift are allowed us bind to something like mysql (3306) port, postgresql(5432) port, mongodb(27017) port ,we need to make a decision here on which port to use based on the list of unused ports that OpenShift allows us to bind to.

Viola! We now can create new applications and deploy them our Jetty server in the OpenShift PaaS. 

Another nice we could do on top it is like adding a hook to our git repo to that the applications are auto deployed to our Jetty . We could see how to do this in my next blog in this series.

Hats off the Redhat OpenShift developers for developing such a cool thing!

About these ads

One thought on “Jetty on OpenShift

  1. Pingback: Running Tomcat on OpenShift - Web programming blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s