Ir al contenido principal

Deploy pseudo Tomcat 7 to OpenShift arquitecture

Hi everybody.

I have been playing with PaaS services lately, and the best for me is OpenShift, for clear reasons: no strings attached, nice interfaces, all built from Red Hat up, etc.

The other side of the coin is that the appliances and all the application servers come with the OpenShift flavor, and that's not what I need. I need a plain Tomcat or JBoss in case that I want to go on the hunt for better tides.

With a little bit of research I managed to have my half-out-of-the-box Tomcat server running on top of the OpenShift platform, and take advantage of the hot deploying that my beloved Tomcat 7-Maven plugin gave me.

Here are the steps. First of all, create an OpenShift account. You can apply for these accounts at https://www.openshift.com/app/account/new, and they offer you 3 gears for free, which means that you can run up to 3 app servers/appliances/whatever. Every gear comes with candies, like relational databases and several tools. You should really check that out.

Once you have an account, you should download the RHC Client that allows you to interface the platform from your commandline. This is awesome. Well, at least for me, since I'm a commandline-lover. Anyway, if you don't want to do that, you can interface OpenShift straight from their website. Yes, like NOOBS. I will assume you are a NOOB and will describe the procedure from your point of view.

Ok, the next step is to create a gear. Our objetive is to create a Tomcat 7 app Server. To do that, go to your app console and follow the steps of "Add Application...". I'm going to speed up a little. You have to search for Tomcat 7, select it, choose a domain, and click "Create application".

Everybody wants to use Tomcat for something useful, so you may want to add a database. To do that, click on "Add MySql vX.Y" and add a cartridge (this is the candy I talked about earlier). Now you have open up your password database and write the credentials down. What?! Oh, yes. Do it on a post-it, NOOB, no problem. Now add phpmyadmin too, you already know how.

Ok. Here comes the tricky part. Now you have to get access to a shell, do not continue without a shell. When you've got the shell you have to install Git and SSH, so you can check out the Git repo for your app.

Go to your console (https://openshift.redhat.com/app/console/applications) and select your fresh new Tomcat. You have to locate a string there like ssh://...hexstrings..@jbossews-yourdomain.rhcloud.com/~/git/jbossews.git/

Now do this.

$ git clone ssh://...hexstrings..@jbossews-yourdomain.rhcloud.com/~/git/jbossews.git/
$ cd jbossews
$ rm -rf pom.xml src/ webapps/*

Ok, the point is that you are removing everything from the Openshift compilation system. They aim to build your mavenized project in their systems and Git-control the source. Some people don't want that, they just want the app to be executed in the cloud, so for this reason we are removing Maven stuff.

The next part is to install Tomcat default applications like the manager, etc.

$ cd webapps
$ wget http://ftp.cixug.es/apache/tomcat/tomcat-7/v7.0.62/bin/apache-tomcat-7.0.62.tar.gz
$ tar xzvf apache-tomcat-7.0.62.tar.gz
$ mv apache-tomcat-7.0.62/webapps/manager .
$ mv apache-tomcat-7.0.62/webapps/host-manager .
$ mv apache-tomcat-7.0.62/webapps/ROOT .
$ rm -rf apache-tomcat-7.0.62*

Ok. What would happen if you try to deploy throught Tomcat7-Maven plugin is that you would get an auth error, since you haven't defined yet the users with manager roles, so continue with this:

$ echo '<?xml version="1.0" encoding="utf-8"?>
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <user username="admin" password="defineithere" roles="manager,manager-gui,manager-script"/>
</tomcat-users>
' > .openshift/config/tomcat-users.xml

Now that you are all set-up, run this order:

$ git add . && git commit -am "This would be my one and only push!" && git push

Congrats! You are now able to hot deploy to your Tomcat instance. HOW?? Relax, just add these lines to your project pom.xml inside the tag <plugins>:

<plugin>
     <groupId>org.apache.tomcat.maven</groupId>
     <artifactId>tomcat7-maven-plugin</artifactId>
     <version>2.0</version>
     <configuration>
         <url>http://jbossews-yourdomain.rhcloud.com/manager/text</url>
         <path>/${artifactId}</path>
         <username>admin</username>
         <password>defineithere</password>
         <update>true</update>
     </configuration>

</plugin>


And run $ mvn clean tomcat7:deploy in your favorite shell now that you have one ;)


--

To conclude, if you want to see the logs of your application, go to your OpenShift console and search for a "Remote access" section or stuff and copypaste the link into your shell.

$ ssh ...hexstrings...@jbossews-yourdomain.rhcloud.com

Now that you are inside, be careful, what you do here would reflect in the behavior of the app server instantly (I mean, without doing a Git push). You can do the usual log tail command:

$ tail -f app-root/logs/jbossews.log

or even restart the server with

$ gear restart


Have fun!!


Comentarios

Entradas populares de este blog

Yamaha XT 125R Manual

Para aquellos que lo hayan perdido y no quieran comprar uno nuevo por el doble de lo que cuesta cambiar el aceite.. https://mega.nz/#F!ZeYh3QzD !mSOhljTo5UWedfEWq5cCjw Algunos "trucos":  - Si os marca mal la velocidad es porque la teneis configurada mal (supermotard en enduro y viceversa), para cambiar este ajuste teneis que quitar la bateria varios minutos y al volver a enchufar con el boton azul seleccionar la correcta. La mia es enduro  - Si cambiais el aceite:    + Para no tener que desmontar media moto lo mejor es introducir una botella de cocacola de plástico cortada, con el tapón abierto y dejar que el aceite escurra a traves de ella hacia la lata dónde vais a desecharlo    + Para resetear el contador de kilómetros que quedan para el cambio de aceite hay que apagar la moto, pulsar el botón azul, encenderla y esperar hasta que en la pantalla aparezca reseteado

Tasker: Profiles with priorities

Hi! If you read Tasker docs, you may find that with Tasker its not possible to establish actions based on profile priorities if you have two of them activated at the same time; in the other hand Setting Profiles is a unmantained old app that can do this, but have no scripting capabilities like Tasker. Here is the solution using Tasker powerful environment. The main idea is to do this: Profiles/Init (44) A1: If [ %Profiles_pactivelast Is Set & %Profiles_pactivelast !~ %PACTIVE ] A2: Perform Task [ Name:Profiles/Profile/Default Stop:Off Priority:5 Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: ]  A3: Variable Set [ Name:%profile_priority To:Work,Class,Study,Sleep,Low battery, Charging weak,Charging strong Do Maths:Off Append:Off ]  A4: Variable Split [ Name:%profile_priority Splitter:, Delete Base:Off ]  A5: For [ Variable:%profile Items:%profile_priority() ]  A6: [X] Flash [ Text:%profile Long:Off ]  A7: [X] Wait [ MS:0 Seconds:5 Minutes:0 Hour