How to run scripts on edge nodes

To be able to orchestrate services on your device, you must configure all the resources needed to install, uninstall, and reload your services.

This guide presents how to install Azion CLI on your edge nodes through a resource of the type Shell Script configured on a specific edge service.


  • An edge node with Edge Orchestrator Agent installed and authorized.
  • The Dpkg package manager installed on this node.
go to how to install edge orchestrator agent
go to how to authorize an edge node
  1. Go to Azion Console > Edge Libraries > Edge Services.
  2. Click on the Add Service button.
  3. Name this service Azion CLI Installation.
  4. Click the Save button.
  5. On the list of services, set the status as active.
  1. On the upper-left corner of the page, open the Products menu, represented by three horizontal lines, and then select Edge Libraries > Edge Services.
  2. Select the edge service you’ve just created, called Azion CLI Installation.
  3. Go to the Resources tab.
  4. Click on Add Resource.
  5. Enter /scripts/install-cli/ in the filepath field.
  6. Choose the type Shell Script.
  7. Choose the trigger Install.
  8. Add the following content to the content block:
#!/bin/bash
# Define the URL of the binary to download
BINARY_URL="https://github.com/aziontech/azion/releases/download/1.10.2/azion_1.10.2_linux_arm64.deb"
# Download the binary
wget $BINARY_URL -O /tmp/azion.deb
# Install the binary
# This assumes that you have dpkg installed on your system
sudo dpkg -i /tmp/azion.deb
# Clean up the downloaded binary
rm /tmp/azion.deb
echo "Installation completed successfully"
  1. Click the Save button.

This script will install the Azion binary in the following path: /usr/local/bin

Binding an edge service to an edge node

Section titled Binding an edge service to an edge node
  1. On the upper-left corner of the page, open the Products menu, represented by three horizontal lines, and then select Edge Nodes.
  2. Select the edge node you want to bind to a service.
  3. Go to the Services tab.
  4. Choose the service.
  5. Click the Save button.

  1. Run the following POST request in your terminal, replacing [TOKEN VALUE] with your personal token and informing the name of the service being created:
Terminal window
curl --location 'https://api.azionapi.net/edge_services/' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
"name": "Azion CLI Installation"
}'
  1. Keep the ID of the edge service you’ve just created. You can access it in the response body, for example:
{
"id": 1196,
"name": "Azion CLI Installation",
"updated_at": "2024-01-18T17:24:33Z",
"last_editor": "xxxxx",
"active": false,
"bound_nodes": 0,
"permissions": [
"read",
"write"
]
}
  1. Run the following PATCH request in your terminal to set the service as active, replacing [TOKEN VALUE] with your personal token:
Terminal window
curl --location --request PATCH 'https://api.azionapi.net/edge_services/:id' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
"active": true,
"name": "Azion CLI Installation",
"variables": [
{
"name": "string",
"value": "string"
}
]
}'
  1. Run the following POST request in your terminal:
Terminal window
curl --location 'https://api.azionapi.net/edge_services/:id/resources' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
"content_type": "Shell Script",
"name": "/scripts/install-cli/",
"content": "#!/bin/bash\n\n# Define the URL of the binary to download\nBINARY_URL=\"https://github.com/aziontech/azion/releases/download/1.10.2/azion_1.10.2_linux_arm64.deb\"\n\n# Download the binary\nwget $BINARY_URL -O /tmp/azion.deb\n\n# Install the binary\n# This assumes that you have dpkg installed on your system\nsudo dpkg -i /tmp/azion.deb\n\n# Clean up the downloaded binary\nrm /tmp/azion.deb\n\necho \"Installation completed successfully\""
}'

Replace [TOKEN VALUE] with your personal token, :id with the ID of the edge service and inform the following parameters in the request body:

PropertyDescriptionRequired
content_typeContent type of the resource being createdYes
nameName of the resource being createdYes
contentContent that defines actions performed when the resource state changes in the edge nodeYes

Binding an edge service to an edge node

Section titled Binding an edge service to an edge node
  1. Run the following GET request in your terminal, replacing [TOKEN VALUE] with your personal token and retrieve the edge node ID you wish to bind to an edge service:
Terminal window
curl --location 'https://api.azionapi.net/edge_nodes/' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]'
  1. Run the following POST request in your terminal:
Terminal window
curl --location 'https://api.azionapi.net/edge_nodes/:id/services' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
"service_id": :id,
"variables": [
{
"name": "string",
"value": "string"
}
]
}'

Replace [TOKEN VALUE] with your personal token, :id with the ID of the edge node and inform the ID of the service in the request body:

PropertyDescriptionRequired
service_idID of the edge service being bound to the edge nodeYes
variablesVariables to be replaced during the processing on the edge nodeNo (requires checking)

After this process, in your edge node, access the folder:

Terminal window
cd /usr/local/bin

Run:

Terminal window
./azion -h

The output will be similar to:

Terminal window
Azion CLI 1.10.2
DESCRIPTION
The Azion Command Line Interface is a unified tool to manage your Azion projects and resources
SYNOPSIS
azion <command> <subcommand> [flags]
EXAMPLES
$ azion
$ azion -t azionb43a9554776zeg05b11cb1declkbabcc9la
$ azion --debug
$ azion -h
...

Contributors