Imagine a bacon-wrapped Ferrari. Still not better than our free technical reports.
See all our reports

Script Java EE Production Hot Updates with LiveRebel and Bash

One of the features that we are looking forward to more people learning about in LiveRebel is the command line interface (CLI). You can run most of the LiveRebel functionality from the command line. There is a manual that covers most of the CLI aspects available on our LiveRebel documentation page. In this article we will use those bits and pieces to write a script that will run automatic updates.

We will be using bash as the scripting language. The end script is available from the LiveRebel Scripts repository.

Some assumptions:

  • We assume that you have installed and configured LiveRebel, and you have access to the LiveRebel script (in the LiveRebel installation’s bin directory).
  • We assume that you have a script to run a full redeploy/restart when LiveRebel does not support the change.

You’ll need a LiveRebel authorization token found inthe LiveRebel Web Console as shown here:

Let’s start with writing the script by defining the TOKEN and LiveRebel home directory and the locations.


# LiveRebel Command Center token
# LiveRebel Installation Dir

Next, let’s use the 1st parameter to the script as the WAR file that needs to be uploaded to the LiveRebel Command Center. We will take the output of the upload command into a variable called RESULT and later on use that to parse the response.

RESULT=$($CLI_SCRIPT -token $TOKEN -url localhost:9001 upload -file $FILENAME)

Now to parse the response. The response has 3 different outcomes and based on the result we are also interested in the name of the application (the application name can be different from the WAR archive name, it is defined in the liverebel.xml file inside the WAR archive).

  • Unable to connect to LiveRebel Command Center
  • Application has already been uploaded
  • The upload was a success
if [[ $RESULT == *refused* ]];
    echo "Unable to connect to LiveRebel. Are you sure your server is running?"
    echo "Exiting..."
    exit 1
elif [[ $RESULT == *ERROR* ]];
    VER=`echo $RESULT | grep -o "Version [^a-z]*"`
    VER=${VER#Version }

    APP=`echo $RESULT | grep -o "of application .* already exists"`
    APP=${APP#of application }
    APP=${APP% already exists}
    VER=`echo $RESULT | grep -o "Version: .*"`
    VER=${VER#Version: }

    APP=`echo $RESULT | grep -o "Application: .*Version: "`
    APP=${APP#Application: }
    APP=${APP% Version: }

If everything went well, then by now we have either uploaded the WAR file or it already exists on the LiveRebel Command Center. We’ve also extracted the name of the application and the version. The next step is to figure out the active version of this application. We will later on use this information to run the compatibility test.

# find out the active version
RESULT=$($CLI_SCRIPT -token $TOKEN -url localhost:9001 vers -app $APP)
ACTIVE_VER=`echo $RESULT | grep -o "Active: .*"`

if [[ "" == $ACTIVE_VER ]];
    echo "The application is not deployed to any of the servers. Not doing anything"
    exit 1

echo "Active ver $ACTIVE_VER, uploaded $VER"

if [[ $VER == $ACTIVE_VER ]];
    echo "You are trying to upload the same version. Not doing anything"
    exit 1

We have the active version of the application now. Now let’s find out if the update from the active version to the version we just uploaded is supported by LiveRebel or not. If it is compatible, then run the update – otherwise use your fallback solution.

RESULT=$($CLI_SCRIPT -token $TOKEN -url localhost:9001 diff -app $APP -from $ACTIVE_VER -to $VER)

if [[ $RESULT == "Compatibility: compatible" ]];
    echo "Versions are compatible. Activating version $VER"
    $CLI_SCRIPT -token $TOKEN -url localhost:9001 update -app $APP -ver $VER
    # your own custom script to run the redeploy

Voila! and we’re done. This article serves as an example how to interact with LiveRebel Command using the CLI. Your mileage may vary and you might want to invoke the LiveRebel script from your own master script. If that is the case, you will need to change a few things here and there. But just refer to the CLI documentation and use the commands one by one.

PS! We are working on a Jenkins/Hudson plugin that would do all this automatically. In case of incompatibility it would either use the Cargo plugin as fallback option. This plugin is available from the LiveRebel Deploy Plugin repository.