> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/documentation/deploy-and-administer/updating-the-platform.md).

# Updating the Platform

Upgrade an existing OctoXLabs installation online or offline, with the checks, backups and version-specific steps that go with it.

Upgrade OctoXLabs to a newer version. The update itself is three commands: stop the services, install the new package, start the services. Some versions need extra steps, listed below.

### Before you begin

* Applies to: OctoXLabs 6.x. Version-specific steps go back to 5.3.5 and one migration from 3.7.x to 4.0.0.
* Required role: root, or a user with `sudo`, on the server.
* You have the update package for your distribution (`.deb` or `.rpm`). Its name looks like `octoxlabs_YOUR_VERSION_amd64_DATE_update.deb`.
* You have read the release notes of every version between your current version and the target.
* You have a current backup (see the next section).

{% hint style="warning" %}
Always read the notes for the target version before you start. Some versions need extra commands, and a few change behaviour for users. For example, in 6.9.0 only the default admin user keeps the Admin role, and each user can have only one active session.
{% endhint %}

### Prepare for the upgrade

1. **Plan a maintenance window.** The services are stopped during the update.
2. **Back up first.** Take a backup of PostgreSQL and Elasticsearch before every upgrade. If you have never run a backup on this server, run the one-time setup first. Use a path on a separate physical disk if you can, and check that the disk has enough free space.

   ```bash
   sudo octox-ctl -x backup -s setup -p /path/to/backup
   sudo octox-ctl -x backup -s postgresql
   sudo octox-ctl -x backup -s elasticsearch
   ```
3. **Check the current state.** Run `sudo octox-ctl -x ps` and confirm that all services are running, and sign in to the console.
4. **Get the package.** For an online update, use the Online Update Service, which downloads the update for you. For an offline update, get the offline package from OctoXLabs and copy it to the server.
5. **Check the version-specific steps** below for every version you will pass.

### Update the server

The commands are the same online and offline. The only difference is how the package reaches the server.

{% stepper %}
{% step %}

#### Stop all services

```bash
sudo octox-ctl -x down
```

{% endstep %}

{% step %}

#### Install the update package

{% tabs %}
{% tab title="Debian and Ubuntu" %}

```bash
sudo dpkg -i octoxlabs_YOUR_VERSION_amd64_DATE_update.deb
```

{% endtab %}

{% tab title="Red Hat and CentOS" %}

```bash
sudo rpm -i --force octoxlabs_YOUR_VERSION_amd64_DATE_update.rpm
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

#### Start all services

```bash
sudo octox-ctl -x up
```

{% endstep %}

{% step %}

#### Run the version-specific steps

Apply any extra steps for the versions you have passed. See the next section.
{% endstep %}
{% endstepper %}

{% tabs %}
{% tab title="Online" %}
Use the Online Update Service when the server can reach OctoXLabs. It replaces the package install step: the download command fetches and applies the update, so you do not copy a package yourself.

1. Ask OctoXLabs to allow your external IP addresses. The service restricts access by IP, so also allow the connection in your firewall.
2. Sign in with the username and token OctoXLabs gives you: `octox-ctl -x update -s login`.
3. Check access and credentials: `octox-ctl -x update -s check`. If this returns an error, sign in again.
4. Stop the services: `octox-ctl -x down -s connector`, then `octox-ctl -x down -s app`.
5. Run the update: `octox-ctl -x update -s download`.
6. When it finishes, start the services: `octox-ctl -x up -s connector`, then `octox-ctl -x up -s app`.

For the full procedure, see Use Online Update Service.
{% endtab %}

{% tab title="Offline" %}
Use this path on servers without internet access. Get the offline update package from OctoXLabs, copy it to the server, and follow the steps above.
{% endtab %}
{% endtabs %}

### Version-specific steps

Apply these in addition to the standard update. Entries are listed newest first.

| Version | What to do                                                                                                                                                                                                   |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 6.9.0   | After the update, give the Admin role back to the users who need management settings. Only the default admin user keeps Admin. Tell users who share an account that each account now has one active session. |
| 6.2.0   | Jira jobs in Action Center are now split into on-premises and cloud. Existing Jira flows stop working until you update them. Tell the customer and update their Action Center flows.                         |
| 6.1.1   | Before you start a new discovery, create a new connector token, replace the token in **Settings > Connectors**, and run a connection test.                                                                   |
| 6.1.0   | Needs the patch procedure below.                                                                                                                                                                             |
| 6.0.0   | Check Elasticsearch health after every new inventory development. See the Elasticsearch steps below.                                                                                                         |
| 5.5.0   | For existing customers, run `docker exec -it octo.backend-django python manage.py move_to_nested` after the update. Offline installs do not need it.                                                         |
| 5.3.5   | A hostname can now belong to only one relation. Before the update, check the customer's relations so that each hostname is used in one relation only.                                                        |

#### New connector token

```bash
sudo octox-ctl -x token
```

Paste the output into **Settings > Connectors**, then run the connector connection test. If the test passes, you can keep using the product.

#### Patch procedure for 6.1.0

The order below is the one used during testing.

1. Stop the application: `octox-ctl -x down`.
2. Install the 6.1 package.
3. Copy `octoxlabs_61_patch.bz2` to `/tmp`, then run:

   ```bash
   cd /tmp
   tar -xjvf octoxlabs_61_patch.bz2
   cd octoxlabs_61_patch/
   ./upgrade_61.sh
   ./backup.sh
   ```
4. Check that `octoxlabs_postgres_backup.sql` in that folder is at least 100 KB.
5. Restore, then start:

   ```bash
   ./restore.sh
   octox-ctl -x up
   ```

#### Elasticsearch health after an upgrade

Run this when the logs show `No search context found for id [88]`, and after every new inventory development.

1. Check the cluster health.

   ```bash
   ELASTIC_PASSWORD=$(grep "ELASTICSEARCH_PASSWORD=" /opt/octoxlabs/data/.env | cut -d '=' -f2- | tr -d '\r')
   curl -s -k -u "elastic:$ELASTIC_PASSWORD" "https://localhost:19200/_cluster/health?pretty"
   ```

   If `status` is `green`, `unassigned_shards` is `0` and `active_shards_percent_as_number` is `100`, you are done.
2. Otherwise update the index template for new indexes.

   ```bash
   curl -X PUT -k -u "elastic:$ELASTIC_PASSWORD" "https://localhost:19200/_index_template/octo_assets_indexes" -H "Content-Type: application/json" -d '{"index_patterns": ["*-devices", "*-users", "*-vulnerabilities", "*-applications", "*-certificates", "*-ais", "*-services", "*-source-codes", "*-device", "*-user", "*-certificate", "*-service", "*-source-code", "*-ai", "octo-*", "connector-logs-*", "fetch-time-*", "merge-recommendation-*"],"priority": 1,"template": {"settings": {"number_of_replicas": 0}}}'
   ```
3. Update the indexes that already exist.

   ```bash
   curl -k -u "elastic:$ELASTIC_PASSWORD" "https://localhost:19200/_settings" -H "Content-Type: application/json" -d '{"index": {"number_of_replicas": 0}}' -X PUT
   ```
4. Run the health check again. If it is still not green, send the output of this command to the OctoXLabs development team.

   ```bash
   curl -s -k -u "elastic:$ELASTIC_PASSWORD" "https://localhost:19200/_cluster/allocation/explain?pretty" -X POST
   ```

<details>

<summary>Migrating from 3.7.x to 4.0.0</summary>

This one-time migration applies only to very old systems.

1. Copy the 4.0.0 update package and the migration assistant package to your home folder.
2. Install the update package: `dpkg -i octoxlabs_stable_4.0.0_amd64_DATE_update.deb`, or `rpm -i --force octoxlabs_stable_4.0.0_amd64_DATE_update.rpm`.
3. Install the migration assistant (`dpkg -i octoxlabs_migration_assistant.deb` or `rpm -i octoxlabs_migration_assistant.rpm`) and run `octoxlabs-migration-assistant`.
4. Clear the old indices: `docker exec -it octo.backend-django python manage.py clear_old_indices`.
5. Start the services with `octox-ctl -x up`, then set a new connector token as described above.

If you changed the Elasticsearch RAM configuration or any index settings by hand, configure them again afterwards.

</details>

### Update a remote connector

Remote connectors use their own **update** package, which replaces only the connector image. Before it installs, the package saves the connector's environment files (`.postgres`, `.cors`, `.django`, `.elastic`) and restores them afterwards, so you do not need to run setup again.

Stop the connector before you install the package:

```bash
sudo octox-connector-ctl -x down
```

Then install the update package:

{% tabs %}
{% tab title="Debian and Ubuntu" %}

```bash
sudo dpkg -i octoxlabs_connector_stable_YOUR_VERSION_amd64_BUILD_update.deb
```

{% endtab %}

{% tab title="Red Hat and CentOS" %}

```bash
sudo rpm -i --force octoxlabs_connector_stable_YOUR_VERSION_amd64_BUILD_update.rpm
```

{% endtab %}
{% endtabs %}

Start the connector again if it is not running, then check the version:

```bash
sudo octox-connector-ctl -x up
octox-connector-ctl -v
```

### Verify the result

* `sudo octox-ctl -x ps` shows all services running.
* You can sign in to the console and the data you expect is there.
* A connection test on the default connector, and on each remote connector, succeeds.
* The Elasticsearch health check reports `green`.
* A new discovery runs to completion.

### Roll back

If an update fails, restore from the backup you took before it.

1. Stop the affected services: `sudo octox-ctl -x down`.
2. Restore PostgreSQL first, then Elasticsearch. Each restore uses the most recent backup and overwrites the current data.

   ```bash
   sudo octox-ctl -x restore -s postgresql
   sudo octox-ctl -x restore -s elasticsearch
   ```
3. Start the services (`sudo octox-ctl -x up`) and check the system as described above.

For backup and server migration details, see Backup Restore and Migrate.

### Troubleshooting

| Symptom                                           | Cause                                                              | Fix                                                                                             |
| ------------------------------------------------- | ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
| `No search context found for id [88]` in the logs | Elasticsearch replicas are unassigned, so the cluster is `yellow`. | Follow the Elasticsearch steps.                                                                 |
| `dpkg` or `rpm` reports an error                  | The package does not match the distribution.                       | Use the `.deb` package on Debian-based systems and the `.rpm` package on Red Hat-based systems. |
| Jira flows in Action Center fail after 6.2.0      | Jira jobs were split into on-premises and cloud.                   | Update the Action Center flows.                                                                 |

### What's next?

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Backup Restore and Migrate</strong></td><td>Back up and restore PostgreSQL and Elasticsearch.</td><td></td></tr><tr><td><strong>Use Online Update Service</strong></td><td>Update from the OctoXLabs package server.</td><td></td></tr><tr><td><strong>Install a remote connector</strong></td><td>Add or rebuild a connector.</td><td></td></tr><tr><td><strong>OctoXLabs CTL Reference</strong></td><td>All octox-ctl commands.</td><td></td></tr></tbody></table>
