# Operate your installation

> Check, upgrade, roll back and remove an installation with the Diakrin CLI.

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

Five commands cover everything after the install: check it, upgrade it, roll it back and remove it.

## Before you start

| You supply | Example | Comes from |
| --- | --- | --- |
| The settings file | `diakrin.env` | The folder you installed from |
| AWS access | `aws sts get-caller-identity` works | The same account as the install |

Every command takes `--env diakrin.env`, plus `--profile`, `--region` and `--installation` to override it. Add `--json` for machine-readable output.

## Check the status

```sh
diakrin self-hosted status --env diakrin.env
```

You should see the installed version, the CLI version, whether an update is available and the running services.

## Run the health check

```sh
diakrin self-hosted doctor --env diakrin.env
```

You should see every check pass. If the GitHub webhook source ranges changed, refresh them:

```sh
diakrin self-hosted doctor --env diakrin.env --fix
```

## Upgrade

List the signed releases, then move to one:

```sh
diakrin self-hosted versions --env diakrin.env
```

```sh
diakrin self-hosted upgrade --to <version> --env diakrin.env
```

You should see a database snapshot, infrastructure changes, migrations and a rolling update, ending healthy. An upgrade must come from a version listed in **Upgrade from** on [Self-hosted releases](/docs/self-hosted/releases). `--to` is required. Run `doctor` afterwards.

## Roll back

```sh
diakrin self-hosted rollback --env diakrin.env
```

You should see the services return to the previous release's images. The database is not rolled back; the result names the snapshot taken before the upgrade. Rolling back after an upgrade needs CLI 0.1.7 or newer.

## Remove it

A person decides this and types the installation id. An agent never does.

```sh
diakrin self-hosted destroy --env diakrin.env --dry-run
```

You should see what would be removed and nothing changed.

> [!WARNING]
> Stop here until a person has read the list and confirmed the installation id. Destroy cannot be undone.

```sh
diakrin self-hosted destroy --env diakrin.env --confirm-installation <id>
```

You should see everything Diakrin created removed. The audit bucket, the state bucket and a final database snapshot are kept on purpose.

For a trial, `--purge-retained` also deletes the final snapshots, the audit bucket and the state bucket. The audit bucket can be deleted only if you set `DIAKRIN_AUDIT_RETENTION_DAYS=1` at install. That value is for trials and never for production.

```sh
diakrin self-hosted destroy --env diakrin.env --confirm-installation <id> --purge-retained
```

You should see nothing left of the installation except a KMS key waiting out its deletion period.

## If it fails

| You see | It means | Do this |
| --- | --- | --- |
| `UPGRADE_TARGET_REQUIRED` (exit 2) | `upgrade` needs `--to` | Pick a version from `versions` |
| `UPGRADE_SKIP` or `DOWNGRADE` (exit 5) | The release is not a valid next step | Upgrade from a version listed in **Upgrade from** |
| `NO_PREVIOUS` (exit 2) | There is no earlier release to return to | Nothing to roll back |
| `DESTROY_INCOMPLETE` (exit 1) | Part of the removal failed; nothing was forgotten | Run the same `destroy` command again |

## Next

See the [releases](/docs/self-hosted/releases), or [troubleshoot](/docs/self-hosted/troubleshooting) a problem.
