Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
---
title: How to run scripts on edge nodes | v3
description: >-
Install Azion CLI on Orchestrator edge nodes with a Shell Script resource, using Azion Console or API v3.
permalink: /documentation/guides/application-development/automation/run-scripts-v3/
meta_tags: >-
Azion CLI, Orchestrator Agent, install Azion, edge service configuration,
shell script resource, edge node setup, API guide for edge services, Edge
Computing, edge node authorization, Dpkg package manager
namespace: docs_deploy_run_scripts_edge_node_v3
---

import DocButton from '~/components/webkit/DocButton.vue';
import Tabs from '~/components/webkit/Tabs.vue'
import Code from '~/components/webkit/CodeBlock.vue'
import VersionDeprecated from '~/includes/snippets/versionDeprecated/en/snippet.mdx'

<VersionDeprecated>[How to run scripts on edge nodes](/en/documentation/guides/application-development/automation/run-scripts/)</VersionDeprecated>


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](/en/documentation/devtools/cli/) on your edge nodes through a resource of the type `Shell Script` configured on a specific edge service.

---

## Requirements

<Tabs client:visible sharedStore="interface">
<Fragment slot="tab.console">Console</Fragment>
<Fragment slot="tab.api">API</Fragment>

<Fragment slot="panel.console">

### Console

- An edge node with **Orchestrator Agent** installed and authorized.
- The Dpkg package manager installed on this node.

<DocButton href="/en/documentation/guides/application-development/automation/install-orchestrator-agent/" label="Go to how to install Orchestrator agent" kind="secondary" target="_blank" size="medium" />
<DocButton href="/en/documentation/guides/application-development/automation/authorize-an-edge-node-v3/" label="Go to how to authorize an edge node" kind="secondary" target="_blank" size="medium" />

:::note
You can find the download links to the respective architectures on [Azion CLI's releases page](https://github.com/aziontech/azion/releases). You must choose the correct download link based on the architecture of your edge node and replace the `BINARY_URL` in the script with the correct URL.
:::

</Fragment>

<Fragment slot="panel.api">

### API

- An edge node with **Orchestrator Agent** installed and authorized.
- The Dpkg package manager installed on this node.

<DocButton href="/en/documentation/guides/application-development/automation/install-orchestrator-agent/" label="Go to how to install Orchestrator agent" kind="secondary" target="_blank" size="medium" />
<DocButton href="/en/documentation/guides/application-development/automation/authorize-an-edge-node-v3/" label="Go to how to authorize an edge node" kind="secondary" target="_blank" size="medium" />

:::note
You can find the download links to the respective architectures on [Azion CLI's releases page](https://github.com/aziontech/azion/releases). You must choose the correct download link based on the architecture of your edge node and replace the `BINARY_URL` in the script with the correct URL.
:::

</Fragment>

</Tabs>

---

## Creating an edge service

<Tabs client:visible sharedStore="interface">

<Fragment slot="panel.console">

### Console

1. Access [Azion Console](https://console.azion.com/) > **Edge Services**.
2. Select **+ Service**.
3. Name this service `Azion CLI Installation`.
4. Enter the variables and values for the resource, if necessary.
5. Set the status as **Active**.
6. Select **Save**.
</Fragment>

<Fragment slot="panel.api">

### API

1. Run the following `POST` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/) and informing the name of the service being created:

```bash
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"
}'
```

2. Keep the ID of the edge service you've just created. You can access it in the response body, for example:

```json
{
"id": 1196,
"name": "Azion CLI Installation",
"updated_at": "2024-01-18T17:24:33Z",
"last_editor": "xxxxx",
"active": false,
"bound_nodes": 0,
"permissions": [
"read",
"write"
]
}
```

:::note
When running the request in the terminal, the response might not return formatted as presented on the example above.
:::

3. Run the following `PATCH` request in your terminal to set the service as active, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/):

```bash
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"
}
]
}'
```

:::note
If an edge service isn't set as active, it isn't available for binding to an edge node.
:::
</Fragment>

</Tabs>

---

## Creating a resource

<Tabs client:visible sharedStore="interface">

<Fragment slot="panel.console">

### Console

1. Inside the service you've just created, called `Azion CLI Installation`, go to the **Resources** tab.
2. Click on **+ Resource**.
3. Enter `/scripts/install-cli` in the **Path** field.
4. Choose the type **Shell Script**.
5. Choose the trigger **Install**.
6. Add the following content to the **Content** block:

<Code client:visible lang="bash" code={`
#!/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"
`} />

7. Click the **Save** button.

This script will install the Azion binary in the following path: `/usr/local/bin`
</Fragment>

<Fragment slot="panel.api">

### API

1. Run the following `POST` request in your terminal:

<Code client:visible lang="bash" code={`
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](/en/documentation/guides/platform/account-and-billing/personal-tokens/), `:id` with the ID of the edge service and inform the following parameters in the request body:

| Property | Description | Required |
| - | - | - |
| `content_type` | Content type of the resource being created | Yes |
| `name` | Name of the resource being created | Yes |
| `content` | Content that defines actions performed when the resource state changes in the edge node | Yes |
</Fragment>

</Tabs>

---

## Binding an edge service to an edge node

<Tabs client:visible sharedStore="interface">

<Fragment slot="panel.console">

### Console

1. Go to **Edge Nodes**.
2. Select the edge node to which you want to bind a service.
3. Go to the **Services** tab and click the **+ Service** button.
4. Choose the service `Azion CLI Installation` you've created.
5. Click the **Save** button.
</Fragment>

<Fragment slot="panel.api">

### API

1. Run the following `GET` request in your terminal, replacing `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/) and retrieve the edge node ID you wish to bind to an edge service:

<Code client:visible lang="bash" code={`
curl --location 'https://api.azionapi.net/edge_nodes/' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]'
`} />

2. Run the following `POST` request in your terminal:

```bash
curl --location 'https://api.azionapi.net/edge_nodes/:node_id/services' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]' \
--header 'Content-Type: application/json' \
--data '{
"service_id": 1196,
"variables": [
{
"name": "string",
"value": "string"
}
]
}'
```

Replace `[TOKEN VALUE]` with your [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/), `:node_id` with the ID of the edge node, and `1196` in the request body with the ID of the edge service you kept when you created it:

| Property | Description | Required |
| - | - | - |
| `service_id` | ID of the edge service being bound to the edge node, as a number | Yes |
| `variables` | Variables to be replaced during the processing on the edge node | No |
</Fragment>

</Tabs>

---

## Accessing Azion CLI

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

```bash
cd /usr/local/bin
```

Run:

```bash
./azion -h
```

The output will be similar to:

```text
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
...
```

:::tip
Check the [Azion API documentation](https://api.azion.com/v3) and the [OpenAPI specification](https://github.com/aziontech/azionapi-openapi/) to know more about all features available via API.
:::
Loading
Loading