• Moving from a non-scaled to scaled OpenShift configuration

    I’ve long been intrigued by OpenSift’s automatic scaling option. Unfortunately, it was out of my reach until Postgres support for scaling was introduced in a recent update. With the path mostly clear (cron is still unavailable unfortunately) I decided to give it a whirl.

    Nothing I’ve read has given the impression that I could simply modify the current application using rhc to take advantage of scaling so i made a new scaled application.

    rhc app create -a MyApp -t jbossas-7 -s

    The “-s” flag tells the broker to create a scaled application. The configuration here is a bit different as rather than a public facing jboss cartridge you instead have haproxy sending requests to however many workers crankcase decides that it needs to have spooled up.

    Now the part I was dreading. A new application template to pull from OpenShift and migrate my code in to. Expecting disaster, I added my original repository as a remote in the new one, performed a git fetch operation into the new application template, and merged the master branch. Aside from a few easy conflicts in my index page, readme, and jboss configuration (my original app predated Java 7 compatibility) the merge operation was successful and I was glad to be able to keep my original code base with history. Seriously, git is a phenomenal tool.

    Similarly, OpenShift brought it to the party and picked up where git left off. I pushed to my new repository and it worked. I was expecting kinks with the JNDI since the Postgres support in scaling was brand new. Nope, everything works.

  • OpenShift PostgreSQL Backups

    Over the last few months I’ve been testing Red Hat’s new PaaS offering, OpenShift.  The testing insofar has gone extremely smooth, but what about preparing for when disaster strikes.  The rhc command-line client provides snapshot functionality but unfortunately carries the caveat of needing to shut down and restart the application in the process.  For a PHP or Python application this is fine as restarts are lightning fast, but redeploying a JavaEE application is… cough… not so lightning fast.

    If you can live with the need to restart, this command will give you a very complete tarball:

    rhc app snapshot save -a ApplicationName

    The other option is to do it via a cron job that will back up the data into your OpenShift data directory on the server (the data in this directory is not deleted each time the application is redeployed).  To do this, you will need to have the cron cartridge installed in your application.

    If you don’t already have the cron cartridge installed, you can easily enable it with this command:

    rhc app cartridge add -a ApplicationName -c cron-1.4

    With cron setup, we can setup jobs to run minutely, hourly, daily, weekly, or monthly by dropping scripts into the appropriate folder in our application’s .openshift/cron directory. Create a file named backup_postgres.sh in the minutely, hourly, daily, weekly, or monthly folder and paste the following script in. (Also available on GitHub)

    #!/bin/bash
    # Backs up the OpenShift PostgreSQL database for this application
    # by Skye Book <skye at skyebook.net>
    
    NOW="$(date +"%Y-%m-%d")"
    FILENAME="$OPENSHIFT_DATA_DIR/$OPENSHIFT_APP_NAME.$NOW.backup.sql.gz"
    pg_dump $OPENSHIFT_APP_NAME | gzip &gt; $FILENAME

    With the backup script created simply commit it and push the changes to your application.

    git add backup_postgres.sh
    git commit -m "Added PostgreSQL backup script"
    git push

    Once the changes are pushed you can retrieve your application’s database backups by using rsync

    rsync -avz -e ssh loginhash@appname-you.rhcloud.com:app-root/data ./

    This, admittedly, isn’t the prettiest solution to the problem but it does its job.  I may end up patching the rhc CLI app to do something similar to this and automatically download the results.

  • Finally a Real Website

    Well its only taken [insert unforgivable number of years], but I’ve finally gotten myself a serviceable web page at the root of my domain..  I still need to finish adding all of the content but I’m glad to have something up with at least some color instead of just redirecting to this rather drab (but very smart and full of knowledge!) blog.

    That said, I’ll see you over at https://skyebook.net

  • Where Have I Been?

    I realize I’ve been more vacant than usual these last few months, perhaps its time to get a post down on [roughly] what I’ve been up to.  In late February I took on a pretty interesting job for a big name client (details coming soon!).  The work has afforded me the ability to become quite intimate with a number of technologies of which I’d only had “user manual” level experience.

    • Event Driven HTTP Servers in Java
    • Lots of spatial analysis using PostgreSQL’s built-in Geometry types (I didn’t even know these existed outside of PostGIS)
    • Circle Packing algorithms
    • Super Bonus:Processing found its way back into my life!  Visual prototypes that happened to be beautiful really helped me out.

    There will be more information about what I’m up to in a the next week or two, but its exciting and I’m working with some awesome people.. Stay tuned!

  • Site Back Up

    After participating in Move Your Domain Day and moving a number of domains under my control from GoDaddy to Gandi, my site experienced some down time as their way of setting DNS records up was a little strange.  The fact that I was editing my records at all was a bit strange as Gandi seemed to indicate that it would copy my pre-existing zone file, but it is what it is.  That said, we’re back up and running.  Cheers.