<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="assets/hazine-bus-dark.png">
<img src="assets/hazine-bus.png" alt="hazine: a double-decker bus" width="200">
</picture>
</p>
# hazine
hazine runs a [DuckDB](https://duckdb.org) server that speaks the Quack
protocol, for a DuckLake catalog, on **localhost only**. Clients reach it
through an SSH tunnel.
It follows the pattern of DuckDB's own Quack deployment
([duckdb-quack-infra](https://github.com/duckdb/duckdb-quack-infra)): the
DuckDB CLI runs an init file that ends in `quack_serve`, and keeps serving for
as long as its stdin stays open. hazine replaces `sleep infinity | duckdb
-init init.sql` with a supervisor that:
- refuses any non-loopback listen address,
- checks that the CLI is DuckDB 2.0 or later,
- holds DuckDB's stdin open, and closes it to stop DuckDB cleanly on SIGTERM
(killing it after `--stop-timeout`),
- forwards DuckDB's output to its log (text or JSON), with the token and
other secrets redacted,
- restarts DuckDB with backoff, and exits non-zero after `--max-failures`
failed starts in a row, so systemd sees the failure.
nginx and TLS are not needed: the SSH tunnel provides authentication and
encryption, and Quack checks a token on top.
The DuckLake catalog lives in a Postgres server and the data in
S3-compatible object storage, both elsewhere. The catalog is DuckDB's main
database, so every Quack session uses it without `USE` or qualified names.
## Requirements
- Linux with systemd, for `hazine setup`
- A Postgres database for the catalog, and an S3 bucket for the data
- Rust ≥ 1.85 to build (`cargo install hazine`)
## Server setup
`hazine setup` does everything as root:
1. installs hazine as `/usr/local/bin/hazine`
2. downloads the DuckDB CLI (2.0.1 by default) as `/usr/local/bin/duckdb`
3. creates the `hazine` system user, home `/var/lib/hazine`
4. installs the `quack`, `ducklake`, `postgres` and `httpfs` extensions for it
5. attaches the lake once, to check the settings, creating the DuckLake
catalog with its data path the first time
6. writes `/etc/hazine/init.sql`, `/etc/hazine/hazine.env` (secrets, `0640
root:hazine`) and `/etc/systemd/system/hazine.service`, sized to the
machine's CPUs and RAM
7. enables and starts the service
Setup asks for the Postgres password and the S3 keys, without echoing them.
For unattended runs, pass them as `HAZINE_PG_PASSWORD`, `HAZINE_S3_KEY_ID` and
`HAZINE_S3_SECRET` in the environment. Flags work too, but other users can
see them in the process list.
```sh
sudo ~/.cargo/bin/hazine setup \
--pg-host db.example.org --pg-database ducklake --pg-user hazine \
--data-path s3://my-bucket/lake/ \
--s3-endpoint fsn1.your-objectstorage.com --s3-region fsn1 --s3-url-style path
```
Add `--dry-run` to see the plan and the files first (secrets redacted, no root
needed). Rerun setup to change settings. Secrets and the Quack token are kept
from the existing `hazine.env` unless you give new ones. A changed file is
kept as `<file>.bak`. If the lake check fails, nothing is written. The
service restarts only if something changed.
Postgres connections use `--pg-sslmode require` by default. The data path is
stored in the catalog the first time and cannot be changed by rerunning
setup.
## Connecting
```sh
ssh -N -L 1294:127.0.0.1:1294 <host>
```
```sql
LOAD quack;
FROM quack_query('quack:127.0.0.1:1294', 'SELECT count(*) FROM my_table',
token = '<QUACK_TOKEN>', disable_ssl = true);
```
Get the token on the server with
`sudo sed -n 's/^QUACK_TOKEN=//p' /etc/hazine/hazine.env`.
## Configuration
Precedence: flags > environment > defaults. See `hazine setup --help` and
`hazine serve --help`. These are the `serve` settings; `setup` writes them to
`hazine.env` and the unit.
| `--duckdb` | `HAZINE_DUCKDB` | `duckdb` (from `PATH`) |
| `--init` | `HAZINE_INIT` | `/etc/hazine/init.sql` |
| `--database` | `HAZINE_DATABASE` | in memory; setup: `ducklake:postgres:` |
| `--quack-addr` | `HAZINE_QUACK_ADDR` | `127.0.0.1:1294` |
| `--ready-timeout` | `HAZINE_READY_TIMEOUT` | `60` seconds |
| `--stop-timeout` | `HAZINE_STOP_TIMEOUT` | `30` seconds |
| `--max-failures` | `HAZINE_MAX_FAILURES` | `5` |
| `--log-format` | `HAZINE_LOG_FORMAT` | `text` (or `json`) |
The log level comes from `RUST_LOG` (default `info`).
## License
MIT