#!/usr/bin/env bash
# Real demos for P101 "How to Fix a Linux systemd Service That Won't Start". Made on the Mac (Docker Desktop), like
# P074 and P100. One container, "shop": a stock Ubuntu 24.04 with systemd as PID 1 (lab/Dockerfile.server). Ana's tea
# shop app (lab/teashop/, later lab/v2/app.py) and her unit file (lab/teashop.service, with the classic python vs
# python3 mistake) are copied in, as if she wrote them in nano. Every command shown is typed into a real interactive
# bash in a pty (demo_driver.py); sudo's password prompt is answered by the driver, so the window shows the prompt
# and nothing typed. The app only listens inside the container.
set -euo pipefail
cd "$(dirname "$0")"
cleanup() { docker rm -f ce-p101-server >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t ce-p101-server -f lab/Dockerfile.server lab >/dev/null
docker run -d --name ce-p101-server --hostname shop \
  --privileged --cgroupns=private -v /sys/fs/cgroup:/sys/fs/cgroup:rw --tmpfs /run --tmpfs /run/lock \
  ce-p101-server >/dev/null
python3 - ce-p101 < demo_driver.py
