2018-10-16 13:09:16 +00:00
# Interacting with the balena Supervisor
2016-03-31 12:50:19 +00:00
2018-10-16 13:09:16 +00:00
The balena Supervisor is balena's agent that runs on devices. Its main role is to ensure your app is running, and keep communications with the balenaCloud API server.
2016-03-31 12:50:19 +00:00
2021-08-09 20:55:06 +00:00
The Supervisor itself has its own set of APIs providing means for services to communicate and execute some special actions that affect the host OS or the services itself. There are two main ways for the services to interact with the Supervisor:
2020-07-27 15:11:48 +00:00
- Update lockfile
- HTTP API
2016-03-31 12:50:19 +00:00
2020-07-27 15:11:48 +00:00
Only Supervisors after version `1.1.0` have this functionality, and some of the endpoints appeared in later versions (we've noted it down where this is the case). Supervisor version `1.1.0` corresponds to OS images downloaded after October 14th, 2015.
2016-03-31 12:50:19 +00:00
2015-10-13 21:18:27 +00:00
## HTTP API reference
2018-11-13 16:46:19 +00:00
**Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_` , e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS` .
2020-07-27 15:11:48 +00:00
The supervisor exposes an HTTP API on port `48484` (`BALENA_SUPERVISOR_PORT`).
2015-10-13 21:18:27 +00:00
2018-12-04 16:38:26 +00:00
To enable these Supervisor environment variables, the `io.balena.features.supervisor-api` label must be applied for each service that requires them. See [here ](https://www.balena.io/docs/learn/develop/multicontainer/#labels ) for further details.
2021-08-09 20:55:06 +00:00
> Note: All endpoints (except /ping) requires an apikey parameter, which is exposed to the services as `BALENA_SUPERVISOR_API_KEY`.
2015-10-13 21:18:27 +00:00
2020-10-30 22:41:20 +00:00
The full address for the API, i.e. `"http://127.0.0.1:48484"` , is available as `BALENA_SUPERVISOR_ADDRESS` .
2020-07-27 15:11:48 +00:00
> Note: Always use `BALENA_*` variables when communicating via the API, since address and port could change.
2015-10-13 21:18:27 +00:00
2021-08-09 20:55:06 +00:00
Alternatively, the balena API (api.balena-cloud.com) has a proxy endpoint at `POST /supervisor/<url>` (where `<url>` is one of the API URLs described below) from which you can send API commands to the supervisor remotely, using your Auth Token instead of your API key. Commands sent through the proxy can specify either an `appId` to send the request to all devices in a fleet, or a `deviceId` or `uuid` to send to a particular device. These requests default to POST unless you specify a `method` parameter (e.g. "GET"). In the examples below, we show how to use a uuid to specify a device, but in any of those you can replace `uuid` for a `deviceId` or `appId` .
2015-10-13 21:18:27 +00:00
The API is versioned (currently at v1), except for `/ping` .
2018-03-16 14:01:50 +00:00
You might notice that the formats of some responses differ. This is because they were implemented later, and in Go instead of node.js - even if the Go pieces were later removed, so we kept the response format for backwards compatibility.
2015-10-13 21:18:27 +00:00
Here's the full list of endpoints implemented so far. In all examples, replace everything between `< >` for the corresponding values.
< hr >
### GET /ping
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2015-10-13 21:18:27 +00:00
Responds with a simple "OK", signaling that the supervisor is alive and well.
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2015-10-13 21:18:27 +00:00
```bash
$ curl -X GET --header "Content-Type:application/json" \
2020-07-27 15:11:48 +00:00
"$BALENA_SUPERVISOR_ADDRESS/ping"
2015-10-13 21:18:27 +00:00
```
Response:
```none
OK
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > ", "method": "GET"}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/ping"
2015-10-13 21:18:27 +00:00
```
< hr >
### POST /v1/blink
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2015-10-13 21:18:27 +00:00
Starts a blink pattern on a LED for 15 seconds, if your device has one.
Responds with an empty 200 response. It implements the "identify device" feature from the dashboard.
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2015-10-13 21:18:27 +00:00
```bash
$ curl -X POST --header "Content-Type:application/json" \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/blink?apikey=$BALENA_SUPERVISOR_API_KEY"
2015-10-13 21:18:27 +00:00
```
(Empty response)
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > "}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/blink"
2015-10-13 21:18:27 +00:00
```
< hr >
### POST /v1/update
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2021-12-28 18:58:11 +00:00
Triggers a check for the target state of configurations and app services. Optionally, if a new target is available, the `force` option tells the supervisor to ignore locks and install the update. This will NOT update the supervisor service.
2015-10-13 21:18:27 +00:00
2017-07-10 13:31:50 +00:00
Responds with an empty 204 (No Content) response.
2015-10-13 21:18:27 +00:00
#### Request body
Can be a JSON object with a `force` property. If this property is true, the update lock will be overridden.
```json
{
"force": true
}
```
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2015-10-13 21:18:27 +00:00
```bash
$ curl -X POST --header "Content-Type:application/json" \
--data '{"force": true}' \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/update?apikey=$BALENA_SUPERVISOR_API_KEY"
2015-10-13 21:18:27 +00:00
```
(Empty response)
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > ", "data": {"force": true}}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/update"
2015-10-13 21:18:27 +00:00
```
< hr >
### POST /v1/reboot
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2021-08-09 20:55:06 +00:00
Reboots the device. This will first try to stop running services, and fail if there is an update lock.
2018-03-15 20:17:29 +00:00
An optional "force" parameter in the body overrides the lock when true (and the lock can also be overridden from
the dashboard).
2015-10-13 21:18:27 +00:00
2017-07-10 13:31:50 +00:00
When successful, responds with 202 accepted and a JSON object:
2015-10-13 21:18:27 +00:00
```json
{
"Data": "OK",
"Error": ""
}
```
2018-03-15 20:17:29 +00:00
#### Request body
Can contain a `force` property, which if set to `true` will cause the update lock to be overridden.
2015-10-13 21:18:27 +00:00
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2015-10-13 21:18:27 +00:00
```bash
$ curl -X POST --header "Content-Type:application/json" \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/reboot?apikey=$BALENA_SUPERVISOR_API_KEY"
2015-10-13 21:18:27 +00:00
```
Response:
```json
2021-05-17 06:14:37 +00:00
{
"Data": "OK",
"Error": ""
}
2015-10-13 21:18:27 +00:00
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > "}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/reboot"
2015-10-13 21:18:27 +00:00
```
< hr >
### POST /v1/shutdown
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2021-08-09 20:55:06 +00:00
> **Dangerous**: Shuts down the device. This will first try to stop services, and fail if there is an update lock.
2021-05-17 06:14:37 +00:00
An optional "force" parameter in the body overrides the lock when true (and the lock can also be overridden from the dashboard).
2015-10-13 21:18:27 +00:00
2017-07-10 13:31:50 +00:00
When successful, responds with 202 accepted and a JSON object:
2015-10-13 21:18:27 +00:00
```json
{
"Data": "OK",
"Error": ""
}
```
2018-03-15 20:17:29 +00:00
#### Request body
Can contain a `force` property, which if set to `true` will cause the update lock to be overridden.
2015-10-13 21:18:27 +00:00
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2015-10-13 21:18:27 +00:00
```bash
$ curl -X POST --header "Content-Type:application/json" \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/shutdown?apikey=$BALENA_SUPERVISOR_API_KEY"
2015-10-13 21:18:27 +00:00
```
Response:
```json
2021-05-17 06:14:37 +00:00
{
"Data": "OK",
"Error": ""
}
2015-10-13 21:18:27 +00:00
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > "}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/shutdown"
2015-10-13 21:18:27 +00:00
```
< hr >
### POST /v1/purge
2021-05-25 10:24:13 +00:00
> **Note:** This route will remove and recreate all service containers, as volumes can only be removed when their associated containers are removed. On devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2021-11-12 10:13:20 +00:00
Clears the device's `/data` folder and named volumes if any.
2015-10-13 21:18:27 +00:00
When successful, responds with 200 and a JSON object:
```json
{
"Data": "OK",
"Error": ""
}
```
#### Request body
2021-08-09 20:55:06 +00:00
Has to be a JSON object with an `appId` property, corresponding to the ID of the fleet the device is running. Example:
2015-10-13 21:18:27 +00:00
```json
{
"appId": 2167
}
```
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container::
2015-10-13 21:18:27 +00:00
```bash
$ curl -X POST --header "Content-Type:application/json" \
--data '{"appId": < appId > }' \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/purge?apikey=$BALENA_SUPERVISOR_API_KEY"
2015-10-13 21:18:27 +00:00
```
Response:
2021-05-17 06:14:37 +00:00
```json
{
"Data": "OK",
"Error": ""
}
2015-10-13 21:18:27 +00:00
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > ", "data": {"appId": < appId > }}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/purge"
2015-10-13 21:18:27 +00:00
```
< hr >
### POST /v1/restart
2021-08-09 20:55:06 +00:00
> **Note:** This route will remove and recreate all service containers. See [the restart action](https://www.balena.io/docs/learn/manage/actions/#restart-fleet) for more information. On devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2021-08-09 20:55:06 +00:00
Restarts a service.
2015-10-13 21:18:27 +00:00
2016-04-08 19:51:39 +00:00
When successful, responds with 200 and an "OK"
2015-10-13 21:18:27 +00:00
#### Request body
2021-08-09 20:55:06 +00:00
Has to be a JSON object with an `appId` property, corresponding to the ID of the fleet the device is running.
2015-10-13 21:18:27 +00:00
Example:
```json
{
"appId": 2167
}
```
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2015-10-13 21:18:27 +00:00
```bash
$ curl -X POST --header "Content-Type:application/json" \
--data '{"appId": < appId > }' \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/restart?apikey=$BALENA_SUPERVISOR_API_KEY"
2015-10-13 21:18:27 +00:00
```
Response:
```none
OK
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > ", "data": {"appId": < appId > }}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/restart"
2015-10-13 21:18:27 +00:00
```
### POST /v1/regenerate-api-key
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2022-12-14 02:46:29 +00:00
Invalidates the current `BALENA_SUPERVISOR_API_KEY` and generates a new one. Responds with the new API key, but **the containers will be restarted on the next update cycle** to update the API key environment variable.
2015-10-13 21:18:27 +00:00
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2015-10-13 21:18:27 +00:00
```bash
$ curl -X POST --header "Content-Type:application/json" \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/regenerate-api-key?apikey=$BALENA_SUPERVISOR_API_KEY"
2015-10-13 21:18:27 +00:00
```
Response:
```none
480af7bb8a9cf56de8a1e295f0d50e6b3bb46676aaddbf4103aa43cb57039364
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > "}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/regenerate-api-key"
2015-10-13 21:18:27 +00:00
```
2016-02-15 20:34:11 +00:00
< hr >
### GET /v1/device
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v1.6.**
> **Note:** On devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2018-10-16 13:09:16 +00:00
Returns the current device state, as reported to the balenaCloud API and with some extra fields added to allow control over pending/locked updates.
2016-02-15 20:34:11 +00:00
The state is a JSON object that contains some or all of the following:
* `api_port` : Port on which the supervisor is listening.
2021-08-09 20:55:06 +00:00
* `commit` : Hash of the current commit of the release that is running on the fleet.
2016-02-15 20:34:11 +00:00
* `ip_address` : Space-separated list of IP addresses of the device.
2021-03-17 18:26:46 +00:00
* `mac_address` : Space-separated list of MAC addresses of the device.
2016-02-15 20:34:11 +00:00
* `status` : Status of the device regarding the app, as a string, i.e. "Stopping", "Starting", "Downloading", "Installing", "Idle".
2021-08-09 20:55:06 +00:00
* `download_progress` : Amount of the release that has been downloaded, expressed as a percentage. If the update has already been downloaded, this will be `null` .
2016-02-15 20:34:11 +00:00
* `os_version` : Version of the host OS running on the device.
* `supervisor_version` : Version of the supervisor running on the device.
2020-10-30 22:41:20 +00:00
* `update_pending` : This one is not reported to the balenaCloud API. It's a boolean that will be true while the Supervisor is checking for updates (such as on boot or every poll interval) or if the supervisor has finally concluded there is an update.
2018-10-16 13:09:16 +00:00
* `update_downloaded` : Not reported to the balenaCloud API either. Boolean that will be true if a pending update has already been downloaded.
* `update_failed` : Not reported to the balenaCloud API. Boolean that will be true if the supervisor has tried to apply a pending update but failed (i.e. if the app was locked, there was a network failure or anything else went wrong).
2016-02-15 20:34:11 +00:00
Other attributes may be added in the future, and some may be missing or null if they haven't been set yet.
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2016-02-15 20:34:11 +00:00
```bash
$ curl -X GET --header "Content-Type:application/json" \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/device?apikey=$BALENA_SUPERVISOR_API_KEY"
2016-02-15 20:34:11 +00:00
```
Response:
```json
2021-05-17 06:14:37 +00:00
{
"api_port":48484,
"ip_address":"192.168.0.114 10.42.0.3",
"commit":"414e65cd378a69a96f403b75f14b40b55856f860",
"status":"Downloading",
"download_progress":84,
"os_version":"Resin OS 1.0.4 (fido)",
"supervisor_version":"1.6.0",
"update_pending":true,
"update_downloaded":false,
"update_failed":false
}
2016-02-15 20:34:11 +00:00
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > ", "method": "GET"}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/device"
2016-02-15 20:34:11 +00:00
```
2016-04-08 19:51:39 +00:00
< hr >
2016-04-16 16:52:38 +00:00
### POST /v1/apps/:appId/stop
2016-04-08 19:51:39 +00:00
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v1.8**
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2021-08-09 20:55:06 +00:00
Temporarily stops a service. A reboot or supervisor restart will cause the container to start again.
2016-04-08 19:51:39 +00:00
The container is not removed with this endpoint.
2021-03-08 10:01:00 +00:00
This is only supported on single-container devices, and will return 400 on devices running multiple containers. Refer to v2 endpoint, [`/v2/applications/:appId/stop-service` ](#post-v2applicationsappidstop-service ) for running the query on multiple containers.
2018-05-11 15:36:10 +00:00
2016-04-20 12:49:22 +00:00
When successful, responds with 200 and the Id of the stopped container.
2016-04-08 19:51:39 +00:00
2016-04-16 16:52:38 +00:00
The appId must be specified in the URL.
2016-04-08 19:51:39 +00:00
2016-04-16 16:52:38 +00:00
#### Request body
Can contain a `force` property, which if set to `true` will cause the update lock to be overridden.
2016-04-08 19:51:39 +00:00
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2016-04-08 19:51:39 +00:00
```bash
$ curl -X POST --header "Content-Type:application/json" \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/apps/< appId > /stop?apikey=$BALENA_SUPERVISOR_API_KEY"
2016-04-08 19:51:39 +00:00
```
Response:
2016-04-20 12:49:22 +00:00
```json
2021-05-17 06:14:37 +00:00
{
"containerId":"5f4d4a857742e9ecac505ba5710834d3852ad7d71e10389fc6f61d8655a21806"
}
2016-04-08 19:51:39 +00:00
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > "}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/apps/< appId > /stop"
2016-04-08 19:51:39 +00:00
```
< hr >
2016-04-20 14:56:02 +00:00
### POST /v1/apps/:appId/start
2016-04-08 19:51:39 +00:00
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v1.8**
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2021-08-09 20:55:06 +00:00
Starts a service, usually after it has been stopped with `/v1/stop` .
2016-04-08 19:51:39 +00:00
2021-03-08 10:01:00 +00:00
This is only supported on single-container devices, and will return 400 on devices running multiple containers. Refer to v2 endpoint, [`/v2/applications/:appId/start-service` ](#post-v2applicationsappidstart-service ) for running the query on multiple containers.
2018-05-11 15:36:10 +00:00
2016-04-20 12:49:22 +00:00
When successful, responds with 200 and the Id of the started container.
2016-04-08 19:51:39 +00:00
2016-04-16 16:52:38 +00:00
The appId must be specified in the URL.
2016-04-08 19:51:39 +00:00
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2016-04-08 19:51:39 +00:00
```bash
$ curl -X POST --header "Content-Type:application/json" \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/apps/< appId > /start?apikey=$BALENA_SUPERVISOR_API_KEY"
2016-04-08 19:51:39 +00:00
```
Response:
2016-04-20 12:49:22 +00:00
```json
2021-05-17 06:14:37 +00:00
{
"containerId":"6d9e1efdb9aad90fdb2df911f785b6aa00270e9448e75226a9a7361c8a9500cf"
}
2016-04-08 19:51:39 +00:00
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > "}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/apps/< appId > /start"
2016-04-16 16:52:38 +00:00
```
< hr >
### GET /v1/apps/:appId
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v1.8**
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2021-08-09 20:55:06 +00:00
Returns the services running on the device
2016-04-16 16:52:38 +00:00
The app is a JSON object that contains the following:
2021-08-09 20:55:06 +00:00
* `appId` : The id of the fleet as per the balenaCloud API.
* `commit` : Release commit that is running.
* `imageId` : The docker image of the current build.
2016-04-16 16:52:38 +00:00
* `containerId` : ID of the docker container of the running app.
* `env` : A key-value store of the app's environment variables.
The appId must be specified in the URL.
2021-03-08 10:01:00 +00:00
This is only supported on single-container devices, and will return 400 on devices running multiple containers. Refer to v2 endpoint, [`/v2/applications/:appId/state` ](#get-v2applicationsappidstate ) for running the query on multiple containers.
2018-05-11 15:36:10 +00:00
2016-04-16 16:52:38 +00:00
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2016-04-16 16:52:38 +00:00
```bash
$ curl -X GET --header "Content-Type:application/json" \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/apps/< appId > ?apikey=$BALENA_SUPERVISOR_API_KEY"
2016-04-16 16:52:38 +00:00
```
Response:
```json
2021-05-17 06:14:37 +00:00
{
"appId": 3134,
"commit":"414e65cd378a69a96f403b75f14b40b55856f860",
"imageId":"registry.balena-cloud.com/superapp/414e65cd378a69a96f403b75f14b40b55856f860",
"containerId":"e5c1eace8b4e",
"env":{
"FOO":"bar"
}
}
2016-04-16 16:52:38 +00:00
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > ", "method": "GET"}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/apps/< appId > "
2016-04-16 16:52:38 +00:00
```
2017-11-29 22:38:18 +00:00
< hr >
### GET /v1/healthy
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v6.5**
2018-11-13 16:46:19 +00:00
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2017-11-29 22:38:18 +00:00
2020-07-27 15:11:48 +00:00
Used **internally** to check whether the supervisor is running correctly, according to some heuristics that help determine
2021-08-09 20:55:06 +00:00
whether the internal components, release updates and reporting to the balenaCloud API are functioning.
2017-11-29 22:38:18 +00:00
Responds with an empty 200 response if the supervisor is healthy, or a 500 status code if something is not working
correctly.
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2017-11-29 22:38:18 +00:00
```bash
2018-10-16 13:09:16 +00:00
$ curl "$BALENA_SUPERVISOR_ADDRESS/v1/healthy"
2017-11-29 22:38:18 +00:00
```
(Empty response)
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > ", "method": "GET"}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/healthy"
2017-11-29 22:38:18 +00:00
```
2018-01-17 18:04:36 +00:00
< hr >
### PATCH /v1/device/host-config
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v6.6**
2018-11-13 16:46:19 +00:00
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-01-17 18:04:36 +00:00
2022-02-09 03:05:40 +00:00
This endpoint allows setting some configuration values for the host OS. Currently it supports proxy and hostname configuration.
2018-01-17 18:04:36 +00:00
2021-08-09 20:55:06 +00:00
For proxy configuration, balenaOS 2.0.7 and higher provides a transparent proxy redirector (redsocks) that makes all connections be routed to a SOCKS or HTTP proxy. This endpoint allows services to modify these proxy settings at runtime.
2018-01-17 18:04:36 +00:00
#### Request body
2022-02-09 03:05:40 +00:00
A JSON object with several optional fields. Proxy and hostname configuration go under a `network` key. If `proxy` or `hostname` are not present (undefined), those values will not be modified, so that a request can modify hostname without changing proxy settings and vice versa.
By default, with [balenaOS 2.82.6 ](https://github.com/balena-os/meta-balena/blob/master/CHANGELOG.md#v2826 ) or newer, host config PATCH requests will cause a balenaEngine restart. Therefore, with Supervisor v12.11.34 and newer, the PATCH request will respect the presence of update locks. Specify the `force` boolean (`false` by default) property in the request body to ignore this.
2018-01-17 18:04:36 +00:00
```json
{
"network": {
"proxy": {
"type": "http-connect",
"ip": "myproxy.example.com",
"port": 8123,
"login": "username",
"password": "password",
"noProxy": [ "152.10.30.4", "253.1.1.0/16" ]
},
2022-02-09 03:05:40 +00:00
"hostname": "mynewhostname",
"force": true
2018-01-17 18:04:36 +00:00
}
}
```
In the proxy settings, `type` , `ip` , `port` , `login` and `password` are the settings for the proxy redirector to
be able to connnect to the proxy, based on how [redsocks.conf ](https://github.com/darkk/redsocks/blob/master/redsocks.conf.example ) works. `type` can be `socks4` , `socks5` , `http-connect` or `http-relay` (not all proxies are
2018-10-16 13:09:16 +00:00
guaranteed to work, especially if they block connections that the balena services may require).
2018-01-17 18:04:36 +00:00
2018-10-16 13:09:16 +00:00
Keep in mind that, even if transparent proxy redirection will take effect immediately after the API call (i.e. all new connections will go through the proxy), open connections will not be closed. So, if for example, the device has managed to connect to the balenaCloud VPN without the proxy, it will stay connected directly without trying to reconnect through the proxy, unless the connection breaks - any reconnection attempts will then go through the proxy. To force *all* connections to go through the proxy, the best way is to reboot the device (see the /v1/reboot endpoint). In most networks were no connections to the Internet can be made if not through a proxy, this should not be necessary (as there will be no open connections before configuring the proxy settings).
2018-01-18 22:07:00 +00:00
2022-02-09 03:05:40 +00:00
The `noProxy` setting for the proxy is an optional array of IP addresses/subnets that should not be routed through the
2021-08-26 13:22:55 +00:00
proxy. Keep in mind that local/reserved subnets are already [excluded by balenaOS automatically ](https://github.com/balena-os/meta-balena/blob/master/meta-balena-common/recipes-connectivity/balena-proxy-config/balena-proxy-config/balena-proxy-config ).
2018-01-17 18:04:36 +00:00
2022-02-09 03:05:40 +00:00
If either `proxy` or `hostname` are null or empty values (i.e. `{}` for proxy or an empty string for hostname), they will be cleared to their default values (i.e. not using a proxy, and a hostname equal to the first 7 characters of the device's uuid, respectively).
2018-01-17 18:04:36 +00:00
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2018-01-17 18:04:36 +00:00
```bash
$ curl -X PATCH --header "Content-Type:application/json" \
--data '{"network": {"hostname": "newhostname"}}' \
2018-10-16 13:09:16 +00:00
"$BALENA_SUPERVISOR_ADDRESS/v1/device/host-config?apikey=$BALENA_SUPERVISOR_API_KEY"
2018-01-17 18:04:36 +00:00
```
Response:
```none
OK
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > ", "method": "PATCH", "data": {"network": {"hostname": "newhostname"}}}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/device/host-config"
2018-01-17 18:04:36 +00:00
```
< hr >
### GET /v1/device/host-config
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v6.6**
2018-11-13 16:46:19 +00:00
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-01-17 18:04:36 +00:00
This endpoint allows reading some configuration values for the host OS, previously set with `PATCH /v1/device/host-config` . Currently it supports
proxy and hostname configuration.
Please refer to the PATCH endpoint above for details on the behavior and meaning of the fields in the response.
#### Examples:
2021-11-12 10:13:20 +00:00
From an app container:
2018-01-17 18:04:36 +00:00
```bash
2018-10-16 13:09:16 +00:00
$ curl "$BALENA_SUPERVISOR_ADDRESS/v1/device/host-config?apikey=$BALENA_SUPERVISOR_API_KEY"
2018-01-17 18:04:36 +00:00
```
Response:
```json
2021-05-17 06:14:37 +00:00
{
"network":{
"proxy":{
"ip":"192.168.0.199",
"port":"8123",
"type":"socks5"
},
"hostname":"27b0fdc"
}
}
2018-01-17 18:04:36 +00:00
```
Remotely via the API proxy:
```bash
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer < auth token > " \
2021-05-17 06:14:37 +00:00
--data '{"uuid": "< uuid > ", "method": "GET"}' \
2018-10-16 13:09:16 +00:00
"https://api.balena-cloud.com/supervisor/v1/device/host-config"
2018-01-17 18:04:36 +00:00
```
2018-08-07 12:42:55 +00:00
### GET /v2/applications/state
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v7.12**
2018-11-13 16:46:19 +00:00
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-08-07 12:42:55 +00:00
2021-08-09 20:55:06 +00:00
Get a list of fleets, services and their statuses. This will reflect the current state of the supervisor, and not the target state.
2018-08-07 12:42:55 +00:00
2021-11-12 10:13:20 +00:00
From an app container:
2018-08-07 12:42:55 +00:00
```bash
2018-10-16 13:09:16 +00:00
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/applications/state?apikey=$BALENA_SUPERVISOR_API_KEY"
2018-08-07 12:42:55 +00:00
```
Response:
```json
{
"appname": {
"appId": 1011165,
"commit": "217d55237092995e4576367e529ebb03",
"services": {
"main": {
"status": "Downloaded",
"releaseId": 557617,
"downloadProgress": null
},
"frontend": {
"status": "Downloading",
"releaseId": 557631,
"downloadProgress": 0
},
"proxy": {
"status": "Downloaded",
"releaseId": 557631,
"downloadProgress": null
},
"data": {
"status": "Downloading",
"releaseId": 557631,
"downloadProgress": 7
},
"metrics": {
"status": "Downloading",
"releaseId": 557631,
"downloadProgress": 35
}
}
}
}
```
2018-10-22 14:05:38 +00:00
2018-10-12 13:42:58 +00:00
Remotely via the API proxy:
```bash
curl -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer < auth token > ' \
-d '{"uuid": "< uuid > ", "method": "GET"}' \
2019-05-02 13:01:48 +00:00
"https://api.balena-cloud.com/supervisor/v2/applications/state"
2018-10-12 13:42:58 +00:00
```
2018-10-22 14:05:38 +00:00
### GET /v2/applications/:appId/state
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v7.12**
2018-11-13 16:46:19 +00:00
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-10-22 14:05:38 +00:00
2021-08-09 20:55:06 +00:00
Use this endpoint to get the state of a single fleet, given the appId.
2018-10-22 14:05:38 +00:00
2021-11-12 10:13:20 +00:00
From an app container:
2018-10-22 14:05:38 +00:00
```bash
2019-07-24 22:30:06 +00:00
curl "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/state?apikey=$BALENA_SUPERVISOR_API_KEY"
2018-10-22 14:05:38 +00:00
```
Response:
```json
{
"local": {
"1234": {
"services": {
"5678": {
"status": "Running",
"releaseId": 99999,
"download_progress": null
}
}
}
},
"commit": "7fc9c5bea8e361acd49886fe6cc1e1cd"
}
```
2019-03-11 16:24:44 +00:00
### GET /v2/state/status
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v9.7**
2019-03-11 16:24:44 +00:00
This will return a list of images, containers, the overall download progress and the status of the state engine.
2022-04-18 19:11:54 +00:00
> **Note:** The `status` field in the JSON response does not indicate the status of the device itself, but rather the status of the HTTP response. To get an accurate representation of whether the device state has settled, use the `appState` field. `appState` will be one of `applying` or `applied`.
2021-11-12 10:13:20 +00:00
From an app container:
2019-03-11 16:24:44 +00:00
```bash
2019-05-02 13:01:48 +00:00
curl "$BALENA_SUPERVISOR_ADDRESS/v2/state/status?apikey=$BALENA_SUPERVISOR_API_KEY"
2019-03-11 16:24:44 +00:00
```
Response:
```json
{
"status": "success",
"appState": "applied",
"overallDownloadProgress": null,
"containers": [
{
"status": "Running",
"serviceName": "main",
"appId": 1032480,
"imageId": 959262,
"serviceId": 29396,
"containerId": "be4a860e34ffca609866f8af3596e9ee7b869e1e0bb9f51406d0b120b0a81cdd",
"createdAt": "2019-03-11T16:05:34.506Z"
}
],
"images": [
{
"name": "registry2.balena-cloud.com/v2/fbf67cf6574fb0f8da3c8998226fde9e@sha256:9e328a53813e3c2337393c63cfd6c2f5294872cf0d03dc9f74d02e66b9ca1221",
"appId": 1032480,
"serviceName": "main",
"imageId": 959262,
"dockerImageId": "sha256:2662fc0ca0c7dd0f549e87e224f454165f260ff54aac59308d2641d99ca95e58",
"status": "Downloaded",
"downloadProgress": null
}
],
"release": "804281fb17e8291c542f9640814ef546"
}
```
2018-10-22 14:05:38 +00:00
### Service Actions
2021-08-09 20:55:06 +00:00
#### The Fleet ID
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2021-08-09 20:55:06 +00:00
For the following endpoints the fleet ID is required in the url. The fleet ID is exposed as `BALENA_APP_ID` inside your container. Otherwise, you can use the following snippet to determine the fleet ID programmatically:
2018-10-22 14:05:38 +00:00
```bash
APPNAME="supervisortest"
2019-07-24 22:30:06 +00:00
BALENA_APP_ID=$(curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/state?apikey=$BALENA_SUPERVISOR_API_KEY" | jq ".$APPNAME.appId")
2018-10-22 14:05:38 +00:00
```
2021-08-09 20:55:06 +00:00
The easiest way to find your fleet from the dashboard is to look at the url when on the device list.
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
### POST /v2/applications/:appId/restart-service
2018-10-22 14:05:38 +00:00
2021-05-25 10:24:13 +00:00
> **Note:** This route will remove and recreate the specified service container. See [the restart action](https://www.balena.io/docs/learn/manage/actions/#restart-application) for more information. On devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2018-10-22 14:05:38 +00:00
Added in supervisor version v7.0.0. Support for passing `serviceName` instead of
`imageId` added in v8.2.2.
2021-08-09 20:55:06 +00:00
Use this endpoint to restart a service in the fleet with fleet id passed in with the url.
2018-10-22 14:05:38 +00:00
2021-11-12 10:13:20 +00:00
From an app container:
2018-10-22 14:05:38 +00:00
```bash
2019-07-24 22:30:06 +00:00
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'
2018-10-22 14:05:38 +00:00
```
Response:
```
OK
```
This endpoint can also take an extra optional boolean, `force` , which if true informs the supervisor to ignore any update locks which have been taken.
2021-03-08 10:01:00 +00:00
### POST /v2/applications/:appId/stop-service
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2018-10-22 14:05:38 +00:00
Added in supervisor version v7.0.0. Support for passing `serviceName` instead of
`imageId` added in v8.2.2.
2021-08-09 20:55:06 +00:00
Temporarily stops a serivce. Rebooting the device or supervisor will cause the container to start again. The container is not removed with this endpoint.
2018-10-22 14:05:38 +00:00
2021-11-12 10:13:20 +00:00
From an app container:
2018-10-22 14:05:38 +00:00
```bash
2019-07-24 22:30:06 +00:00
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'
2018-10-22 14:05:38 +00:00
```
Response:
```
OK
```
This endpoint can also take an extra optional boolean, `force` , which if true informs the supervisor to ignore any update locks which have been taken.
2020-07-27 15:11:48 +00:00
### POST /v2/applications/:appId/start-service
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2018-10-22 14:05:38 +00:00
Added in supervisor version v7.0.0. Support for passing `serviceName` instead of
`imageId` added in v8.2.2.
2021-08-09 20:55:06 +00:00
Use this endpoint to start a service in the fleet with fleet id passed in with the url.
2018-10-22 14:05:38 +00:00
2021-11-12 10:13:20 +00:00
From an app container:
2018-10-22 14:05:38 +00:00
```bash
2019-07-24 22:30:06 +00:00
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/start-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/start-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'
2018-10-22 14:05:38 +00:00
```
Response:
```
OK
```
This endpoint can also take an extra optional boolean, `force` , which if true informs the supervisor to ignore any update locks which have been taken.
2020-07-27 15:11:48 +00:00
### POST /v2/applications/:appId/restart
2018-10-22 14:05:38 +00:00
2021-05-25 10:24:13 +00:00
> **Note:** This route will remove and recreate all service containers. See [the restart action](https://www.balena.io/docs/learn/manage/actions/#restart-application) for more information. On devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2018-10-22 14:05:38 +00:00
Added in supervisor version v7.0.0.
2021-08-09 20:55:06 +00:00
Use this endpoint to restart every service in a fleet.
2018-10-22 14:05:38 +00:00
2021-11-12 10:13:20 +00:00
From an app container:
2018-10-22 14:05:38 +00:00
```bash
2019-07-24 22:30:06 +00:00
curl -X POST --header "Content-Type: application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart?apikey=$BALENA_SUPERVISOR_API_KEY"
2018-10-22 14:05:38 +00:00
```
Response:
```
OK
```
This endpoint can also take an extra optional boolean, `force` , which if true informs the supervisor to ignore any update locks which have been taken.
2020-07-27 15:11:48 +00:00
### POST /v2/applications/:appId/purge
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
> **Note:** on devices with supervisor version lower than 7.22.0, replace all `BALENA_` variables with `RESIN_`, e.g. `RESIN_SUPERVISOR_ADDRESS` instead of `BALENA_SUPERVISOR_ADDRESS`.
2018-11-13 16:46:19 +00:00
2018-10-22 14:05:38 +00:00
Added in supervisor version v7.0.0.
2021-08-09 20:55:06 +00:00
Use this endpoint to purge all user data for a given fleet id.
2018-10-22 14:05:38 +00:00
2021-11-12 10:13:20 +00:00
From an app container:
2018-10-22 14:05:38 +00:00
```bash
2019-07-24 22:30:06 +00:00
curl -X POST --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/purge?apikey=$BALENA_SUPERVISOR_API_KEY"
2018-10-22 14:05:38 +00:00
```
Response:
```
OK
```
This endpoint can also take an extra optional boolean, `force` , which if true informs the supervisor to ignore any update locks which have been taken.
2020-07-27 15:11:48 +00:00
### GET /v2/version
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v7.21**
2018-10-22 14:05:38 +00:00
This endpoint returns the supervisor version currently running the device api.
2021-11-12 10:13:20 +00:00
From an app container:
2021-05-17 06:14:37 +00:00
```bash
2018-10-22 14:05:38 +00:00
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/version?apikey=$BALENA_SUPERVISOR_API_KEY"
```
Response:
```json
{
"status": "success",
"version": "v7.21.0"
}
```
2020-07-27 15:11:48 +00:00
### GET /v2/containerId
2018-11-27 22:05:39 +00:00
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v8.6**
2018-11-27 22:05:39 +00:00
Use this endpoint to match a service name to a container ID.
2021-11-12 10:13:20 +00:00
From an app container:
2021-05-17 06:14:37 +00:00
```bash
2018-11-27 22:05:39 +00:00
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/containerId?apikey=$BALENA_SUPERVISOR_API_KEY"
```
Response:
```json
{
"status": "success",
"services": {
"service-one": "ad6d5d32576ad3cb1fcaa59b564b8f6f22b079631080ab1a3bbac9199953eb7d",
"service-two": "756535dc6e9ab9b560f84c85063f55952273a23192641fc2756aa9721d9d1000"
}
}
```
You can also specify a service, to return only that container id:
2021-05-17 06:14:37 +00:00
```bash
2018-11-27 22:05:39 +00:00
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/containerId?apikey=$BALENA_SUPERVISOR_API_KEY& service=service-one"
```
Response:
```json
{
2019-08-08 18:12:09 +00:00
"status": "success",
2018-11-27 22:05:39 +00:00
"containerId": "ad6d5d32576ad3cb1fcaa59b564b8f6f22b079631080ab1a3bbac9199953eb7d"
}
```
2018-10-22 14:05:38 +00:00
### Local mode endpoints
These endpoints are mainly for use by the CLI, for working with a local mode device.
As such they are not recommended for general use.
2020-01-29 15:30:17 +00:00
The device must be in local mode before these endpoints are
called, with the exception of `GET /v2/local/target-state` ,
which can be called when the device is not in local mode.
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
### GET /v2/local/target-state
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v7.21**
2018-10-22 14:05:38 +00:00
Get the current target state. Note that if a local mode target state has not been
set then the apps section of the response will always be empty.
Request:
```bash
2018-11-13 16:46:19 +00:00
curl "$BALENA_SUPERVISOR_ADDRESS/v2/local/target-state"
2018-10-22 14:05:38 +00:00
```
Response:
```json
{
"status": "success",
"state": {
"local": {
"name": "my-device",
"config": {
"HOST_CONFIG_disable_splash": "1",
"HOST_CONFIG_dtparam": "\"i2c_arm=on\",\"spi=on\",\"audio=on\"",
"HOST_CONFIG_enable_uart": "1",
"HOST_CONFIG_gpu_mem": "16",
"SUPERVISOR_LOCAL_MODE": "1",
"SUPERVISOR_PERSISTENT_LOGGING": "",
"SUPERVISOR_POLL_INTERVAL": "600000",
"SUPERVISOR_VPN_CONTROL": "true",
"SUPERVISOR_CONNECTIVITY_CHECK": "true",
"SUPERVISOR_LOG_CONTROL": "true",
"SUPERVISOR_DELTA": "false",
"SUPERVISOR_DELTA_REQUEST_TIMEOUT": "30000",
"SUPERVISOR_DELTA_APPLY_TIMEOUT": "",
"SUPERVISOR_DELTA_RETRY_COUNT": "30",
"SUPERVISOR_DELTA_RETRY_INTERVAL": "10000",
"SUPERVISOR_DELTA_VERSION": "2",
"SUPERVISOR_OVERRIDE_LOCK": "false"
},
"apps": {}
}
}
}
```
2020-07-27 15:11:48 +00:00
### POST /v2/local/target-state
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v7.21**
2018-10-22 14:05:38 +00:00
Set the current target state.
Request:
```bash
TARGET_STATE='{
"local": {
"name": "Home",
"config": {
"HOST_CONFIG_disable_splash": "1",
"HOST_CONFIG_dtparam": "i2c_arm=on,i2s=on",
"HOST_CONFIG_enable_uart": "1",
"HOST_CONFIG_gpio": "\"2=op\",\"3=op\"",
"HOST_CONFIG_gpu_mem": "16",
"SUPERVISOR_LOCAL_MODE": "1",
"SUPERVISOR_POLL_INTERVAL": "600000",
"SUPERVISOR_VPN_CONTROL": "true",
"SUPERVISOR_CONNECTIVITY_CHECK": "true",
"SUPERVISOR_LOG_CONTROL": "true",
"SUPERVISOR_DELTA": "false",
"SUPERVISOR_DELTA_REQUEST_TIMEOUT": "30000",
"SUPERVISOR_DELTA_APPLY_TIMEOUT": "",
"SUPERVISOR_DELTA_RETRY_COUNT": "30",
"SUPERVISOR_DELTA_RETRY_INTERVAL": "10000",
"SUPERVISOR_DELTA_VERSION": "2",
"SUPERVISOR_OVERRIDE_LOCK": "false",
"SUPERVISOR_PERSISTENT_LOGGING": "false"
},
"apps": {
"1": {
"name": "localapp",
"commit": "localcommit",
"releaseId": "1",
"services": {
"1": {
"environment": {},
"labels": {},
"imageId": 1,
"serviceName": "one",
"serviceId": 1,
"image": "local_image_one:latest",
"running": true
},
"2": {
"environment": {},
"labels": {},
"network_mode": "container:one",
"imageId": 2,
"serviceName": "two",
"serviceId": 2,
"image": "local_image_two:latest",
"running": true
}
},
"volumes": {},
"networks": {}
}
}
}
}
'
2018-11-13 16:46:19 +00:00
curl -X POST --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/local/target-state" -d $TARGET_STATE
2018-10-22 14:05:38 +00:00
```
Response:
```json
{
"status": "success",
"message": "OK"
}
```
2020-07-27 15:11:48 +00:00
### Get the device type information
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v7.21**
2018-10-22 14:05:38 +00:00
Get the architecture and device type of the device.
Request:
```bash
2018-11-13 16:46:19 +00:00
curl "$BALENA_SUPERVISOR_ADDRESS/v2/local/device-info"
2018-10-22 14:05:38 +00:00
```
Response:
```json
{
"status": "success",
"info": {
"arch": "armv7hf",
2018-11-13 16:46:19 +00:00
"deviceType": "raspberry-pi3"
2018-10-22 14:05:38 +00:00
}
}
```
2021-08-09 20:55:06 +00:00
### Stream local mode logs from device
2018-10-22 14:05:38 +00:00
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v7.21**
2018-10-22 14:05:38 +00:00
2021-08-09 20:55:06 +00:00
This endpoint will stream the logs of the services and the supervisor. The logs come in as NDJSON.
2018-10-22 14:05:38 +00:00
Request:
```bash
2018-11-13 16:46:19 +00:00
curl "$BALENA_SUPERVISOR_ADDRESS/v2/local/logs"
2018-10-22 14:05:38 +00:00
```
Response:
```json
{
"message": "log line text",
"timestamp": 1541508467072,
"serviceName": "main"
}
{
"message": "another log line",
"timestamp": 1541508467072,
"serviceName": "main"
}
```
2019-03-12 13:56:31 +00:00
### V2 Device Information
#### Device name
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v9.11**
2019-03-12 13:56:31 +00:00
Get the last returned device name from the balena API. Note that this differs from the
`BALENA_DEVICE_NAME_AT_INIT` environment variable provided to containers, as this will
not change throughout the runtime of the container, but the endpoint will always return
the latest known device name.
2021-11-12 10:13:20 +00:00
From an app container:
2021-05-17 06:14:37 +00:00
```bash
2019-03-12 13:56:31 +00:00
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/device/name?apikey=$BALENA_SUPERVISOR_API_KEY"
```
Response:
```json
{
"status": "success",
"deviceName": "holy-wildflower"
}
```
2019-03-12 14:43:01 +00:00
#### Device tags
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v9.11**
2019-03-12 14:43:01 +00:00
Retrieve any device tags from the balena API. Note that this endpoint will not work when
the device does not have an available connection to the balena API.
2021-11-12 10:13:20 +00:00
From an app container:
2021-05-17 06:14:37 +00:00
```bash
2019-03-12 14:43:01 +00:00
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/device/tags?apikey=$BALENA_SUPERVISOR_API_KEY"
```
Response:
```json
{
"status": "success",
"tags": [
{
"id": 188303,
"name": "DeviceLocation",
"value": "warehouse #3 "
}
]
}
```
2019-06-18 11:22:37 +00:00
2020-05-08 20:04:21 +00:00
#### Device VPN Information
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v11.4**
2020-05-08 20:04:21 +00:00
Retrieve information about the VPN connection running on the device.
2021-11-12 10:13:20 +00:00
From an app container:
2020-05-08 20:04:21 +00:00
2021-05-17 06:14:37 +00:00
```bash
2020-05-08 20:04:21 +00:00
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/device/vpn?apikey=$BALENA_SUPERVISOR_API_KEY"
```
Response:
```json
{
"status": "success",
"vpn": {
"enabled": true,
"connected": true
}
}
```
2019-07-05 12:27:31 +00:00
### V2 Utilities
#### Cleanup volumes with no references
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v10.0**
2019-07-05 12:27:31 +00:00
Starting with balena-supervisor v10.0.0, volumes which have no
references are no longer automatically removed as part of
the standard update flow. To cleanup up any orphaned
volumes, use this supervisor endpoint:
2021-11-12 10:13:20 +00:00
From an app container:
2021-05-17 06:14:37 +00:00
```bash
2019-07-05 12:27:31 +00:00
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/cleanup-volumes?apikey=$BALENA_SUPERVISOR_API_KEY"
```
Successful response:
2021-05-17 06:14:37 +00:00
```json
2019-07-05 12:27:31 +00:00
{
"status": "success"
}
```
Unsuccessful response:
2021-05-17 06:14:37 +00:00
```json
2019-07-05 12:27:31 +00:00
{
"status": "failed",
"message": "the error message"
}
```
2019-06-18 11:22:37 +00:00
#### Journald logs
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v10.2**
2019-06-18 11:22:37 +00:00
Retrieve a stream to the journald logs on device. This is
2019-08-21 14:01:18 +00:00
equivalent to running `journalctl --no-pager` . Options
2019-06-18 11:22:37 +00:00
supported are:
##### all: boolean
Show all fields in full, equivalent to `journalctl --all` .
##### follow: boolean
Continuously stream logs as they are generated, equivalent
to `journalctl --follow` .
##### count: integer
Show the most recent `count` events, equivalent to
`journalctl --line=<count>` .
##### unit
Show journal logs from `unit` only, equivalent to
`journalctl --unit=<unit>` .
2022-06-22 17:40:03 +00:00
##### containerId
Show journal logs for the given `containerId` identifier only, equivalent to
`journalctl -t=<containerId>` .
2019-08-21 14:01:18 +00:00
##### format
2020-07-27 15:11:48 +00:00
> **Introduced in supervisor v10.3**
2019-08-21 14:09:09 +00:00
2019-08-21 14:01:18 +00:00
The format which will be streamed from journalctl, formats
2019-08-21 14:09:09 +00:00
are described here:
2019-08-21 14:01:18 +00:00
https://www.freedesktop.org/software/systemd/man/journalctl.html#-o
2019-06-18 11:22:37 +00:00
Fields should be provided via POST body in JSON format.
2021-11-12 10:13:20 +00:00
From an app container:
2021-05-17 06:14:37 +00:00
```bash
2019-08-21 14:09:09 +00:00
$ curl -X POST -H "Content-Type: application/json" --data '{"follow":true,"all":true}' "$BALENA_SUPERVISOR_ADDRESS/v2/journal-logs?apikey=$BALENA_SUPERVISOR_API_KEY" > log.journal
2019-06-18 11:22:37 +00:00
```
2022-12-27 07:30:21 +00:00
##### since: string
> **Introduced in supervisor v14.7.0**
Show journal logs since the given `since` timestamp, formats are described here:
[https://www.freedesktop.org/software/systemd/man/journalctl.html#-S ](https://www.freedesktop.org/software/systemd/man/journalctl.html#-S )
##### until: string
> **Introduced in supervisor v14.7.0**
Show journal logs until the given `until` timestamp, formats are described here:
[https://www.freedesktop.org/software/systemd/man/journalctl.html#-S ](https://www.freedesktop.org/software/systemd/man/journalctl.html#-S )
2019-08-21 14:09:09 +00:00
An example project using this endpoint can be found
2020-06-05 13:16:43 +00:00
[in this repository ](https://github.com/balena-io-playground/device-cloud-logging ).