# Agent updates

> How the agent keeps itself up to date, how to check a server's version, and how to restart, reinstall or remove the agent.

You install the agent once. After that it updates itself, so a server needs no visit when Clokeep publishes a new agent release. To install the agent on a new server, see [Install the agent](/docs/servers/install-agent).

## How the agent updates itself

Each time the agent checks in, the panel tells it which agent release is current. When that release is newer than the version it runs, the agent:

1. Stops picking up new runs, and lets the runs in progress finish.
2. Downloads the new version from the panel. It checks the SHA-256 checksum, and Clokeep's signature for that exact version and platform.
3. Starts the new version once to check that it reports the expected version number.
4. Puts it in place of the old one and restarts.

If any step fails, the old version keeps running. The agent tries that release again after 10 minutes.

The agent turns down a release older than its own, or one without Clokeep's signature, and keeps running its own version.

An agent on version 2 updates itself to version 3 like any other release. From version 3 on, an agent applies only releases that Clokeep signed.

A backup in progress is never cut short by an update. A server busy with a long backup updates after that backup.

## See a server's agent version

- In **Servers**, the **Agent version** column shows each server's version as a badge. Green means the server runs the current release or a later one. Yellow means it is behind. Hover over the badge to see the current release. On a narrow screen the column is hidden.
- On a server's page, **Agent version** shows the version with a green or amber dot. A server that is behind also shows **Latest is** and the current release under it.

On the page of a server whose agent has never checked in, **Agent version** reads **Not reported yet**.

## When a server stays behind

A yellow badge while a backup or restore is running is normal: the agent updates once it ends. If it stays yellow with nothing running:

<Steps>
<Step title="Check that the server is Online">
The agent updates only while it checks in. If the server shows **Offline**, see [Install the agent](/docs/servers/install-agent) for a server that stays Pending or turns Offline.
</Step>
<Step title="Read the agent's log">
On the server, look for the update in the log:

```bash Read the log
journalctl -u clokeep-agent
```

An update line reads `agent update to` and the version, then what happened:

- `failed:` and the reason.
- `refused:` and the reason, for example a release older than the agent's own, or one without a Clokeep signature.
- `skipped:`: this agent cannot update itself. Reinstall it.
- `pending` or `no longer requested`: routine.
</Step>
<Step title="Reinstall the agent">
If the update keeps failing or is refused, run the installer again. See the next section.
</Step>
</Steps>

<Note>
The panel refuses check-ins from an agent older than the oldest version Clokeep supports. Such a server shows **Offline**. Its agent still learns of the current release and updates itself, and the server comes back **Online** after the update.
</Note>

A few features need a recent agent. With an older one, the run fails at once with a message that says the agent on this server is too old, for example to recreate a deleted Plesk subscription. Update the agent, then run it again.

## Restart, reinstall or check the agent

Run these on the server.

Show the installed version:

```bash Version
clokeep-agent version
```

Check that the service runs, and restart it:

```bash Service
sudo systemctl status clokeep-agent
sudo systemctl restart clokeep-agent
```

<Warning>
Restarting or reinstalling the agent stops any backup or restore it is running. The panel then marks that run **Failed**. Do it outside your backup times.
</Warning>

To reinstall the current release, run the installer without a token:

```bash Reinstall
curl -fsSL https://app.clokeep.com/agent/install.sh | sudo bash -s -- --url 'https://app.clokeep.com'
```

The installer downloads the current agent from the panel, keeps the server's settings and key, and restarts the service. The server needs no new enrollment. When it finishes, the output includes:

```text Output
==> Agent installed and started
```

To enroll the server again, for example after **Revoke agent tokens**, generate a new install command on the server's page and run it as in [Install the agent](/docs/servers/install-agent).

Enrolling revokes the server's earlier agent keys at once. An agent still running on another machine with the old key can no longer reach the panel.

Enrolling again changes only the panel address and the agent's key in `/etc/clokeep-agent.yaml`. Your other changes to the file, such as [allowed folders](/docs/restores/files-databases#allowed-folders), are kept. If the file is no longer valid YAML, enrolling stops before it uses the install command, and says so. Fix or remove the file, then run the command again. Agents older than 3.2.0 wrote a new file with default settings instead.

## Remove the agent

To take the agent off a server, run:

```bash Remove
curl -fsSL https://app.clokeep.com/agent/install.sh | sudo bash -s -- --uninstall
```

The command stops the service, then removes:

- the Backups plugin from cPanel, or the Backups extension from Plesk, if the server has one
- the systemd service, the agent program and `/etc/clokeep-agent.yaml`
- the work folder `/var/lib/clokeep-agent`
- a work folder you set by hand as `work_dir` in that file, when it is named `clokeep-agent` or `.clokeep-agent` and owned by root, such as `/srv/clokeep-agent`. Any other folder stays, and the output says so.

Work folders named `.clokeep-agent` on other disks stay in place, and the output says so. See [Disk space and the work folder](/docs/servers/install-agent#disk-space-and-the-work-folder). Your backups on your storage are not touched. The server stays in the panel, shown as **Offline**, until you delete it there.

To delete it, open the server's page and click **More actions** > **Delete**. Its plans and their run history are deleted with it, and a run still queued or running is discarded. Its backups stay on your storage and show under **Browse Backups** as **Orphaned backups**, unless you tick **Also delete the backups from storage**. Backups you keep can still be browsed, downloaded and shared, but not restored to a server, and retention no longer deletes them. See [Browse a backup](/docs/restores/browse#orphaned-backups).

If the server is lost and you want its data back on another machine, do not delete it. See [Restore to a new server](/docs/restores/new-server).

## Next steps

<CardGroup cols="2">
<Card title="Install the agent" href="/docs/servers/install-agent" icon="term">
Put the agent on a new server.
</Card>
<Card title="How Clokeep works" href="/docs/how-clokeep-works" icon="book">
What the agent connects to, and what happens to a run when it stops.
</Card>
</CardGroup>
