# systemd deployment

This directory contains the versioned systemd deployment used for the Debian runtime.

## Install

Run the installer as `root` and point it at the live runtime root:

```bash
cd /path/to/m2dev-server
python3 deploy/systemd/install_systemd.py \
  --user mt2.jakubkadlec.dev \
  --group mt2.jakubkadlec.dev \
  --runtime-root /home/mt2.jakubkadlec.dev/metin/runtime/server \
  --env-file /etc/metin/metin.env \
  --channel 1 \
  --channel 99 \
  --restart
```

`--channel-limit 1` is also supported and will auto-include channel `99` when present in the channel inventory.

By default the installer refuses channel selections that omit every client-visible public channel. If you intentionally want an auth/internal-only stack, pass `--allow-internal-only`.

The channel selection and port layout now come from the versioned inventory file:

- [deploy/channel-inventory.json](../channel-inventory.json)

## What it installs

- `metin-server.service`
- `metin-db.service`
- `metin-db-ready.service`
- `metin-auth.service`
- `metin-game@.service`
- `/usr/local/libexec/metin-game-instance-start`
- `/usr/local/libexec/metin-wait-port`
- `/usr/local/bin/metinctl`
- `/usr/local/sbin/metin-collect-incident`
- `/usr/local/sbin/metin-core-backtrace`

The `metin-db-ready.service` gate waits until the DB socket is actually accepting connections before `auth` and `game` units start.

The installer also reconciles enabled `metin-game@...` instances against the selected channel set so stale units do not stay enabled forever.

The runtime unit templates now also set `LimitCORE=infinity` for `db`, `auth`, and `game` services.

## Optional Environment File

The runtime units support an optional `EnvironmentFile` for host-local overrides:

- default path: `/etc/metin/metin.env`
- it is loaded with `EnvironmentFile=-...`, so the file may be absent
- recommended ownership: `root:root`
- recommended mode: `0600`

This is the preferred place for production-only values such as DB credentials and the admin page password.
