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

Ahi va la segunda ventanilla rota, puto megane cc

Era cuestion de tiempo viendo la calidad de los componentes que monta Renault. Esta vez ha sido la ventanilla trasera el pasajero, asique he tenido que volver a investigar como arreglarla. Ahi va el procedimiento, intentare narrarlo bien porque no pude sacar fotos ya que estaba muy oscuro.
Lo primero y mas importante de todo es NO ACCIONAR LA VENTANILLA DESPUES DE QUE SE SEPA QUE SE HA ROTO, ya que lo unico que se consigue es liarla mas, pues funcionan con sistemas de cables tensos y cuando pierden la tension porque se ha roto una pieza o lo que sea, los cables se empiezan a enrrollar mal y se rompen mas, es decir, una averia de 10 euros se convierte en la de 300. Y no estamos para gastos.
Para empezar hay que intentar no maximizar el problema, asique lo que yo hice fue desconectar los botones de las ventanillas en la puerta del conductor, simplemente levantando el panel con un destornillador plano por la parte de delante, y en el panel de freno de mano, abriendo la guantera y tirando d…

Arreglando el elevalunas del megane II CC

Os voy a poner en antecedentes.

Nazco, crezco y el otro dia me meto en mi coche y al abrir la ventanilla suena un pedazo-de-ostia de mucho cuidado dentro de la puerta y le doy a subir y sube a trompicones, asique nada, me armé de valor y me puse a desmontar la puerta. Esto se hace siguiendo las instrucciones del hilo del foro meganecc que cuenta como cambiar el receptor de rf de la maneta del coche para la version manos libres, pero voy a contarlo un poco de palabra.