#!/usr/bin/env bash
# Real demos for P116 "Linux Logs: syslog vs journald". Run on render01 (Docker).
# Two containers on their own Docker network, each a stock Ubuntu 24.04 with systemd as PID 1 and the packages
# Ubuntu Server installs for logging (journald, rsyslog, logrotate): "shop" runs Ana's tea shop as a systemd service
# (lab/teashop/, lab/teashop.service), "logs" is a central log server (lab/10-remote.conf). 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.
# Config files are copied in as if Ana wrote them in nano. Nothing leaves the Docker network.
set -euo pipefail
cd "$(dirname "$0")"
P=ce-p116
cleanup() { docker rm -f $P-shop $P-logs >/dev/null 2>&1 || true; docker network rm $P-net >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t $P-server -f lab/Dockerfile.server lab >/dev/null
docker network create $P-net >/dev/null
for h in logs shop; do
  docker run -d --name $P-$h --hostname $h --network $P-net --network-alias $h --privileged --cgroupns=private \
    --tmpfs /run --tmpfs /run/lock $P-server >/dev/null
done
python3 - $P < demo_driver.py
