Skip to content

Deploy Scripts

In this tutorial, we demonstrate how to deploy scripts on a node using Edge Builder CLI. This will cover how to:

Initialise Edge Builder server components and CLI

To initialize the Edge Builder server components and CLI, complete the following steps:

  1. Set up the environment as described in Tutorials Setup

  2. SSH into the master node:

    vagrant ssh master
    

  3. Start the Edge Builder server components using the following command:

    sudo edgebuilder-server up -a 192.168.56.10
    
    When the server components are up, you should see all server components up and running via the docker ps command:
    vagrant@master:~$ docker ps
    CONTAINER ID   IMAGE                                    COMMAND                  CREATED          STATUS          PORTS                                                                                                                                                     NAMES
    cd848b7cf1b6   iotechsys/dev-eb-controller:1.2.0.dev    "./entrypoint.sh"        15 seconds ago   Up 11 seconds   0.0.0.0:8085->8085/tcp, :::8085->8085/tcp, 0.0.0.0:50000-50100->50000-50100/tcp, :::50000-50100->50000-50100/tcp, 0.0.0.0:1022->22/tcp, :::1022->22/tcp   eb-controller
    58072d82dbc3   chronograf:1.8.8-alpine                  "./custom-entrypoint…"   17 seconds ago   Up 14 seconds   0.0.0.0:8888->8888/tcp, :::8888->8888/tcp                                                                                                                 eb-chronograf
    b40a1ec47019   iotechsys/dev-eb-salt-master:1.2.0.dev   "/bin/sh -c 'sed -i …"   19 seconds ago   Up 15 seconds   0.0.0.0:4505-4506->4505-4506/tcp, :::4505-4506->4505-4506/tcp, 0.0.0.0:8099->8099/tcp, :::8099->8099/tcp                                                  eb-salt-master
    56f1c3bc6ee5   iotechsys/dev-eb-webssh:1.2.0.dev        "wssh --address=0.0.…"   19 seconds ago   Up 15 seconds   0.0.0.0:8989->8989/tcp, :::8989->8989/tcp                                                                                                                 eb-webssh
    5064b0670594   portainer/portainer-ce:2.1.0-alpine      "/portainer -H unix:…"   19 seconds ago   Up 15 seconds   0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp                                                                      eb-portainer
    8f5ff8a2e5e7   vault:1.7.1                              "./entrypoint.sh"        19 seconds ago   Up 15 seconds   8200/tcp                                                                                                                                                  eb-vault
    a05e87267db8   iotechsys/dev-eb-redis:1.2.0.dev         "redis-server /etc/r…"   19 seconds ago   Up 16 seconds   6379/tcp                                                                                                                                                  eb-redis
    161101640ff1   influxdb:1.8.1-alpine                    "./custom-entrypoint…"   19 seconds ago   Up 16 seconds   0.0.0.0:8086->8086/tcp, :::8086->8086/tcp                                                                                                                 eb-influxdb
    dd24648ebb7b   grafana/grafana:7.4.2                    "/run.sh"                19 seconds ago   Up 15 seconds   0.0.0.0:3000->3000/tcp, :::3000->3000/tcp                                                                                                                 eb-grafana
    71749e615a76   postgres:alpine                          "./entrypoint.sh"        19 seconds ago   Up 16 seconds   5432/tcp                                                                                                                                                  eb-db
    5cae5e428799   kapacitor:1.5-alpine                     "/entrypoint.sh kapa…"   19 seconds ago   Up 17 seconds   9092/tcp                                                                                                                                                  eb-kapacitor
    

  4. Log in to Edge Builder with the default user credentials using the following command:

    edgebuilder-cli user login -u iotech -p EdgeBuilder123 -c "http://192.168.56.10:8085"
    
    You should see the following INFO message:
    INFO: User "iotech" logged in successfully
    

  5. Confirm that you have a valid license in the Vagrant project directory (edgebuilder-vagrant)

  6. Add the license using the following command:
    edgebuilder-cli license add -l DemoLicense -f /vagrant/EdgeBuilder_test_Evaluation.lic
    
    You should see the output similar to that shown below:
    INFO: License added successfully
    +-------------+--------------------------------------+---------------------------------+-----------+-----------+
    | NAME        | ID                                   | FILENAME                        | MAX NODES | EXPIRY    |
    +-------------+--------------------------------------+---------------------------------+-----------+-----------+
    | DemoLicense | b65c2ba0-c78b-4031-aaf4-cc030d3d763d | EdgeBuilder_test_Evaluation.lic | 100       | unlimited |
    +-------------+--------------------------------------+---------------------------------+-----------+-----------+
    INFO: Viewing 1 result(s)
    

Add a node

In this section of the tutorial, we will add a node to Edge Builder. It is accessible on 192.168.56.11.

To add an edge node, complete the following steps:

  1. Confirm that the example node configuration file is avaliable using the cat command:

    cat /vagrant/examples/single-node-config.json
    
    Expected output:
    {
      "NodeConfig": [
          {
              "name": "node1",
              "description": "virtual node 1",
              "nodeaddress": "192.168.56.11",
              "username" : "vagrant",
              "password" : "vagrant",
              "serveraddress": "192.168.56.10",
              "groups" : []
          }
      ]
    }
    

  2. Add the node to Edge Builder using the following command:

     edgebuilder-cli node add -f /vagrant/examples/single-node-config.json
    
    Expected output:
    INFO: SSH Node(s) added successfully:
    +-------+--------------------------------------+
    | NODE  | ID                                   |
    +-------+--------------------------------------+
    | node1 | e01c540b-fa87-4721-b38c-5f0109210381 |
    +-------+--------------------------------------+
    INFO: Viewing 1 result(s)
    

  3. Confirm that the node has been added using the following command:

    edgebuilder-cli node view --all
    
    Expected output:
    INFO: Finding nodes: ["node1"]
    INFO: *** Node View Results ***
    +-------+--------------------------------------+--------+------------+--------------+------------------------------------------+----------------+
    | NAME  | ID                                   | STATUS | DEBUG MODE | METRICS MODE | LABELS                                   | DESCRIPTION    |
    +-------+--------------------------------------+--------+------------+--------------+------------------------------------------+----------------+
    | node1 | f0d8244d-3f72-475c-b567-6cddbf8053e0 | Up     | Off        | Local        | Kernel:Linux, OSFinger:Ubuntu-20.04, Use | virtual node 1 |
    |       |                                      |        |            |              | rName:root, OSArch:amd64, Manufacturer:i |                |
    |       |                                      |        |            |              | nnotekGmbH, Language:en_US, label1, OSFa |                |
    |       |                                      |        |            |              | mily:Debian, CPUModel:Intel(R)Core(TM)i9 |                |
    |       |                                      |        |            |              | -9900CPU@3.10GHz, ProductName:VirtualBox |                |
    |       |                                      |        |            |              | , Virtual:VirtualBox, Hostname:node1, CP |                |
    |       |                                      |        |            |              | UArch:x86_64, GroupName:root, label2, Ti |                |
    |       |                                      |        |            |              | mezone:UTC                               |                |
    +-------+--------------------------------------+--------+------------+--------------+------------------------------------------+----------------+
    INFO: Viewing 1 result(s)
    

    Note

    • The status of the node is initially shown as Deploying. After a few minutes, you can re-issue the command and the status will have changed to Up
    • You can also use the watch command with the node view above to automatically track the status changes

Add a script definition

In this section of the tutorial, we demonstrate how to add a script definition which will be used to run the script on the node

  1. Confirm that you have the example script definition configuration file using the following command:

    cat /vagrant/examples/hello-script-def-config.json
    
    Expected output:
    {
      "ScriptDefinitionConfig": [
        {
          "Name": "Hello",
          "Description": "Example script definition to print Hello World",
          "ScriptFile": "/vagrant/examples/hello.py"
        }
      ]
    }
    

  2. Confirm that you have the associated python script using the following command:

    cat /vagrant/examples/hello.py
    
    Expected output:
    print("Hello World!")
    print("changed=yes")
    exit(0)
    

  3. Add the script definition to Edge Builder using the following command:

    edgebuilder-cli scriptDefinition add -f /vagrant/examples/hello-script-def-config.json
    
    Expected output:
    INFO: ScriptDefinition(s) added successfully:
    +-------+--------------------------------------+--------+
    | NAME  | ID                                   | TYPE   |
    +-------+--------------------------------------+--------+
    | Hello | 8013ae09-f11d-4cf2-a02c-7e5dfbfb4ad2 | Python |
    +-------+--------------------------------------+--------+
    INFO: Viewing 1 result(s)
    

  4. Confirm that the script definition has been added using the following command:

    edgebuilder-cli scriptDefinition view --all
    
    Expected output:
    INFO: Finding all scriptDefinitions...
    INFO: *** ScriptDefinition View Results ***
    +-------+--------------------------------------+--------+--------+------------------------------------------------+
    | NAME  | ID                                   | TYPE   | LABELS | DESCRIPTION                                    |
    +-------+--------------------------------------+--------+--------+------------------------------------------------+
    | Hello | 337062b7-471c-44f2-b6cf-0dab73b86120 | Python |        | Example script definition to print Hello World |
    +-------+--------------------------------------+--------+--------+------------------------------------------------+
    INFO: Viewing 1 result(s)
    

Run a script on a node

In this section of the tutorial, we demonstrate how to run a script on a node

  1. Deploy the script using the following command:

    edgebuilder-cli script deploy -d Hello -n node1
    
    Expected output:
    INFO: Deploying script(s):
    +--------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    | SCRIPT NAME                                | SCRIPT ID                            | STATUS  | NODE ID                              | LABELS |
    +--------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    | Hello_7a88ea96-5333-420b-ad62-4458aa6e9848 | 7a88ea96-5333-420b-ad62-4458aa6e9848 | Pending | f0d8244d-3f72-475c-b567-6cddbf8053e0 |        |
    +--------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    INFO: Viewing 1 result(s)
    

  2. Confirm that the script has been run using the following command:

    edgebuilder-cli script view --all
    
    Expected output:
    INFO: Finding all scripts...
    INFO: *** Script View Results ***
    +--------------------------------------------+--------------------------------------+--------+--------------------------------------+--------------------------------------+--------+
    | NAME                                       | ID                                   | STATUS | SCRIPT_DEFINITION ID                 | NODE ID                              | LABELS |
    +--------------------------------------------+--------------------------------------+--------+--------------------------------------+--------------------------------------+--------+
    | Hello_7a88ea96-5333-420b-ad62-4458aa6e9848 | 7a88ea96-5333-420b-ad62-4458aa6e9848 | Done   | 337062b7-471c-44f2-b6cf-0dab73b86120 | f0d8244d-3f72-475c-b567-6cddbf8053e0 |        |
    +--------------------------------------------+--------------------------------------+--------+--------------------------------------+--------------------------------------+--------+
    INFO: Viewing 1 result(s)
    

  3. The script can be inspected to view details about its execution:

    edgebuilder-cli script inspect -s <script_id>
    
    Expected output:
    {
      "Metadata": {
        "ResultSet": {
          "Count": 1,
          "Total": 1
        }
      },
      "Results": [
        {
          "CreatedBy": "iotech",
          "Duration": 34.656,
          "ID": "7a88ea96-5333-420b-ad62-4458aa6e9848",
          "ModifiedBy": "iotech",
          "Name": "Hello_7a88ea96-5333-420b-ad62-4458aa6e9848",
          "NodeID": "f0d8244d-3f72-475c-b567-6cddbf8053e0",
          "ScriptDefinitionID": "337062b7-471c-44f2-b6cf-0dab73b86120",
          "Status": 3,
          "Stdout": "Hello World!",
          "TimestampCreate": 1639664606,
          "TimestampModify": 1639664609
        }
      ]
    }
    

Cancel a running script

In this section of the tutorial, you cancel a long-running script.

Info

You cannot cancel a script that has already completed. You must ensure that you use a long-running script for this tutorial.

  1. Confirm that you have the long-running example script definition configuration file using the following command:

    cat /vagrant/examples/long-script-def-config.json
    
    Expected output:
    {
      "ScriptDefinitionConfig": [
        {
          "Name": "LongRunning",
          "Description": "Example script definition to run a long computation",
          "ScriptFile": "/vagrant/examples/long.py"
        }
      ]
    }
    

  2. Confirm that you have the associated python script file using the following command:

    cat /vagrant/examples/long.py
    
    Expected output:
    import time
    
    print("Long script - start")
    time.sleep(300) # Sleep for 5 minutes
    print("Long script - end")
    
    print("changed=yes")
    exit(0)
    

  3. Add the script definition configuration file using the following command:

    edgebuilder-cli scriptDefinition add -f /vagrant/examples/long-script-def-config.json
    
    Expected output:
    INFO: ScriptDefinition(s) added successfully:
    +-------------+--------------------------------------+--------+--------+
    | NAME        | ID                                   | TYPE   | LABELS |
    +-------------+--------------------------------------+--------+--------+
    | LongRunning | 63afc0ed-4aee-4c27-a31e-16122b9abf77 | Python |        |
    +-------------+--------------------------------------+--------+--------+
    INFO: Viewing 1 result(s)
    

  4. Deploy the script using the following command:

    edgebuilder-cli script deploy -d LongRunning -n node1
    
    Expected output:
    INFO: Deploying script(s):
    +--------------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    | SCRIPT NAME                                      | SCRIPT ID                            | STATUS  | NODE ID                              | LABELS |
    +--------------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    | LongRunning_d684237c-311d-44a6-a400-efdf59e8a573 | d684237c-311d-44a6-a400-efdf59e8a573 | Pending | f0d8244d-3f72-475c-b567-6cddbf8053e0 |        |
    +--------------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    INFO: Viewing 1 result(s)
    

  5. View all scripts to see that the script is in the Running state

    edgebuilder-cli script view --all
    
    Expected output: INFO: Finding all scripts... INFO: Script View Results +--------------------------------------------------+--------------------------------------+---------+--------------------------------------+--------------------------------------+--------+ | NAME | ID | STATUS | SCRIPT_DEFINITION ID | NODE ID | LABELS | +--------------------------------------------------+--------------------------------------+---------+--------------------------------------+--------------------------------------+--------+ | Hello_7a88ea96-5333-420b-ad62-4458aa6e9848 | 7a88ea96-5333-420b-ad62-4458aa6e9848 | Done | 337062b7-471c-44f2-b6cf-0dab73b86120 | f0d8244d-3f72-475c-b567-6cddbf8053e0 | | | LongRunning_d684237c-311d-44a6-a400-efdf59e8a573 | d684237c-311d-44a6-a400-efdf59e8a573 | Running | 63afc0ed-4aee-4c27-a31e-16122b9abf77 | f0d8244d-3f72-475c-b567-6cddbf8053e0 | | +--------------------------------------------------+--------------------------------------+---------+--------------------------------------+--------------------------------------+--------+ INFO: Viewing 2 result(s)
    - Stop the running script, using the following command, where `<script_id>` is the ID of the long running script:
    
    edgebuilder-cli script cancel -s
    Expected output:
    
    INFO: Finding scripts: ["d684237c-311d-44a6-a400-efdf59e8a573"] INFO: Stopping 1 script(s)
    - Confirm that the running script has been canceled, using the following command:
    
    edgebuilder-cli script view -s
    Expected output:
    
    INFO: Finding scripts: ["d684237c-311d-44a6-a400-efdf59e8a573"] INFO: Script View Results +--------------------------------------------------+--------------------------------------+-----------+--------------------------------------+--------------------------------------+--------+ | NAME | ID | STATUS | SCRIPT_DEFINITION ID | NODE ID | LABELS | +--------------------------------------------------+--------------------------------------+-----------+--------------------------------------+--------------------------------------+--------+ | LongRunning_d684237c-311d-44a6-a400-efdf59e8a573 | d684237c-311d-44a6-a400-efdf59e8a573 | Cancelled | 63afc0ed-4aee-4c27-a31e-16122b9abf77 | f0d8244d-3f72-475c-b567-6cddbf8053e0 | | +--------------------------------------------------+--------------------------------------+-----------+--------------------------------------+--------------------------------------+--------+ INFO: Viewing 1 result(s)
    - To view the detailed results from the script run, you can use the following command:
    
    edgebuilder-cli script inspect -s
    Expected output:
    ```json
    {
      "Metadata": {
        "ResultSet": {
          "Count": 1,
          "Total": 1
        }
      },
      "Results": [
        {
          "CreatedBy": "iotech",
          "ID": "d684237c-311d-44a6-a400-efdf59e8a573",
          "ModifiedBy": "iotech",
          "Name": "LongRunning_d684237c-311d-44a6-a400-efdf59e8a573",
          "NodeID": "f0d8244d-3f72-475c-b567-6cddbf8053e0",
          "ScriptDefinitionID": "63afc0ed-4aee-4c27-a31e-16122b9abf77",
          "Status": 5,
          "TimestampCreate": 1639664869,
          "TimestampModify": 1639664922
        }
      ]
    }
    

Remove the node

To remove an edge node, complete the following steps:

  1. Remove the edge node node1 using the following command:

    edgebuilder-cli node rm -n node1 -y
    
    Expected output:
    INFO: Processing nodes: ["node1"]
    INFO: Attempting to remove 1 node(s)
    INFO: 1 node(s) removed successfully
    

  2. Confirm that the node has been removed using the following command:

    edgebuilder-cli node view -n node1
    
    Expected output:
    INFO: Finding nodes: ["node1"]
    WARN: node "node1" not found
    INFO: 0 results to view