# tops.ng1–ng3 (podman compose) — start on user session / boot (linger)
#
# On koopa as hernani:
#   mkdir -p ~/.config/systemd/user
#   cp deploy/container-koopa-tops.service ~/.config/systemd/user/
#   systemctl --user daemon-reload
#   systemctl --user enable --now container-koopa-tops.service
#
# Once as root (if not already): loginctl enable-linger hernani

[Unit]
Description=Podman koopa-tops (tops.ng1–ng3 static nginx)
Documentation=file:///home/hernani/koopa-tops/README.md
Wants=network-online.target
After=network-online.target
RequiresMountsFor=%t/containers /home/hernani/koopa-tops

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/hernani/koopa-tops
Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=on-failure
RestartSec=15
TimeoutStartSec=120
TimeoutStopSec=60

ExecStartPre=/bin/bash -c "chmod -R a+rX /home/hernani/koopa-tops/ng1 /home/hernani/koopa-tops/ng2 /home/hernani/koopa-tops/ng3 2>/dev/null || true"

ExecStart=/bin/bash -c "if podman compose version >/dev/null 2>&1; then podman compose -f deploy/compose.yml up -d; elif command -v podman-compose >/dev/null 2>&1; then podman-compose -f deploy/compose.yml up -d; else echo \"no podman compose\" >&2; exit 1; fi"

ExecStop=/bin/bash -c "if podman compose version >/dev/null 2>&1; then podman compose -f deploy/compose.yml stop; elif command -v podman-compose >/dev/null 2>&1; then podman-compose -f deploy/compose.yml stop; else podman stop koopa-tops-ng1 koopa-tops-ng2 koopa-tops-ng3 2>/dev/null || true; fi"

[Install]
WantedBy=default.target
