Live Debugging

Use the Apcera Platform to clone a running app using a capsule and debug the clone without disturbing the running app.

Requirements:

1: Deploy an app

Using your APC client, target your cluster and log in.

apc target <your-cluster>.apcera-platform.io

apc login -- basic

Tip: To get the target URL, run command

./apcera-setup info

CD to the sample app directory for this tutorial.

cd sample-apps-master/example-java-hello/

Deploy and start the Java app.

apc app create live-debug -dr -ae -–start --batch

You should see that app runs and outputs “Hello, World.”

[stdout] Hello, World

2: Debug the live app

Clone the app for live debugging by running the apc app console live-debug command.

apc app console live-debug

Creating a capsule for "job::/sandbox/admin::live-debug"... done

Starting the capsule... done

Waiting for the capsule to start...

Start Command: java HelloWorld

root@ip-169- 254-0- 35:/$

An app console is a cloned instance of your app running inside an Apcera capsule. Creating a console app immediately drops you into the container as root via SSH without exposing the SSH port on the live app. The cloned app includes all service bindings present in the original app, and lets you debug the app without disturbing the running instance.

In the cloned app, cd to the /app directory and list the files.

You see the source code for the cloned app.

cd app

ls

HelloWorld.class HelloWorld.java README.md

If necessary, install the VI editor into the capsule container:

apt-get update && apt-get install vim

Edit the source code using the VI editor:

$vi HelloWorld.java

Arrow down to the following line in the code and arrow over to the end of the quoted string “Hello, World ”.

System.out.println("Hello, World");

Press the “i” key to enter insert mode.

Enter a space and append “LIVE-DEBUG” to the output, within the quotes.

public class HelloWorld {
    public static void main(String[] args) throws Exception {
        while (true){
            System.out.println("Hello, World LIVE-DEBUG");
            TimeUnit.SECONDS.sleep(15);
        }
    }
}

Press the escape key to exit insert mode.

Enter the following command to save your changes and quit the VI editor: colon + w + q

:wq

Compile the source code and run the app:

javac *.java
java HelloWorld

You see that the cloned app runs the changes you made to the source.

Enter Ctrl + C to stop the app.

Enter “exit” to return to APC. Notice that the app console is destroyed and the SSH session is closed.

$exit
logout
Stopping the capsule... done
Deleting the capsule... done
SSH connection closed with
status: 130

Now restart the app using APC. You see that the deployed version of the app remains unchanged. This demonstrates how Apcera’s capsule feature is used to easily allow you to perform live debugging of your apps and services.

$ apc app restart live-debug
Stopping "live-debug"... done
Restarting "live-debug"... done
Waiting for "live-debug" to
start...
[stdout] Hello, World