Launch Tomcat on OpenShift

    image

    Having read an article on Habré about OpenShift ,
    I immediately wanted to make friends with this platform. Still, a free remote computer with 512MB of RAM and 1GB of space will not be superfluous in the economy. ;) Moreover, you can run not only the web server offered by the platform itself, but also something of your own. The choice fell on Tomcat with a small personal project.

    Next, I will describe the algorithm for implementing this idea:



    1. Get ssh access


    • Create an account on OpenShift
    • After authorization, you are prompted to choose an application type ( Choose a type of application ),
      select the Do-It-Yourself type from the list
    • Set the Public URL and click Create Application
    • Hooray, the remote computer is waiting for us! It remains to reach it through ssh. At the bottom of the page we see the Set your Public Key section - you need to set the public key. I took advantage of public key generation through PuTTY . By sending the public key to the server, an ssh address will be available to us (something like: ssh: //much-digit@your-application.rhcloud.com)
    • Now you can deploy your application!


    2. What do they give?


    In the beginning, I’ll say a few words about the remote machine we received:
    • Installed java 1.6.0_22
    • For the outside world, you can use port 8080, which, by default, is occupied by a ruby ​​stub
    • For internal needs, you can use only ports 15000 - 35530
    • For server debug, you can separately enable port 8787 (more on that below)


    3. Launch Tomcat


    The basic nuances of copying a server to a remote machine are described in this wonderful article . Therefore, we assume that we have already copied Tomcat to the app-root / data / tomcat folder , configured ip and all ports in the app-root / data / tomcat / conf / server.xml file (we got ip from $ OPENSHIFT_INTERNAL_IP, and set the port values above 15000, except for port 8080) and now we are ready to start our server, but the ruby-stub already running on port 8080 interferes with us. And plus, we don’t have the option of debugging the server through port 8787. We will solve these difficulties:
    • It’s time to install OpenShift client tools . Unfortunately, without it, it will not be possible to solve all the problems voiced.
    • After installing client tools and running it in the console, you will be prompted to generate an ssh key and save it to the server. Be sure to agree! Because Git will use this key , but nobody knows anything about your PuTTY key :)
    • So, we have client tools and Git, now we can turn off the ruby ​​stub. At the beginning, check out the article explaining how to start and stop applications through the Git repository . In a nutshell, the meaning is this: when you push to a remote computer, it automatically calls sh-scripts from the .openshift / action_hooks folder (this is the path relative to the repository, but the address on the remote machine is: app-root / runtime / repo / .openshift / action_hooks ). These scripts are designed to stop the current web server, build and restart it. By default, ruby ​​stubs are written in these sh-files. The idea is to remove .openshift / action_hooks / start from the scriptrun this stub and send the changes to the remote repository. Then the .openshift / action_hooks / stop script will stop the stub and port 8080 will be free.
    • Actually, we do everything that was said above: download the repository to our machine, edit the .openshift / action_hooks / start file , removing the ruby ​​stub from it, and send the changes to the server. As a result, port 8080 is freed up and we can launch our Tomcat through PuTTY. No, of course, you can register the start and stop of the tomato in the .openshift / action_hooks files , but I was not interested - the ssh console is somehow closer;)
    • Almost everything is ready. Tomcat is launched and available to the outside world. It remains only to solve the problem with debug. The solution lies in this article . In a nutshell, you need to create a new .openshift / markers / enable_jpda file and upload it to the remote repository. After that, port 8787 will be open for our tomato. But stop! After all, only port 8080 sticks out, how can I get to 8787?
    • To access ports other than 8080, you need to use client tools : we type rhc-port-forward –a applicationName in our console and now all ports of the remote machine are available on the local machine (at the address in the spirit of 127.6.242.5)


    4. Summary


    The Tomcat launch algorithm on OpenShift turned out to be rather dreary, but you won’t do anything for the sake of a freebie. Have a nice work!

    Also popular now: