# Application assignment

## Introduction

It is currently not technically possible to automatically assign host processes and their services to a software application. Versio.io allows customers to define the application context for processes and services in an environment variable `VERSIO_APPLICATION_ID`.

The environment variable for application assignment can be defined at the following levels:

- Host level - application mapping applies to all processes and services on the host. Assignment at the host level is only recommended to a limited extent, because all captured host processes and services are assigned to one application by Versio.io (too coarse).
- Process level - application mapping applies to the process instance and all services provided by it.
- Shell/Bash level - application mapping applies to all processes and services in the dedicated execution context.

## Configuration

The mapping is done in a defined format `Application(Service)`, which for simplicity is illustrated in the following table in the form of examples. Specifying services reduces the mapping to an application only for the specified services. For example, the databases of a database management system can be assigned to different applications.

| Assignment type | Configuration |
| --- | --- |
| One application | `VERSIO_APPLICATION_ID = "MyApp1"` |
| Multiple applications | `VERSIO_APPLICATION_ID = "MyApp1,MyApp2"` |
| One application and one service | `VERSIO_APPLICATION_ID = "MyApp1(Service-A)"` |
| One application and specific services | `VERSIO_APPLICATION_ID = "MyApp1(Service-A\\|Service-B)"` |
| Assignment to multiple applications and specific services | `VERSIO_APPLICATION_ID = "MyApp1(Service-A\\|Service-B),MyApp2,MyApp3(Service-C)"` |

### NGINX workaround

By default, nginx removes all environment variables inherited from its parent process except the TZ variable. [(https://nginx.org/en/docs/ngx\_core\_module.html)](<https://nginx.org/en/docs/ngx_core_module.html>)

This means that the `VERSIO_APPLICATION_ID` environment variable is not available even if it has been set.

To automatically assign NGINX to the application anyway, the environment variable can be entered in the `/etc/nginx/versio-io.env` file.

## Topology example

The following topology shows an example of how processes and specific services have been assigned to an application.

![Example topology for which the processes and services are assigned to an application](<https://docs.versio.io/img/settings/application-assignment/software-architecture-topology-with-assigned-services.png>)

*Figure: Example topology for which the processes and services are assigned to an application*

## Integration examples

### Shell script or batch file

```sh
export VERSIO_APPLICATION_ID="crm.my-domain.com"
bash my-app
```

### Docker

```sh
docker run -d -e VERSIO_APPLICATION_ID="crm.my-domain.com" my-docker-image:latest
```

### Docker compose

```yml
version: "3"

services:
  crm:
    image: mycrm/mycrm:latest
    environment:
      - VERSIO_APPLICATION_ID="crm.my-domain.com"
    ports:
      - 443:443
```

### Linux systemd service

```text
[UNIT]
...

[Service]
Environment="VERSIO_APPLICATION_ID=crm.my-domain.com"
...

[INSTALL]
...
```
