summaryrefslogtreecommitdiffstats
path: root/docs/src/tutorials/supported_operations.md
blob: 3a5a7af5c0826920c08c0107bcb8a00b0b020c14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# thin-edge.io Supported Operations

## Supported Operations concepts

### Device operations

IoT devices often do more than just send data to the cloud. They also do things like:

* receive triggers from the operator
* reboot on demand
* install or remove software

These operations that are supported by [Cumulocity IoT](https://cumulocity.com/api/10.11.0/#section/Device-management-library) and other cloud providers.
On `thin-edge.io` the support for one such operation can be added using the `thin-edge.io` Supported Operations API.

### `thin-edge.io` Supported Operations API

The Supported Operations utilises the file system to add and remove operations. A special file placed in `/etc/tedge/operations` directory will indicate that an operation is supported.
The specification for the operation files is described in `thin-edge.io` specifications repository[src/supported-operations/README.md](https://github.com/thin-edge/thin-edge.io-specs/blob/main/src/supported-operations/README.md)

## `thin-edge.io` List of Supported Operations

`thin-edge.io` supports natively the following operations:

* Software Update
* Software Update Log Upload
* Restart

The list is growing as we support more operations, but is not exhaustive and we encourage you to contribute to the list.

## How to use Supported Operations

### Listing current operations

You can obtain the current list of supported operations by listing the content of the `/etc/tedge/operations` directory.
This directory should have permissions set to `755` and the owner to `tedge`.
This directory will contain a set subdirectories based on cloud providers currently supported eg:

```shell
$ ls -l /etc/tedge/operations

drwxr-xr-x 2 tedge tedge 4096 Jan 01 00:00 az
drwxr-xr-x 2 tedge tedge 4096 Jan 01 00:00 c8y
```

From the above you can see that there are two cloud providers supported by `thin-edge.io`.
The directories should be readable by `thin-edge.io` user - `tedge` - and should have permissions `755`.

To list all currently supported operations for a cloud provider, run:

```shell
$ ls -l /etc/tedge/operations/c8y

-rw-r--r-- 1 tedge tedge 0 Jan 01 00:00 c8y_Restart
```

To list all currently supported operations, run:
The operations files should have permissions `644` and the owner `tedge`.

```shell
$ sudo ls -lR /etc/tedge/operations
/etc/tedge/operations:
drwxr-xr-x 2 tedge tedge 4096 Jan 01 00:00 az
drwxr-xr-x 2 tedge tedge 4096 Jan 01 00:00 c8y

/etc/tedge/operations/az:
-rw-r--r-- 1 tedge tedge 0 Jan 01 00:00 Restart

/etc/tedge/operations/c8y:
-rw-r--r-- 1 tedge tedge 0 Jan 01 00:00 c8y_Restart
```

### Adding new operations

To add new operation we need to create new file in `/etc/tedge/operations` directory.
Before we create that file we have to know which cloud provider we are going to support (it is possible to support multiple cloud providers, but we won't cover this here).

We will add operation `Restart` for our device which can be triggered from Cumulocity IoT called, in Cumulocity IoT this operations name is `c8y_Restart`.
This operation will do the reboot of our device when we receive trigger from the operator. `thin-edge.io` device will receive an MQTT message with certain payload and we already have a handler for that payload in the `tedge-mapper-c8y`.

To add new operation we will create a file in `/etc/tedge/operations/c8y` directory:

```shell
sudo -u tedge touch /etc/tedge/operations/c8y/c8y_Restart
```

> Note: We are using `sudo -u` to create the file because we want to make sure that the file is owned by `tedge` user.

Now we just need to reboot the `tedge-mapper-c8y` so it picks new operations and it will automatically add it to the list and send it to the cloud.

### Removing supported operations

To remove supported operation we can remove the file from `/etc/tedge/operations/c8y` directory and restart the `tedge-mapper-c8y` to pick up the new list of supported operations. eg:

```shell
sudo rm /etc/tedge/operations/c8y/c8y_Restart
```