mithlond-public/OKF/guides/maintenance.md
Lukasz Boryn c12604ebb4 feat(template): publish the Mithlond self-hosted Gitea template
A spare-machine Gitea forge, hardened, backed up and with CI, as a template.
Personal values are placeholders listed in the README.
2026-10-16 15:04:18 +02:00

118 lines
4.5 KiB
Markdown

---
type: Guide
purpose: Keep the server updated and healthy across reboots.
answers:
- "How is the server updated, rebooted and worked on?"
---
# Maintenance: Updates, Reboots, Working on the Server
How to update the box without losing anything, how to prove it came back,
and what the server does and does not have. All of it learned the hard way on the
reference server.
## The server environment
Know these before typing commands on mithlond:
| Missing / different | Use instead |
|---|---|
| no `nano`, no `vi` | `sed -i` one-liners (all docs use them); `vim` **is** installed |
| no `hostname` (no `inetutils`) | `uname -n` |
| no `git` | `git` inside the gitea image: `docker run --rm --entrypoint git gitea/gitea:1.23 …` |
| no `rsync` | copy a file: `ssh -p 2234 admin@192.168.1.50 'cat > ~/mithlond/<path>' < <path>`; a tree: `tar -cz … \| ssh … 'tar -xz -C …'` |
| no `dig` | `getent hosts <name>` |
| no passwordless `sudo` | root steps run in your own terminal over SSH |
| `/tmp` is a **1.5G tmpfs** | big scratch work goes to `~` or `/var/tmp` |
| admin SSH LAN-only | from outside: router WireGuard first ([03 §7](03-ssh-hardening.md#7-remote-admin-wireguard-never-a-port-forward)) |
Typing hazards that cost time in practice — paste these, don't retype:
- `umount`, not `unmount`; `/dev/disk/by-label/BACKUP`, not `/dev/dick/…`,
and never `/dev/sdX` by hand (an `sda1`/`sdb1` slip hit `/boot`).
- `sudo systemctl daemon-reload` — `daemon-reload` alone is not a command.
- A shell `cd`'d into a mount keeps it busy; the prompt `[… mithlond]$` looks
the same in `/mnt/backup/mithlond` and `~/mithlond`. `cd ~` first.
- **Long one-liners break when pasted** (a paste once lost everything after
`qemu-system-x86_64`). Anything over one line belongs in a script under
`scripts/`.
## System update
### 1. Back up first
```bash
sudo systemctl start gitea-backup # nightly job, run now ([11](11-backup-automated.md))
journalctl -u gitea-backup -n 20 --no-pager # "snapshot … saved", Result success
```
Optionally also a standalone tar archive: `~/mithlond/scripts/backup.sh` ([10](10-backup-manual.md)).
### 2. Upgrade — always the whole system
```bash
sudo pacman -Syu
```
Never `pacman -S <pkg>` on its own after a long gap: if the local package
database is stale, mirrors answer `404` for the old file names (seen
installing `ntfs-3g` — every mirror 404'd until one still had the
old build). Installing against a stale database is a partial upgrade, which
Arch does not support. If you see a wall of 404s, stop and run `-Syu`.
### 3. Reboot if the kernel changed
`pacman -Syu` **deletes the running kernel's modules**. Until reboot, anything
that loads a module fails — e.g. mounting the backup drive (`ntfs3`). A Docker upgrade
also leaves the old daemon running until reboot.
```bash
uname -r # running kernel
ls /usr/lib/modules # installed — if uname -r is not listed, reboot now
grep -E 'upgraded (linux|docker|containerd) ' /var/log/pacman.log | tail -3
sudo reboot
```
An old laptop takes a few minutes to come back (slow HDD, slow USB spin-up).
## After every reboot — verify
On the server:
```bash
uname -r # the new kernel
systemctl is-active mithlond fail2ban ddclient docker # all active (+ your apex site's unit)
systemctl show nftables -p Result # Result=success ("inactive" is normal: oneshot)
sudo nft list table inet filter | head -5 # table present, "policy drop"
docker ps --format '{{.Names}} {{.Status}}' # caddy, gitea, runner Up (+ the apex site)
systemctl list-timers gitea-backup.timer # NEXT = next 03:30
```
Judge the firewall by the table, never by `systemctl is-active nftables`.
From any machine:
```bash
curl -sI https://git.example.com | head -1 # 200
curl -sI https://example.com | head -1 # 200
curl -sI https://www.example.com | head -1 # 301 → apex
ssh -T -p 2222 git@git.example.com # "Hi there, …"
```
A `502` for ~20 s right after boot is Gitea still starting behind Caddy.
### `enabled` is not `started`
A unit can show `enabled` but `inactive (dead)`: it had
been enabled after the previous boot without `--now`, and the container was
started by hand. Only a reboot proves an autostart unit. When enabling a unit,
use `sudo systemctl enable --now <unit>`, and count it as proven only after
the next reboot brings it up.
## Log
| Date | Change | Verified |
|---|---|---|
| YYYY-MM-DD | `pacman -Syu`: kernel, docker, containerd versions; reboot | all checks above green |