# Linux

Install kogut on Linux and configure its systemd service.

The install script downloads the static binary for x86_64 or aarch64, checks its SHA-256
checksum, and starts a systemd service when systemd is available.

## Install

Run as root or with `sudo`. The script needs `curl` or `wget`. To read it first:

```sh
curl -fsSL https://kogut.dev/install -o install.sh
less install.sh
sh install.sh
```

Or run it directly:

```sh
curl -fsSL https://kogut.dev/install | sh
```

Open `http://<server>:8484` and create your account with the setup token from the
journal or `/var/lib/kogut/setup-token` ([First run](https://docs.kogut.dev/getting-started/first-run/)):

```sh
journalctl -u kogut | grep setup_token
```

## Configure the service

The installer writes `/usr/local/bin/kogut` and `/etc/systemd/system/kogut.service`.
The service uses `DynamicUser` and keeps data in `/var/lib/kogut`, which systemd stores
at `/var/lib/private/kogut`. Edit [`kogut.toml`](https://docs.kogut.dev/reference/configuration/) there as
root.

Put service settings in a drop-in, so reinstalling does not overwrite them:

```sh
sudo systemctl edit kogut
```

For HTTPS through [Caddy on the same host](https://docs.kogut.dev/installation/caddy/#use-caddy-on-the-host), add:

```ini
[Service]
Environment=KOGUT_URL=https://kogut.acme.com
Environment=KOGUT_LISTEN=127.0.0.1:8484
```

Then restart the service:

```sh
sudo systemctl restart kogut
```

See [Environment variables](https://docs.kogut.dev/reference/environment-variables/), and
[install-script options](https://docs.kogut.dev/reference/environment-variables/#install-script) for a fixed
version or a binary-only install.

## Read logs

```sh
journalctl -u kogut -f
```

For more detail, add `Environment=RUST_LOG=debug` to the drop-in and restart.

## Install without systemd

Run the same installer, then start `kogut serve` under your supervisor, with `KOGUT_DATA`
set to a persistent directory and `KOGUT_LISTEN` to the address
([defaults](https://docs.kogut.dev/reference/environment-variables/)). Have the supervisor restart kogut
when it exits with an error; the database stays consistent.

## Install the agent

On each monitored server, run the command from **Hosts → Add a server**:

```sh
curl -fsSL https://kogut.dev/install | sh -s -- agent --server https://kogut.acme.com --token <token>
```

This installs `kogut-agent.service` and saves its connection settings in
`/etc/kogut/agent.env`, readable only by root. For both server and agent on one host, run
the installer once for each. See [Installing the agent](https://docs.kogut.dev/agent/installing/).

For the agent alone, the installer downloads the smaller
[agent-only build](https://docs.kogut.dev/reference/cli/#the-agent-only-build). Where `kogut` already runs
the server, it keeps the full binary, which runs the agent too.

To create the first account without the panel, call the setup endpoint of the
[HTTP API](https://docs.kogut.dev/reference/http-api/) with the setup token and an `Origin` matching the
panel.

## Shell completion

`kogut completions <shell>` prints a completion script. Save it where your shell looks
for completions, then open a new shell:

```sh
kogut completions bash > ~/.local/share/bash-completion/completions/kogut
kogut completions zsh > ~/.zfunc/_kogut   # a directory on $fpath, before compinit
kogut completions fish > ~/.config/fish/completions/kogut.fish
```

For zsh, the file must be named `_kogut`, and `~/.zshrc` needs
`fpath=(~/.zfunc $fpath)` before `compinit`.

## Uninstall

```sh
sudo systemctl disable --now kogut
sudo rm /etc/systemd/system/kogut.service /usr/local/bin/kogut
sudo systemctl daemon-reload
```

Data remains in `/var/lib/private/kogut`. Take a [backup](https://docs.kogut.dev/high-availability/backups/)
before removing it.
