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

Use rclone to mount cloud storage

I realized that the fat clients that allows you to sync your contents are not only wasting CPU cycles but also lots of disk space. Yes, that enables you to have the file opened almost instantly, no matter its size, but for me that use case is almost never needed, I use the cloud storage to save stuff that is in the range of a few MiB. Here is where rclone comes into play, it allows you to mount your storage as if it were a regular disk, and it handles the communication with the cloud servers on the go. As there are many different combinations I'll cover only two Linux w/ Dropbox curl https://rclone.org/install.sh | bash # Use rclone config to add a new remote called db for dropbox MAIN_USER=$SUDO_USER MAIN_USER_HOME=$(grep ^$SUDO_USER: /etc/passwd | head -1 | cut -d: -f6) mkdir /media/db chown $MAIN_USER:$MAIN_USER /media/db cat <<EOF > /lib/systemd/system/rclone-db.service [Unit] Description=Dropbox rclone mount After=multi-user.targetrclone [Service] Type=simple User=$ M...