# License

> Add the license file from Diakrin before the install or any time after it.

Source: https://diakrin.com/docs/self-hosted/license

A license file from Diakrin tells your installation who it is licensed to and until when; you can add it before the install or any time after.

## Before you start

| You supply | Example | Comes from |
| --- | --- | --- |
| A license file | `acme-license.json` | Your Diakrin contact. It is a signed file, not a secret |
| Your installation id and organization id | shown in the console's **License** step (after you create the owner account), and the installation id in `diakrin self-hosted status` | Only needed if you add the license after deploy |

## Get a license file

1. Tell your Diakrin contact your company name. If you already deployed, also send the installation id and organization id from the console's **License** step.
2. Diakrin sends you one file. It is bound to your installation, so it works only for you.

## Add it before you install

1. Save the file next to `diakrin.env`.
2. Add this line to `diakrin.env`:

```sh
DIAKRIN_LICENSE_FILE=./acme-license.json
```

3. Run `infra up` and `deploy` as usual. `deploy` uses the installation id and organization id from the file and stores the license, so the console's **License** step is already done after you create the owner account. A file for a different installation is refused before anything is created.

## Add it after you deploy

The license is optional at install. Without it, Diakrin installs and runs, and the console's **License** step shows as pending.

```sh
diakrin self-hosted license update ./acme-license.json
```

The command prints the license revision and its expiry date. The installation picks the license up within a minute, with no redeploy. `diakrin self-hosted status` shows the license state (`active`, `expiring` within 30 days, `expired` or `none`) and the two ids, and `doctor` lists it as a finding. You can also open the console's **License** step, choose **Import a license file** and paste or upload the file.

## Renew

Before the expiry date Diakrin sends you a new file. Run the same command with it:

```sh
diakrin self-hosted license update ./acme-license-renewed.json
```

## If it fails

| You see | It means | Do this |
| --- | --- | --- |
| `LICENSE_INSTALLATION_MISMATCH` (or the console says the file is not valid for this installation) | The ids in the file differ from this installation's | Send the ids from the **License** step to your Diakrin contact for a new file |
| `LICENSE_STALE` | The stored license has a higher revision than this file | Use the newest file Diakrin sent you |
| `NOT_INSTALLED` | `license update` ran before `deploy` | Run `deploy` first, or set `DIAKRIN_LICENSE_FILE` and deploy |
| The file is rejected as expired | The expiry date has passed | Ask your Diakrin contact for a renewal |
| `license` is an unknown command | Your CLI or release is too old | Run the install command again to update the CLI, then `diakrin self-hosted upgrade --to <version>` |

## Next

Back to [Operate your installation](/docs/self-hosted/operate).
