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",
            "nodesshport": "22",
            "username" : "vagrant",
            "password" : "vagrant",
            "serveraddress": "192.168.56.10",
            "labels" : ["label1", "label2"]
          }
      ]
    }
    

  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                                   | LABELS         |
    +-------+--------------------------------------+----------------+
    | node1 | c355c48d-1cf1-492b-95d0-223a90d2d9ed | label1, label2 |
    +-------+--------------------------------------+----------------+
    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 all nodes...
    INFO: *** Node View Results ***
    +-------+--------------------------------------+--------+------------+--------------+------------------------------------------+----------------+
    | NAME  | ID                                   | STATUS | DEBUG MODE | METRICS MODE | LABELS                                   | DESCRIPTION    |
    +-------+--------------------------------------+--------+------------+--------------+------------------------------------------+----------------+
    | node1 | c355c48d-1cf1-492b-95d0-223a90d2d9ed | Up     | Off        | Local        | Kernel:Linux, GroupName:root, Manufactur | virtual node 1 |
    |       |                                      |        |            |              | er:innotekGmbH, OSArch:amd64, OSFamily:D |                |
    |       |                                      |        |            |              | ebian, label2, Language:en_US, ProductNa |                |
    |       |                                      |        |            |              | me:VirtualBox, label1, Timezone:UTC, OSF |                |
    |       |                                      |        |            |              | inger:Ubuntu-20.04, UserName:root, Virtu |                |
    |       |                                      |        |            |              | al:VirtualBox, CPUModel:11thGenIntel(R)C |                |
    |       |                                      |        |            |              | ore(TM)i7-11800H@2.30GHz, Hostname:node1 |                |
    |       |                                      |        |            |              | , CPUArch:x86_64                         |                |
    +-------+--------------------------------------+--------+------------+--------------+------------------------------------------+----------------+
    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",
          "Labels": ["scriptDef_label1", "scriptDef_label2"]
        }
      ]
    }
    

  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   | LABELS                             |
    +----------+--------------------------------------+--------+------------------------------------+
    | Hello_py | 1ff1982e-8f9e-4cea-9224-cbf924532f25 | Python | scriptDef_label1, scriptDef_label2 |
    +----------+--------------------------------------+--------+------------------------------------+
    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_py | 1ff1982e-8f9e-4cea-9224-cbf924532f25 | Python | scriptDef_label2, scriptDef_label1 | 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_py -n node1
    
    Expected output:
    INFO: Found nodes: "node1" 
    INFO: Deploying script(s):
    +-----------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    | SCRIPT NAME                                   | SCRIPT ID                            | STATUS  | NODE ID                              | LABELS |
    +-----------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    | Hello_py_6f544148-e720-4dfd-8a4b-40beb926d596 | 6f544148-e720-4dfd-8a4b-40beb926d596 | Pending | c355c48d-1cf1-492b-95d0-223a90d2d9ed |        |
    +-----------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    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_py_6f544148-e720-4dfd-8a4b-40beb926d596 | 6f544148-e720-4dfd-8a4b-40beb926d596 | Done   | 1ff1982e-8f9e-4cea-9224-cbf924532f25 | c355c48d-1cf1-492b-95d0-223a90d2d9ed |        |
    +-----------------------------------------------+--------------------------------------+--------+--------------------------------------+--------------------------------------+--------+
    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:
    {
      "CreatedBy": "iotech",
      "Duration": 15.064,
      "ID": "6f544148-e720-4dfd-8a4b-40beb926d596",
      "ModifiedBy": "iotech",
      "Name": "Hello_py_6f544148-e720-4dfd-8a4b-40beb926d596",
      "NodeID": "c355c48d-1cf1-492b-95d0-223a90d2d9ed",
      "ScriptDefinitionID": "1ff1982e-8f9e-4cea-9224-cbf924532f25",
      "Status": 3,
      "Stdout": "Hello World!",
      "TimestampCreate": 1646683505,
      "TimestampModify": 1646683507
    }
    

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",
          "Labels": []
        }
      ]
    }
    

  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: Found nodes: "node1" 
    INFO: Deploying script(s):
    +--------------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    | SCRIPT NAME                                      | SCRIPT ID                            | STATUS  | NODE ID                              | LABELS |
    +--------------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    | LongRunning_a0d043dc-7d99-4601-804e-1c18a0f8d1d9 | a0d043dc-7d99-4601-804e-1c18a0f8d1d9 | Pending | c355c48d-1cf1-492b-95d0-223a90d2d9ed |        |
    +--------------------------------------------------+--------------------------------------+---------+--------------------------------------+--------+
    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_py_6f544148-e720-4dfd-8a4b-40beb926d596    | 6f544148-e720-4dfd-8a4b-40beb926d596 | Done    | 1ff1982e-8f9e-4cea-9224-cbf924532f25 | c355c48d-1cf1-492b-95d0-223a90d2d9ed |        |
    | LongRunning_a0d043dc-7d99-4601-804e-1c18a0f8d1d9 | a0d043dc-7d99-4601-804e-1c18a0f8d1d9 | Running | 1dbf6db6-09ff-4de9-9942-424dee435400 | c355c48d-1cf1-492b-95d0-223a90d2d9ed |        |
    +--------------------------------------------------+--------------------------------------+---------+--------------------------------------+--------------------------------------+--------+
    INFO: Viewing 2 result(s)
    

  6. Stop the running script, using the following command, where <script_id> is the ID of the long running script:

    edgebuilder-cli script cancel -s <script_id>
    
    Expected output:
    INFO: Finding scripts: ["a0d043dc-7d99-4601-804e-1c18a0f8d1d9"]
    INFO: Stopping 1 script(s)
    

  7. Confirm that the running script has been canceled, using the following command:

    edgebuilder-cli script view -s <script_id>
    
    Expected output:
    INFO: Finding scripts: ["a0d043dc-7d99-4601-804e-1c18a0f8d1d9"]
    INFO: *** Script View Results ***
    +--------------------------------------------------+--------------------------------------+-----------+--------------------------------------+--------------------------------------+--------+
    | NAME                                             | ID                                   | STATUS    | SCRIPT_DEFINITION ID                 | NODE ID                              | LABELS |
    +--------------------------------------------------+--------------------------------------+-----------+--------------------------------------+--------------------------------------+--------+
    | LongRunning_a0d043dc-7d99-4601-804e-1c18a0f8d1d9 | a0d043dc-7d99-4601-804e-1c18a0f8d1d9 | Cancelled | 1dbf6db6-09ff-4de9-9942-424dee435400 | c355c48d-1cf1-492b-95d0-223a90d2d9ed |        |
    +--------------------------------------------------+--------------------------------------+-----------+--------------------------------------+--------------------------------------+--------+
    INFO: Viewing 1 result(s)
    

  8. To view the detailed results from the script run, you can use the following command:

    edgebuilder-cli script inspect -s <script_id>
    
    Expected output:
    {
      "CreatedBy": "iotech",
      "ID": "a0d043dc-7d99-4601-804e-1c18a0f8d1d9",
      "ModifiedBy": "iotech",
      "Name": "LongRunning_a0d043dc-7d99-4601-804e-1c18a0f8d1d9",
      "NodeID": "c355c48d-1cf1-492b-95d0-223a90d2d9ed",
      "ScriptDefinitionID": "1dbf6db6-09ff-4de9-9942-424dee435400",
      "Status": 5,
      "TimestampCreate": 1646683960,
      "TimestampModify": 1646684072
    }
    

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: Removal request for 1 node(s) accepted for processing by Edge Builder. Use 'node view' command to get updated status
    

  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
    WARN: 0 results to view