Repository navigation
Machines and Servers
ops/server.py for a machine over ssh and system.py for this one.
Looking after a machine over ssh: logs, systemd, podman, new rootless containers. Called by its path, not
installed into projects: a server is a machine, not a project. The machines are tables in
~/.config/devscripts/servers.toml, outside the checkout, so their names and layout never end up here:
[web]
ssh = "web" # the alias in ~/.ssh/config, never the address
data_directory = "services" # where `new` keeps a service's data, under the home directory
after_new = "..." # what `new` reminds you of afterwards (optional)
timezone = "Europe/Berlin" # TZ of the containers `new` creates (optional)What differs between machines belongs in that table, never in server.py. A three-line wrapper per machine
(from server import main; main("web")) saves typing the name.
python3 ~/dev/tools/devscripts/ops/server.py web logs app --grep "proxy|scanner" --since "-90min"
python3 ~/dev/tools/devscripts/ops/server.py web ps | stats | timers | status UNIT | cat UNIT
python3 ~/dev/tools/devscripts/ops/server.py web ps shop -a --ports # one stack's containers, also the exited, with ports
python3 ~/dev/tools/devscripts/ops/server.py web logs shop_app_1 --container --grep "error|warn" --since -30min
python3 ~/dev/tools/devscripts/ops/server.py web exec shop_db_1 psql -U shop -tAc "select 1"
python3 ~/dev/tools/devscripts/ops/server.py web put compose.override.yaml services/shop/ # a file to the server, relative to ~
python3 ~/dev/tools/devscripts/ops/server.py web get services/shop/.env /tmp/shop.env # and back
python3 ~/dev/tools/devscripts/ops/server.py web restart app --wait # also start, stop; --wait: fail unless active
python3 ~/dev/tools/devscripts/ops/server.py web update [--apply] # podman auto-update, a dry run by default
python3 ~/dev/tools/devscripts/ops/server.py web install app.container --restart # scp, daemon-reload, restart
python3 ~/dev/tools/devscripts/ops/server.py web new something --image ghcr.io/vendor/something:latest \
--port 1234:8080 --volume config:/config [--network N] [--dry-run]Everything is rootless (sudo would ask for a password over ssh). logs takes the unit name, which is not always the
container name, and filters entries: a traceback is one journal line per line, so a line-wise grep returns the
message without its trace.
A container that is no unit - the services of a podman-compose stack - has no journal to read: logs NAME --container
reads podman logs instead, through the same entry grouping and the same --grep, --exclude, --since (-30min
is turned into the 30m podman wants). ps NAME lists only the containers whose name contains NAME and leaves out the
failed-units list; -a adds the ones that exited (a compose migrator), --ports a column with the published ports.
For a project's own containers deploy.py logs --target NAME does the same by the target's container name.
new writes a quadlet unit: %h/<data_directory>/<name>/…, :Z, TZ when the machine sets one,
AutoUpdate=registry, WantedBy=default.target. It creates the data directories, refuses to overwrite an existing
unit, runs daemon-reload, starts the unit and waits for it to be active. What it cannot do is the proxy host and the
DNS record; after_new says which. server.test.py checks the grouping and the generated unit.
The same questions asked of this machine instead of a server: the journal, systemd units, processes. Read-only, so nothing needs sudo. Called by its path.
python3 ~/dev/tools/devscripts/system.py logs sshd # a unit: last 60 entries of the last 6 hours
python3 ~/dev/tools/devscripts/system.py logs --process steam --grep "error|fail" --exclude "vulkan|shader"
python3 ~/dev/tools/devscripts/system.py logs --kernel --grep "usb|xpad" --boot -1 # the kernel log of the previous boot
python3 ~/dev/tools/devscripts/system.py logs --priority err --since "-2h" # everything at error level or worse
python3 ~/dev/tools/devscripts/system.py failed | timers | boots | units PATTERN | status UNIT | cat UNIT
python3 ~/dev/tools/devscripts/system.py ps PATTERN # processes by regex, with the unit each belongs to
python3 ~/dev/tools/devscripts/system.py blame # boot time and the slowest unitslogs narrows by source (a unit, --process NAME, --kernel, or everything), by time (--since, or --boot [N] for
a whole boot), by --priority, then by --grep / --exclude - the entry filter of server.py, imported from it. A
unit is looked up as a user unit first and as a system unit second, so the scope does not have to be known; --user /
--system force one. journalctl -k only ever shows one boot, whatever --since says: an older kernel log is
--kernel --boot -1. system.test.py checks the journalctl call.