utils.cleanup package

Submodules

utils.cleanup.databases_csv module

Strip databases.csv rows for purged application entities.

utils.cleanup.databases_csv.main(argv: list[str]) → int
utils.cleanup.databases_csv.wipe_database_entries(app_ids: list[str], csv_file: Path | None = None) → list[str]

Remove rows whose database or username column matches an entity derived from app_ids via get_entity_name().

utils.cleanup.nginx_vhosts module

nginx vhost-file purge helper (entity-keyed).

Matrix-deploy variant transitions can leave per-domain nginx vhost configs behind: when a service drops out of a round’s include set, sys-svc-compose’s aggressive docker prune removes the container, but the vhost file under <NGINX_DIR>/conf.d/servers/{http,https}/<domain>.conf survives. The next round’s probe then gets HTTP 502 (nginx serves the vhost with no upstream) instead of the expected TLS-error 000.

The entity-keyed purge primitive scripts/container/purge/entity/nginx.sh (driven by the app-keyed orchestrator apps.sh as a sibling of db.sh, compose.sh, dir.sh) invokes this module to remove the vhost files belonging to a given compose entity. The mapping entity -> apps -> domains is resolved via utils.roles.entity.apps.apps_for_entity plus utils.domains.list.build_applications_from_roles / utils.domains.application_domain_index.iter_app_domains so the helper stays ansible-free and runnable inside the infinito container without a templar context.

utils.cleanup.nginx_vhosts.iter_vhost_files_for_entity(entity: str, *, nginx_dir: Path, domain_primary: str, roles_dir: Path = PosixPath('/data/work/latest/src/roles')) → Iterable[Path]

Yield existing vhost files (http + https) for every app belonging to entity, plus the www.<domain>.conf redirect variant and — when a node onion is provisioned (services.tor.node / the key file) — the dual-stack <sub>.<node-onion>.conf variant, so a dropped app leaves no stale onion vhost either. Only yields files that exist.

utils.cleanup.nginx_vhosts.main(argv: list[str]) → int
utils.cleanup.nginx_vhosts.purge_vhost_files_for_entities(entities: list[str], *, nginx_dir: Path | None = None, domain_primary: str | None = None, roles_dir: Path = PosixPath('/data/work/latest/src/roles')) → list[Path]

Remove vhost files for every entity in entities. Returns the list of paths that were actually removed (existed and unlink succeeded), in iteration order.

utils.cleanup.pycache_only_dirs module

Remove directories whose only child is a __pycache__ folder.

Such directories show up after Python test modules / source files are moved or deleted: the __pycache__ cache remains and the now-orphan parent directory holds nothing else. git clean -fdX does not touch the parent because the parent itself is tracked, so they stick around forever.

Run via python -m utils.cleanup.pycache_only_dirs (or make clean-pycache-dirs).

utils.cleanup.pycache_only_dirs.main() → int

utils.cleanup.tokens module

Token-store wipe helper.

The token store at /var/lib/infinito/secrets/tokens.yml survives compose+volumes purges. Matrix-deploy variant transitions wipe an app’s persistent state but the stale token would otherwise be reused on the next round (for example matomo’s API probe in sys-front-inj-matomo, whose token-empty guard never fires while the prior round’s token is still present). The purge orchestrator invokes this module to drop the matching users.<user>.tokens.<app_id> entries alongside the entity-level wipe.

utils.cleanup.tokens.main(argv: list[str]) → int
utils.cleanup.tokens.wipe_tokens(app_ids: list[str], tokens_file: Path | None = None) → list[str]

Remove users.<user>.tokens.<app_id> entries for app_ids.

Returns the list of removed <user>.<app_id> keys (empty when the file is missing or no entries matched). The file is rewritten only when at least one entry was removed.

Module contents