- 浏览: 239057 次
- 性别:
- 来自: 珠海
文章分类
- 全部博客 (196)
- 职业感想 (66)
- hadoop (7)
- spark (5)
- mycat (13)
- Raft (2)
- nexus (3)
- Nginx (5)
- SpringBoot (5)
- Mongodb (5)
- amq (2)
- shell (3)
- netty (3)
- spring 5.0 (2)
- 响应式编程 (1)
- Spring Cloud (4)
- pdf (1)
- docker (17)
- Kubernetes (1)
- 技术总监 (1)
- 区块链 (1)
- 大数据 (1)
- Kylin (1)
- NIO (1)
- JVM (2)
- zookeeper (1)
- Python (2)
- Docker-Compose (2)
- mysql (14)
- eclipse (1)
- spring cloud config (1)
- Redis (1)
- centos (2)
- tokudb (1)
- findbugs (1)
- HikariCP (1)
- php (1)
- ES (1)
- ZigBee (1)
- 物联网 (1)
- NLP (1)
- ionic (1)
- go (4)
- node red (3)
- 树莓派 (1)
- iot (1)
- pm2 (1)
- nodejs (1)
- Supervisor (1)
- dbus (1)
- linux (1)
- vpn (1)
- arm (1)
- debian (1)
- consul (1)
- Hystrix (1)
- InheritableThreadLocal (1)
最新评论
-
男人50:
不远啊 写道难道大多程序猿都是这样过来的吗,接着后来有一部分当 ...
刚毕业的时候 -
不远啊:
难道大多程序猿都是这样过来的吗,接着后来有一部分当了老师教着新 ...
刚毕业的时候 -
男人50:
...
ES 与关系型数据库的对比 -
liaodongdakai:
精通并发与Netty网盘地址:https://pan.baid ...
精通netty框架 -
男人50:
knight_black_bob 写道这内容怎么审核的,你好, ...
我从事技术的这些年(第12年)
he 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.
The Supervisor itself has its own API, with means for user applications to communicate and execute some special actions that affect the host OS or the application itself. There are two main ways for the application to interact with the Supervisor: the update lockfile and the HTTP API.
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.
HTTP API reference
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.
The supervisor exposes an HTTP API on port 48484 (BALENA_SUPERVISOR_PORT).
To enable these Supervisor environment variables, the io.balena.features.supervisor-api label must be applied for each service that requires them. See here for further details.
All endpoints require an apikey parameter, which is exposed to the application as BALENA_SUPERVISOR_API_KEY.
The full address for the API, i.e. "http://127.0.0.1:48484", is available as BALENA_SUPERVISOR_ADDRESS. Always use these variables when communicating via the API, since address and port could change.
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 an application, 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.
The API is versioned (currently at v1), except for /ping.
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.
Here's the full list of endpoints implemented so far. In all examples, replace everything between < > for the corresponding values.
GET /ping
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.
Responds with a simple "OK", signaling that the supervisor is alive and well.
Examples:
From the app on the device:
$ curl -X GET --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/ping?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
OK
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "GET"}' \
"https://api.balena-cloud.com/supervisor/ping"
POST /v1/blink
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.
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:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/blink?apikey=$BALENA_SUPERVISOR_API_KEY"
(Empty response)
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/blink"
POST /v1/update
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.
Triggers an update check on the supervisor. Optionally, forces an update when updates are locked.
Responds with an empty 204 (No Content) response.
Request body
Can be a JSON object with a force property. If this property is true, the update lock will be overridden.
{
"force": true
}
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
--data '{"force": true}' \
"$BALENA_SUPERVISOR_ADDRESS/v1/update?apikey=$BALENA_SUPERVISOR_API_KEY"
(Empty response)
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "data": {"force": true}}' \
"https://api.balena-cloud.com/supervisor/v1/update"
POST /v1/reboot
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.
Reboots the device. This will first try to stop applications, and fail if there is an update lock. An optional "force" parameter in the body overrides the lock when true (and the lock can also be overridden from the dashboard).
When successful, responds with 202 accepted and a JSON object:
{
"Data": "OK",
"Error": ""
}
Request body
Can contain a force property, which if set to true will cause the update lock to be overridden.
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/reboot?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"Data":"OK","Error":""}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/reboot"
POST /v1/shutdown
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.
Dangerous. Shuts down the device. This will first try to stop applications, and fail if there is an update lock. An optional "force" parameter in the body overrides the lock when true (and the lock can also be overridden from the dashboard).
When successful, responds with 202 accepted and a JSON object:
{
"Data": "OK",
"Error": ""
}
Request body
Can contain a force property, which if set to true will cause the update lock to be overridden.
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/shutdown?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"Data":"OK","Error":""}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/shutdown"
POST /v1/purge
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.
Clears the user application's /data folder.
When successful, responds with 200 and a JSON object:
{
"Data": "OK",
"Error": ""
}
Request body
Has to be a JSON object with an appId property, corresponding to the ID of the application the device is running.
Example:
{
"appId": 2167
}
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
--data '{"appId": <appId>}' \
"$BALENA_SUPERVISOR_ADDRESS/v1/purge?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"Data":"OK","Error":""}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "data": {"appId": <appId>}}' \
"https://api.balena-cloud.com/supervisor/v1/purge"
POST /v1/restart
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.
Restarts a user application container
When successful, responds with 200 and an "OK"
Request body
Has to be a JSON object with an appId property, corresponding to the ID of the application the device is running.
Example:
{
"appId": 2167
}
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
--data '{"appId": <appId>}' \
"$BALENA_SUPERVISOR_ADDRESS/v1/restart?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
OK
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "data": {"appId": <appId>}}' \
"https://api.balena-cloud.com/supervisor/v1/restart"
POST /v1/regenerate-api-key
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.
Invalidates the current BALENA_SUPERVISOR_API_KEY and generates a new one. Responds with the new API key, but the application will be restarted on the next update cycle to update the API key environment variable.
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/regenerate-api-key?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
480af7bb8a9cf56de8a1e295f0d50e6b3bb46676aaddbf4103aa43cb57039364
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/regenerate-api-key"
GET /v1/device
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.
Introduced in supervisor v1.6. Returns the current device state, as reported to the balenaCloud API and with some extra fields added to allow control over pending/locked updates. The state is a JSON object that contains some or all of the following:
api_port: Port on which the supervisor is listening.
commit: Hash of the current commit of the application that is running.
ip_address: Space-separated list of IP addresses of the device.
status: Status of the device regarding the app, as a string, i.e. "Stopping", "Starting", "Downloading", "Installing", "Idle".
download_progress: Amount of the application image that has been downloaded, expressed as a percentage. If the update has already been downloaded, this will be null.
os_version: Version of the host OS running on the device.
supervisor_version: Version of the supervisor running on the device.
update_pending: This one is not reported to the balenaCloud API. It's a boolean that will be true if the supervisor has detected there is a pending update.
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).
Other attributes may be added in the future, and some may be missing or null if they haven't been set yet.
Examples:
From the app on the device:
$ curl -X GET --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/device?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"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}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "GET"}' \
"https://api.balena-cloud.com/supervisor/v1/device"
POST /v1/apps/:appId/stop
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.
Introduced in supervisor v1.8. Temporarily stops a user application container. A reboot or supervisor restart will cause the container to start again. The container is not removed with this endpoint.
This is only supported on single-container devices, and will return 400 on devices running multiple containers.
When successful, responds with 200 and the Id of the stopped container.
The appId must be specified in the URL.
Request body
Can contain a force property, which if set to true will cause the update lock to be overridden.
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/apps/<appId>/stop?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"containerId":"5f4d4a857742e9ecac505ba5710834d3852ad7d71e10389fc6f61d8655a21806"}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/apps/<appId>/stop"
POST /v1/apps/:appId/start
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.
Introduced in supervisor v1.8. Starts a user application container, usually after it has been stopped with /v1/stop.
This is only supported on single-container devices, and will return 400 on devices running multiple containers.
When successful, responds with 200 and the Id of the started container.
The appId must be specified in the URL.
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/apps/<appId>/start?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"containerId":"6d9e1efdb9aad90fdb2df911f785b6aa00270e9448e75226a9a7361c8a9500cf"}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/apps/<appId>/start"
GET /v1/apps/:appId
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.
Introduced in supervisor v1.8. Returns the application running on the device The app is a JSON object that contains the following:
appId: The id of the app as per the balenaCloud API.
commit: Application commit that is running.
imageId: The docker image of the current application build.
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.
This is only supported on single-container devices, and will return 400 on devices running multiple containers.
Examples:
From the app on the device:
$ curl -X GET --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/apps/<appId>?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"appId": 3134,"commit":"414e65cd378a69a96f403b75f14b40b55856f860","imageId":"registry.balena-cloud.com/superapp/414e65cd378a69a96f403b75f14b40b55856f860","containerId":"e5c1eace8b4e","env":{"FOO":"bar"}}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "GET"}' \
"https://api.balena-cloud.com/supervisor/v1/apps/<appId>"
GET /v1/healthy
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.
Added in supervisor v6.5.0.
Used internally to check whether the supervisor is running correctly, according to some heuristics that help determine whether the internal components, application updates and reporting to the balenaCloud API are functioning.
Responds with an empty 200 response if the supervisor is healthy, or a 500 status code if something is not working correctly.
Examples:
From the app on the device:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v1/healthy"
(Empty response)
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "GET"}' \
"https://api.balena-cloud.com/supervisor/v1/healthy"
PATCH /v1/device/host-config
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.
Added in supervisor v6.6.0.
This endpoint allows setting some configuration values for the host OS. Currently it supports proxy and hostname configuration.
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 user applications to modify these proxy settings at runtime.
Request body
Is 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 viceversa.
{
"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" ]
},
"hostname": "mynewhostname"
}
}
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 works. type can be socks4, socks5, http-connect or http-relay (not all proxies are guaranteed to work, especially if they block connections that the balena services may require).
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).
The "noProxy" setting for the proxy is an optional array of IP addresses/subnets that should not be routed through the proxy. Keep in mind that local/reserved subnets are already excluded by balenaOS automatically.
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).
Examples:
From the app on the device:
$ curl -X PATCH --header "Content-Type:application/json" \
--data '{"network": {"hostname": "newhostname"}}' \
"$BALENA_SUPERVISOR_ADDRESS/v1/device/host-config?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
OK
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "PATCH", "data": {"network": {"hostname": "newhostname"}}}' \
"https://api.balena-cloud.com/supervisor/v1/device/host-config"
GET /v1/device/host-config
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.
Added in supervisor v6.6.0.
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:
From the app on the device:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v1/device/host-config?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"network":{"proxy":{"ip":"192.168.0.199","port":"8123","type":"socks5"},"hostname":"27b0fdc"}}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "GET"}' \
"https://api.balena-cloud.com/supervisor/v1/device/host-config"
GET /v2/applications/state
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.
Added in supervisor v7.12.0
Get a list of applications, services and their statuses. This will reflect the current state of the supervisor, and not the target state.
From the user container:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/applications/state?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{
"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
}
}
}
}
Remotely via the API proxy:
curl -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <auth token>' \
-d '{"uuid": "<uuid>", "method": "GET"}' \
"https://api.resin.io/supervisor/v2/applications/state"
GET /v2/applications/:appId/state
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.
Added in supervisor version v7.12.0.
Use this endpoint to get the state of a single application, given the appId.
From the user container:
curl "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/state?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{
"local": {
"1234": {
"services": {
"5678": {
"status": "Running",
"releaseId": 99999,
"download_progress": null
}
}
}
},
"dependent": {},
"commit": "7fc9c5bea8e361acd49886fe6cc1e1cd"
}
Service Actions
The application ID
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.
For the following endpoints the application id is required in the url. The easiest way to get the application id from the device is to use the following process (note that you will need jq and curl inside your container):
From the user container:
APPNAME="supervisortest"
APPID=$(curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/state?apikey=$BALENA_SUPERVISOR_API_KEY" | jq ".$APPNAME.appId")
The easiest way to find your application from the dashboard is to look at the url when on the device list.
Restart a service (POST /v2/applications/:appId/restart-service)
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.
Added in supervisor version v7.0.0. Support for passing serviceName instead of imageId added in v8.2.2.
Use this endpoint to restart a service in the application with application id passed in with the url.
From the user container:
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'
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.
Stop a service (POST /v2/applications/:appId:/stop-service)
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.
Added in supervisor version v7.0.0. Support for passing serviceName instead of imageId added in v8.2.2.
Use this endpoint to stop a service in the application with application id passed in with the url.
From the user container:
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'
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.
Start a service (POST /v2/applications/:appId/start-service)
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.
Added in supervisor version v7.0.0. Support for passing serviceName instead of imageId added in v8.2.2.
Use this endpoint to start a service in the application with application id passed in with the url.
From the user container:
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/start-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/start-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'
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.
Restart all services in an application (POST /v2/applications/:appId/restart)
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.
Added in supervisor version v7.0.0.
Use this endpoint to restart every service in an application.
From the user container:
curl -X POST --header "Content-Type: application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/restart?apikey=$BALENA_SUPERVISOR_API_KEY"
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.
Purge an application data (POST /v2/applications/:appId/purge)
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.
Added in supervisor version v7.0.0.
Use this endpoint to purge all user data for a given application id.
From the user container:
curl -X POST --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/purge?apikey=$BALENA_SUPERVISOR_API_KEY"
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.
Supervisor version (GET /v2/version)
Added in supervisor v7.21.0
This endpoint returns the supervisor version currently running the device api.
From the user container:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/version?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{
"status": "success",
"version": "v7.21.0"
}
Container ID (GET /v2/containerId)
Added in supervisor v8.6.0
Use this endpoint to match a service name to a container ID.
From the user container:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/containerId?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{
"status": "success",
"services": {
"service-one": "ad6d5d32576ad3cb1fcaa59b564b8f6f22b079631080ab1a3bbac9199953eb7d",
"service-two": "756535dc6e9ab9b560f84c85063f55952273a23192641fc2756aa9721d9d1000"
}
}
You can also specify a service, to return only that container id:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/containerId?apikey=$BALENA_SUPERVISOR_API_KEY&service=service-one"
Response:
{
"status": "sucess",
"containerId": "ad6d5d32576ad3cb1fcaa59b564b8f6f22b079631080ab1a3bbac9199953eb7d"
}
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.
The device must be in local mode before these endpoints are called.
Get current target state (GET /v2/local/target-state)
Added in supervisor version v7.21.0.
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:
curl "$BALENA_SUPERVISOR_ADDRESS/v2/local/target-state"
Response:
{
"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": {}
},
"dependent": {
"apps": [],
"devices": []
}
}
}
Set a target state (POST /v2/local/target-state)
Added in supervisor version v7.21.0.
Set the current target state.
Request:
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": {}
}
}
},
"dependent": {
"apps": [],
"devices": []
}
}
'
curl -X POST --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/local/target-state" -d $TARGET_STATE
Response:
{
"status": "success",
"message": "OK"
}
Get the device type information
Added in supervisor version v7.21.0.
Get the architecture and device type of the device.
Request:
curl "$BALENA_SUPERVISOR_ADDRESS/v2/local/device-info"
Response:
{
"status": "success",
"info": {
"arch": "armv7hf",
"deviceType": "raspberry-pi3"
}
}
Stream local mode application logs from device
Added in supervisor version v7.21.0.
This endpoint will stream the logs of the applications containers and the supervisor. The logs come in as NDJSON.
Request:
curl "$BALENA_SUPERVISOR_ADDRESS/v2/local/logs"
Response:
{
"message": "log line text",
"timestamp": 1541508467072,
"serviceName": "main"
}
{
"message": "another log line",
"timestamp": 1541508467072,
"serviceName": "main"
}
The Supervisor itself has its own API, with means for user applications to communicate and execute some special actions that affect the host OS or the application itself. There are two main ways for the application to interact with the Supervisor: the update lockfile and the HTTP API.
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.
HTTP API reference
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.
The supervisor exposes an HTTP API on port 48484 (BALENA_SUPERVISOR_PORT).
To enable these Supervisor environment variables, the io.balena.features.supervisor-api label must be applied for each service that requires them. See here for further details.
All endpoints require an apikey parameter, which is exposed to the application as BALENA_SUPERVISOR_API_KEY.
The full address for the API, i.e. "http://127.0.0.1:48484", is available as BALENA_SUPERVISOR_ADDRESS. Always use these variables when communicating via the API, since address and port could change.
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 an application, 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.
The API is versioned (currently at v1), except for /ping.
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.
Here's the full list of endpoints implemented so far. In all examples, replace everything between < > for the corresponding values.
GET /ping
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.
Responds with a simple "OK", signaling that the supervisor is alive and well.
Examples:
From the app on the device:
$ curl -X GET --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/ping?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
OK
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "GET"}' \
"https://api.balena-cloud.com/supervisor/ping"
POST /v1/blink
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.
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:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/blink?apikey=$BALENA_SUPERVISOR_API_KEY"
(Empty response)
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/blink"
POST /v1/update
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.
Triggers an update check on the supervisor. Optionally, forces an update when updates are locked.
Responds with an empty 204 (No Content) response.
Request body
Can be a JSON object with a force property. If this property is true, the update lock will be overridden.
{
"force": true
}
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
--data '{"force": true}' \
"$BALENA_SUPERVISOR_ADDRESS/v1/update?apikey=$BALENA_SUPERVISOR_API_KEY"
(Empty response)
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "data": {"force": true}}' \
"https://api.balena-cloud.com/supervisor/v1/update"
POST /v1/reboot
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.
Reboots the device. This will first try to stop applications, and fail if there is an update lock. An optional "force" parameter in the body overrides the lock when true (and the lock can also be overridden from the dashboard).
When successful, responds with 202 accepted and a JSON object:
{
"Data": "OK",
"Error": ""
}
Request body
Can contain a force property, which if set to true will cause the update lock to be overridden.
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/reboot?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"Data":"OK","Error":""}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/reboot"
POST /v1/shutdown
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.
Dangerous. Shuts down the device. This will first try to stop applications, and fail if there is an update lock. An optional "force" parameter in the body overrides the lock when true (and the lock can also be overridden from the dashboard).
When successful, responds with 202 accepted and a JSON object:
{
"Data": "OK",
"Error": ""
}
Request body
Can contain a force property, which if set to true will cause the update lock to be overridden.
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/shutdown?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"Data":"OK","Error":""}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/shutdown"
POST /v1/purge
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.
Clears the user application's /data folder.
When successful, responds with 200 and a JSON object:
{
"Data": "OK",
"Error": ""
}
Request body
Has to be a JSON object with an appId property, corresponding to the ID of the application the device is running.
Example:
{
"appId": 2167
}
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
--data '{"appId": <appId>}' \
"$BALENA_SUPERVISOR_ADDRESS/v1/purge?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"Data":"OK","Error":""}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "data": {"appId": <appId>}}' \
"https://api.balena-cloud.com/supervisor/v1/purge"
POST /v1/restart
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.
Restarts a user application container
When successful, responds with 200 and an "OK"
Request body
Has to be a JSON object with an appId property, corresponding to the ID of the application the device is running.
Example:
{
"appId": 2167
}
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
--data '{"appId": <appId>}' \
"$BALENA_SUPERVISOR_ADDRESS/v1/restart?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
OK
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "data": {"appId": <appId>}}' \
"https://api.balena-cloud.com/supervisor/v1/restart"
POST /v1/regenerate-api-key
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.
Invalidates the current BALENA_SUPERVISOR_API_KEY and generates a new one. Responds with the new API key, but the application will be restarted on the next update cycle to update the API key environment variable.
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/regenerate-api-key?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
480af7bb8a9cf56de8a1e295f0d50e6b3bb46676aaddbf4103aa43cb57039364
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/regenerate-api-key"
GET /v1/device
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.
Introduced in supervisor v1.6. Returns the current device state, as reported to the balenaCloud API and with some extra fields added to allow control over pending/locked updates. The state is a JSON object that contains some or all of the following:
api_port: Port on which the supervisor is listening.
commit: Hash of the current commit of the application that is running.
ip_address: Space-separated list of IP addresses of the device.
status: Status of the device regarding the app, as a string, i.e. "Stopping", "Starting", "Downloading", "Installing", "Idle".
download_progress: Amount of the application image that has been downloaded, expressed as a percentage. If the update has already been downloaded, this will be null.
os_version: Version of the host OS running on the device.
supervisor_version: Version of the supervisor running on the device.
update_pending: This one is not reported to the balenaCloud API. It's a boolean that will be true if the supervisor has detected there is a pending update.
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).
Other attributes may be added in the future, and some may be missing or null if they haven't been set yet.
Examples:
From the app on the device:
$ curl -X GET --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/device?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"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}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "GET"}' \
"https://api.balena-cloud.com/supervisor/v1/device"
POST /v1/apps/:appId/stop
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.
Introduced in supervisor v1.8. Temporarily stops a user application container. A reboot or supervisor restart will cause the container to start again. The container is not removed with this endpoint.
This is only supported on single-container devices, and will return 400 on devices running multiple containers.
When successful, responds with 200 and the Id of the stopped container.
The appId must be specified in the URL.
Request body
Can contain a force property, which if set to true will cause the update lock to be overridden.
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/apps/<appId>/stop?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"containerId":"5f4d4a857742e9ecac505ba5710834d3852ad7d71e10389fc6f61d8655a21806"}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/apps/<appId>/stop"
POST /v1/apps/:appId/start
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.
Introduced in supervisor v1.8. Starts a user application container, usually after it has been stopped with /v1/stop.
This is only supported on single-container devices, and will return 400 on devices running multiple containers.
When successful, responds with 200 and the Id of the started container.
The appId must be specified in the URL.
Examples:
From the app on the device:
$ curl -X POST --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/apps/<appId>/start?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"containerId":"6d9e1efdb9aad90fdb2df911f785b6aa00270e9448e75226a9a7361c8a9500cf"}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>}' \
"https://api.balena-cloud.com/supervisor/v1/apps/<appId>/start"
GET /v1/apps/:appId
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.
Introduced in supervisor v1.8. Returns the application running on the device The app is a JSON object that contains the following:
appId: The id of the app as per the balenaCloud API.
commit: Application commit that is running.
imageId: The docker image of the current application build.
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.
This is only supported on single-container devices, and will return 400 on devices running multiple containers.
Examples:
From the app on the device:
$ curl -X GET --header "Content-Type:application/json" \
"$BALENA_SUPERVISOR_ADDRESS/v1/apps/<appId>?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"appId": 3134,"commit":"414e65cd378a69a96f403b75f14b40b55856f860","imageId":"registry.balena-cloud.com/superapp/414e65cd378a69a96f403b75f14b40b55856f860","containerId":"e5c1eace8b4e","env":{"FOO":"bar"}}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "GET"}' \
"https://api.balena-cloud.com/supervisor/v1/apps/<appId>"
GET /v1/healthy
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.
Added in supervisor v6.5.0.
Used internally to check whether the supervisor is running correctly, according to some heuristics that help determine whether the internal components, application updates and reporting to the balenaCloud API are functioning.
Responds with an empty 200 response if the supervisor is healthy, or a 500 status code if something is not working correctly.
Examples:
From the app on the device:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v1/healthy"
(Empty response)
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "GET"}' \
"https://api.balena-cloud.com/supervisor/v1/healthy"
PATCH /v1/device/host-config
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.
Added in supervisor v6.6.0.
This endpoint allows setting some configuration values for the host OS. Currently it supports proxy and hostname configuration.
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 user applications to modify these proxy settings at runtime.
Request body
Is 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 viceversa.
{
"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" ]
},
"hostname": "mynewhostname"
}
}
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 works. type can be socks4, socks5, http-connect or http-relay (not all proxies are guaranteed to work, especially if they block connections that the balena services may require).
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).
The "noProxy" setting for the proxy is an optional array of IP addresses/subnets that should not be routed through the proxy. Keep in mind that local/reserved subnets are already excluded by balenaOS automatically.
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).
Examples:
From the app on the device:
$ curl -X PATCH --header "Content-Type:application/json" \
--data '{"network": {"hostname": "newhostname"}}' \
"$BALENA_SUPERVISOR_ADDRESS/v1/device/host-config?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
OK
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "PATCH", "data": {"network": {"hostname": "newhostname"}}}' \
"https://api.balena-cloud.com/supervisor/v1/device/host-config"
GET /v1/device/host-config
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.
Added in supervisor v6.6.0.
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:
From the app on the device:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v1/device/host-config?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{"network":{"proxy":{"ip":"192.168.0.199","port":"8123","type":"socks5"},"hostname":"27b0fdc"}}
Remotely via the API proxy:
$ curl -X POST --header "Content-Type:application/json" \
--header "Authorization: Bearer <auth token>" \
--data '{"uuid": <uuid>, "method": "GET"}' \
"https://api.balena-cloud.com/supervisor/v1/device/host-config"
GET /v2/applications/state
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.
Added in supervisor v7.12.0
Get a list of applications, services and their statuses. This will reflect the current state of the supervisor, and not the target state.
From the user container:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/applications/state?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{
"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
}
}
}
}
Remotely via the API proxy:
curl -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <auth token>' \
-d '{"uuid": "<uuid>", "method": "GET"}' \
"https://api.resin.io/supervisor/v2/applications/state"
GET /v2/applications/:appId/state
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.
Added in supervisor version v7.12.0.
Use this endpoint to get the state of a single application, given the appId.
From the user container:
curl "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/state?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{
"local": {
"1234": {
"services": {
"5678": {
"status": "Running",
"releaseId": 99999,
"download_progress": null
}
}
}
},
"dependent": {},
"commit": "7fc9c5bea8e361acd49886fe6cc1e1cd"
}
Service Actions
The application ID
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.
For the following endpoints the application id is required in the url. The easiest way to get the application id from the device is to use the following process (note that you will need jq and curl inside your container):
From the user container:
APPNAME="supervisortest"
APPID=$(curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/state?apikey=$BALENA_SUPERVISOR_API_KEY" | jq ".$APPNAME.appId")
The easiest way to find your application from the dashboard is to look at the url when on the device list.
Restart a service (POST /v2/applications/:appId/restart-service)
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.
Added in supervisor version v7.0.0. Support for passing serviceName instead of imageId added in v8.2.2.
Use this endpoint to restart a service in the application with application id passed in with the url.
From the user container:
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'
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.
Stop a service (POST /v2/applications/:appId:/stop-service)
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.
Added in supervisor version v7.0.0. Support for passing serviceName instead of imageId added in v8.2.2.
Use this endpoint to stop a service in the application with application id passed in with the url.
From the user container:
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'
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.
Start a service (POST /v2/applications/:appId/start-service)
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.
Added in supervisor version v7.0.0. Support for passing serviceName instead of imageId added in v8.2.2.
Use this endpoint to start a service in the application with application id passed in with the url.
From the user container:
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/start-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/start-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'
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.
Restart all services in an application (POST /v2/applications/:appId/restart)
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.
Added in supervisor version v7.0.0.
Use this endpoint to restart every service in an application.
From the user container:
curl -X POST --header "Content-Type: application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/restart?apikey=$BALENA_SUPERVISOR_API_KEY"
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.
Purge an application data (POST /v2/applications/:appId/purge)
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.
Added in supervisor version v7.0.0.
Use this endpoint to purge all user data for a given application id.
From the user container:
curl -X POST --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$APPID/purge?apikey=$BALENA_SUPERVISOR_API_KEY"
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.
Supervisor version (GET /v2/version)
Added in supervisor v7.21.0
This endpoint returns the supervisor version currently running the device api.
From the user container:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/version?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{
"status": "success",
"version": "v7.21.0"
}
Container ID (GET /v2/containerId)
Added in supervisor v8.6.0
Use this endpoint to match a service name to a container ID.
From the user container:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/containerId?apikey=$BALENA_SUPERVISOR_API_KEY"
Response:
{
"status": "success",
"services": {
"service-one": "ad6d5d32576ad3cb1fcaa59b564b8f6f22b079631080ab1a3bbac9199953eb7d",
"service-two": "756535dc6e9ab9b560f84c85063f55952273a23192641fc2756aa9721d9d1000"
}
}
You can also specify a service, to return only that container id:
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/containerId?apikey=$BALENA_SUPERVISOR_API_KEY&service=service-one"
Response:
{
"status": "sucess",
"containerId": "ad6d5d32576ad3cb1fcaa59b564b8f6f22b079631080ab1a3bbac9199953eb7d"
}
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.
The device must be in local mode before these endpoints are called.
Get current target state (GET /v2/local/target-state)
Added in supervisor version v7.21.0.
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:
curl "$BALENA_SUPERVISOR_ADDRESS/v2/local/target-state"
Response:
{
"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": {}
},
"dependent": {
"apps": [],
"devices": []
}
}
}
Set a target state (POST /v2/local/target-state)
Added in supervisor version v7.21.0.
Set the current target state.
Request:
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": {}
}
}
},
"dependent": {
"apps": [],
"devices": []
}
}
'
curl -X POST --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/local/target-state" -d $TARGET_STATE
Response:
{
"status": "success",
"message": "OK"
}
Get the device type information
Added in supervisor version v7.21.0.
Get the architecture and device type of the device.
Request:
curl "$BALENA_SUPERVISOR_ADDRESS/v2/local/device-info"
Response:
{
"status": "success",
"info": {
"arch": "armv7hf",
"deviceType": "raspberry-pi3"
}
}
Stream local mode application logs from device
Added in supervisor version v7.21.0.
This endpoint will stream the logs of the applications containers and the supervisor. The logs come in as NDJSON.
Request:
curl "$BALENA_SUPERVISOR_ADDRESS/v2/local/logs"
Response:
{
"message": "log line text",
"timestamp": 1541508467072,
"serviceName": "main"
}
{
"message": "another log line",
"timestamp": 1541508467072,
"serviceName": "main"
}
相关推荐
【应用】★★★★★-manzana-.NET API for interacting with the Apple iPhone【应用】★★★★★-manzana-.NET API for interacting with the Apple iPhone 1.适合学生学习研究参考 2.适合个人学习研究参考 3.适合...
《manzana-.NET API for interacting with the Apple iPhone》是一个专为与苹果iPhone进行交互而设计的.NET API库。这个源码包对于那些希望在iOS平台上构建应用的开发者来说,是一份宝贵的资源,特别是对.NET框架有...
【标题】"IOS应用源码之manzana-.NET API for interacting with the Apple iPhone" 提供了一种使用.NET框架与苹果iPhone进行交互的途径。manzana是一个.NET库,它为开发者提供了方便的API,使得在iOS应用开发过程中...
本文将深入探讨标题为“【应用】-manzana-.NET API for interacting with the Apple iPhone.7z”的压缩包,其中包含了一个名为“Manzana”的.NET库,它为开发者提供了一种与Apple iPhone进行交互的方式。 首先,...
interacting with data This lecture covers the basics of core concepts in probability and statistics to be used in the course. These include random variables, continuous and discrete distributions, ...
《苹果iPhone交互.NET API——Manzana库详解》 在当今移动开发领域,iOS系统以其稳定性和用户友好性获得了广大开发者和用户的喜爱。对于非Objective-C或Swift开发者来说,想要与苹果iPhone进行交互可能会遇到一些...
Python library for interacting with FreeIPA network protocols
Golang client for interacting with Moov API server side
The module has two 32-bit MCUs - an x86 Intel Quark processor and an ARC EM4 processor along with 384kB flash memory and 80kB SRAM. These onboard MCUs combine a variety of new technologies including ...
Interacting with other devices via SMS, web browsing, and social networkingStoring data efficiently with SQLite and its alternatives Accessing location data via GPS Using location-related services ...
Interacting With Your Users CHAPTER 4. Introducing MySQL CHAPTER 5. Introducing the Zend Framework CHAPTER 6. Talking to the Database with Zend_Db CHAPTER 7. Processing Forms and Sending Email ...
Nitrogen fixation of faba bean interacting with a non-legume in two contrasting intercropping systems,范分良,余常兵,A field experiment was carried out to quantify biological nitrogen fixation (BNF)...
C++作为一款强大的系统编程语言,虽然原生不支持JSON解析和生成,但有许多第三方库可以帮助开发者处理JSON,其中之一就是这个"A C++ library for interacting with JSON"。 在C++中,与JSON交互的库通常提供了解析...
As with all classes derived from SocketClient, you must first connect to the server with connect before doing anything, and finally disconnect after you're completely finished interacting with the ...
If you are a Python administrator or developer interested in interacting with web APIs and have a passion for creating your own web applications, this is the book for you. Basic knowledge of Python ...
Moving on, you'll get hands on by expanding the storage options of the Raspberry Pi beyond the SD card and interacting with the graphics hardware. Furthermore, you will be introduced to the basics of...
UNIT 2 - STRINGS, TUPLES, AND INTERACTING WITH THE USER Lesson 7 - Introducing string objects: sequences of characters Lesson 8 - Advanced string operations Lesson 9 - Simple error messages Lesson 10 ...
We will then learn how to build learning agents that can learn from interacting with the environment. We will use Deep Learning with Convolutional Neural Networks, and use TensorFlow to build neural ...
《ISO IEC TR 23187:2020 Information technology - Cloud computing - Interacting with cloud service partners (CSNs)》是国际标准化组织(ISO)和国际电工委员会(IEC)联合发布的一份技术报告,旨在为云计算...
Chapter 9 Interacting with the Physical Environment 401 Chapter 10 Real-Time Interfacing Using External Slave Processors 455 Part III Advanced Beagle Board Systems 495 Chapter 11 The Internet of ...