start.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Remove lingering .sock files, relayd and unixhttpd will do that too but
  4. # measure twice, cut once.
  5. rm *.sock ||:
  6. # If the transient local TLS certificate doesn't exist, mint a new one
  7. if [ ! -f ../pki/relayd.local.cetacean.club/cert.pem ]; then
  8. # Subshell to contain the directory change
  9. (
  10. cd ../pki \
  11. && mkdir -p relayd.local.cetacean.club \
  12. && \
  13. # Try using https://github.com/FiloSottile/mkcert for better DevEx,
  14. # but fall back to using https://github.com/jsha/minica in case
  15. # you don't have that installed.
  16. (
  17. mkcert \
  18. --cert-file ./relayd.local.cetacean.club/cert.pem \
  19. --key-file ./relayd.local.cetacean.club/key.pem relayd.local.cetacean.club \
  20. || go tool minica -domains relayd.local.cetacean.club
  21. )
  22. )
  23. fi
  24. # Build static assets
  25. (cd ../.. && npm ci && npm run assets)
  26. # Spawn three jobs:
  27. # HTTP daemon that listens over a unix socket (implicitly ./unixhttpd.sock)
  28. go run ../cmd/unixhttpd &
  29. # A copy of Anubis, specifically for the current Git checkout
  30. go tool anubis \
  31. --bind=./anubis.sock \
  32. --bind-network=unix \
  33. --policy-fname=../anubis_configs/aggressive_403.yaml \
  34. --target=unix://$(pwd)/unixhttpd.sock &
  35. # A simple TLS terminator that forwards to Anubis, which will forward to
  36. # unixhttpd
  37. go run ../cmd/relayd \
  38. --proxy-to=unix://./anubis.sock \
  39. --cert-dir=../pki/relayd.local.cetacean.club &
  40. # When you press control c, kill all the child processes to clean things up
  41. trap 'echo signal received!; kill $(jobs -p); wait' SIGINT SIGTERM
  42. echo "open https://relayd.local.cetacean.club:3004/reqmeta"
  43. # Wait for all child processes to exit
  44. wait