# Daemon Commands

Start, stop, and pin the port of the KuraDB background daemon with `kura`, `kura stop`, and `kura port`.

## Start the daemon

```bash
kura
```

The launcher:

1. Opens `~/.config/kuradb/daemon.log` in append mode for daemon output.
2. Starts the same executable with the internal `--daemon` argument in a new session, with stdin bound to `/dev/null`.
3. Polls `~/.config/kuradb/endpoint` every 100 ms for up to 10 seconds.
4. Prints the endpoint when ready, or exits with status 1 and a message directing you to `daemon.log`.

`--daemon` is an internal lifecycle argument rather than a normal user command. The launcher does not check for a daemon that is already running, so run `kura stop` before starting again.

## Configure the port

```bash
kura port set 8080
kura port clear
```

| Subcommand | Accepts | Effect |
|---|---|---|
| `set <port>` | An integer from 1 through 65535 | Writes `port` to `config.json`, stops a live daemon when present, then starts the daemon |
| `clear` | No argument | Removes the pin from `config.json`; deliberately does not restart, so the next manual start picks a random port |

An out-of-range or non-numeric port, or any other subcommand, prints usage and exits with status 2. Port selection rules are covered in [Network Settings](/configuration-network).

## Stop the daemon

```bash
kura stop
```

KuraDB reads the PID from `runtime.uid`, verifies it is alive, and sends `SIGTERM`. It polls for up to five seconds at 100 ms intervals, then sends `SIGKILL` if the process has not exited, and prints `stopped kura (PID <pid>)`.

| Condition | Output | Exit status |
|---|---|---|
| `runtime.uid` missing or unreadable | `stop: no running daemon found` | 1 |
| PID recorded but process not alive | `stop: daemon not running` | 1 |
| Signal delivery fails | `stop: <error>` | 1 |
