Close

Request a demo

CliQr's groundbreaking technology makes it fast and efficient for businesses to move, manage and secure applications onto any private, public or hybrid cloud environment.

CliQr is now part of Cisco Learn More About Cisco
Request a Demo

Blog

How to Display Script Messages in Deployment Screens

CliQr CloudCenter removes the need for a lot of scripting by taking care of the infrastructure configuration for you, but your applications might still need to be installed and configured via scripts. Your developers might sometimes want messages or errors from these scripts to display within CloudCenter screens for faster troubleshooting.

I recently learned a cool trick that will make script error and messages display within the CloudCenter deployment screen.

The below steps and outcome will be illustrated with a VERY simple script that you can download, if you wish, HERE. I used CentOS for these steps and they will work on any Linux based OS. The script is intended to have one command that work and one that does not. The contents of the script are:

#!/bin/bash
echo “something” > file
TEST –test

Like I said, VERY simple. Obviously, there’s no command called “TEST” and that one will be the one to fail and give us an error.

General method

The very first step is to alter your script to have the logging feature.

  1. Add the following line to your script to include the CliQr agent utility:. /usr/local/osmosix/service/utils/agent_util.shThe outcome of the sample script would be:

    #!/bin/bash
    . /usr/local/osmosix/service/utils/agent_util.sh
    echo “something” > file
    TEST –test

    If you want to use this on a windows machine, you would include the following in your script instead:c:\Program Files\osmosix\service\utils\agent_util.ps1

  1. Next, add in messages that you want to display in the CloudCenter deployment screen by calling the CliQr agent’s agentSendLogMessage function. An example of that would be:

    #!/bin/bash
    . /usr/local/osmosix/service/utils/agent_util.sh
    agentSendLogMessage “SCRIPT MESSAGE: Building text file”
    echo “something” > file
    agentSendLogMessage “SCRIPT MESSAGE: Text file created successfully. Running TEST command”
    TEST –test

  1. Save and upload this script to your code repository so that you can call it from an application profile. The final script can be downloaded HERE.

Now, let’s test out the result of the logging messages. To create an application profile that will run this script:

  1. Navigate to your application screen and press Model
  2. Select the N-Tier Execution template
  3. Go to the “OS Service” area of the services library, choose a CentOS (or other Linux based OS) service and drag it onto the palate.
  4. In the properties, go to “Node Initialization and Clean Up”
  5. Select your repository and enter the relative path to your script
  6. On the basic information tab, supply a name and version
  7. Save
  8. Deploy the newly created application profile

Below are screenshot comparisons of deploying in CloudCenter with and without logging.

Without Logging

With Logging

Screen Shot 2015-12-16 at 9.54.41 AM Screen Shot 2015-12-16 at 10.05.20 AM
Screen Shot 2015-12-16 at 9.55.15 AM  Screen Shot 2015-12-16 at 10.06.02 AM

You can see that adding the CliQr agent utilities into your script gives you more detailed error messages but also the log messages that are entered into the script. COOL and EASY!

EXTRA CREDIT

That’s great and good to be able to do this, but doesn’t that lock us into keeping CliQr forever, or have to go back and update all of our scripts? Nope!

To take this one step further, let’s make a wrapper script so that there can be comments in the scripts, but are turned into commands when run by CliQr. The wrapper script I’ve built looks like the below and can be downloaded as part of the package the following steps will help you build, HERE:

  1. Create a wrapper script:

    #!/bin/bash
    if [ $2 = "debug" ]; then
    . /usr/local/osmosix/service/utils/agent_util.sh
    sudo sed -i ‘s/#cliqr//g’ $1
    . $1
    else
    . $1
    fi

  2. Now, update the core script to have a #cliqr in front of all calls to the logging function, like the below. Note that you no longer need the call to the CliQr agent_util in this core script.

    #!/bin/bash
    #cliqr agentSendLogMessage “SCRIPT MESSAGE: Building text file”
    echo “something” > file
    #cliqr agentSendLogMessage “SCRIPT MESSAGE: Text file created successfully. Running TEST command”
    TEST -test

  3. You should now have 2 files, the core script and the wrapper script. Put both of these files into a zip and place it on your repository.
  4. In your application profile, select the repository and enter the zip file’s relative path in the “Basic Information” tab’s “App Content Package” field
  5. In the “Topology Modeler” tab, click on the CentOS service and change the initialization script value to:<wrapperfile> <corefile> debugIf using the downloaded example zip from above, the command would be:wrapper.sh brokenwrapperlog.sh debug
  6. Save the profile
  7. Deploy the application

When the application deploys, the wrapper file runs the core file if the debug attribute is not supplied. If the debug attribute is supplied, it goes into the core file and removes all the #cliqr comments so that they then become commands to call back to the CliQr agent_util for the logging in the UI. Then end result looks as you probably expect from the previous exercises, but I didn’t have to make a static call within my already build script:

Screen Shot 2015-12-16 at 2.02.04 PM

 

Comments are closed

Stay Informed

Subscribe to our email list for company updates.

CliQr Technologies, CliQr CloudCenter and CloudBlades are trademarks of CliQr Technologies, Inc. All other registered or unregistered trademarks are the sole property of their respective owners.