# Exercise 18 — Deploy VisitCounter via Quadlets

podman pull postgres:16-alpine
podman pull nginx:1.27-alpine
podman build -t localhost/visitcounter:latest listings/visitcounter/app/

# nginx config an Ort und Stelle bringen (Quadlet-Version mit systemd-visitcounter-app als Hostname)
mkdir -p ~/visitcounter/nginx
cp listings/visitcounter/quadlets/nginx-default.conf ~/visitcounter/nginx/default.conf

# Create the Quadlet directory
mkdir -p ~/.config/containers/systemd/

# Copy all Quadlet unit files
cp listings/visitcounter/quadlets/* ~/.config/containers/systemd/

# Reload systemd to pick up the new units
systemctl --user daemon-reload

# Check that units were generated
systemctl --user list-unit-files | grep visitcounter
# → visitcounter-app.service     generated
# → visitcounter-db.service      generated
# → visitcounter-proxy.service   generated

# Start only the proxy — systemd resolves After= dependencies automatically
systemctl --user start visitcounter-proxy.service

# Verify all three services are running
systemctl --user status visitcounter-db.service
systemctl --user status visitcounter-app.service
systemctl --user status visitcounter-proxy.service

# Test
curl localhost:8080

# Bonus: kill the app container and watch systemd restart it
podman stop systemd-visitcounter-app
systemctl --user status visitcounter-app.service
