run 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. echo never > /sys/kernel/mm/transparent_hugepage/enabled
  4. redis-server /racket/config/redis.conf &
  5. export PLT_INCREMENTAL_GC=1
  6. CORES=$(("$(nproc --all)" * 1))
  7. CONF="/racket/config/upstream.conf"
  8. cat >"$CONF" <<EOF
  9. upstream app {
  10. least_conn;
  11. EOF
  12. for i in $(seq 0 $CORES); do
  13. port=$((8081 + i))
  14. /racket/app "$port" &
  15. echo " server unix:///racket/$port.sock;" >> "$CONF"
  16. done
  17. cat >>"$CONF" <<EOF
  18. keepalive 512;
  19. }
  20. EOF
  21. for i in $(seq 0 $CORES); do
  22. port=$((8081 + i))
  23. filename="/racket/$port.ready"
  24. while [ ! -f "$filename" ]; do
  25. echo "Waiting for $filename..."
  26. sleep 0.25;
  27. done
  28. chmod 0777 "/racket/$port.sock"
  29. done
  30. export NGINX_WORKER_PROCESES=$(("$CORES" / 4))
  31. envsubst '$NGINX_WORKER_PROCESES' < /racket/config/nginx.conf.tpl > /racket/config/nginx.conf
  32. cat /racket/config/upstream.conf
  33. nginx -c /racket/config/nginx.conf