Spaces:
Paused
Paused
| set -euo pipefail | |
| LOG_PREFIX="[playit-entrypoint]" | |
| PLAYIT_ENV_BIN="${PLAYIT_BIN:-}" | |
| CANDIDATE_PATHS=( | |
| "/usr/bin/playit" | |
| "/usr/local/bin/playit" | |
| "/opt/playit/playit" | |
| ) | |
| PLAYIT_LOG="/tmp/playit.log" | |
| PLAYIT_SECRET_VAR="${PLAYIT_SECRET:-}" | |
| # cp "/usr/local/nginx/sbin/nginx" "/tmp/nginx/sbin/nginx" | |
| # NGINX_BIN="/tmp/nginx/sbin/nginx" | |
| NGINX_CONF="/tmp/nginx/nginx.conf" | |
| NGINX_ORIG_CONF_DIR="/usr/local/nginx/conf" | |
| LOG_DIR="/tmp/nginx/logs" | |
| PROXY_TEMP="/tmp/nginx/proxy_temp" | |
| if [ -x "/usr/local/nginx/sbin/nginx" ]; then | |
| mkdir -p /tmp/nginx/sbin | |
| # Then copy the binary | |
| cp /usr/local/nginx/sbin/nginx /tmp/nginx/sbin/nginx | |
| chmod +x /tmp/nginx/sbin/nginx | |
| NGINX_BIN="/tmp/nginx/sbin/nginx" | |
| else | |
| echo "$LOG_PREFIX nginx binary not found at /usr/local/nginx/sbin/nginx" >&2 | |
| exit 1 | |
| fi | |
| echo "$LOG_PREFIX starting entrypoint..." | |
| determine_playit_bin() { | |
| if [ -n "${PLAYIT_ENV_BIN:-}" ]; then | |
| if [ -x "$PLAYIT_ENV_BIN" ]; then | |
| echo "$PLAYIT_ENV_BIN" | |
| return 0 | |
| else | |
| echo "$LOG_PREFIX PLAYIT_BIN is set but not executable: $PLAYIT_ENV_BIN" >&2 | |
| return 1 | |
| fi | |
| fi | |
| if command -v playit >/dev/null 2>&1; then | |
| command -v playit | |
| return 0 | |
| fi | |
| for p in "${CANDIDATE_PATHS[@]}"; do | |
| if [ -x "$p" ]; then | |
| echo "$p" | |
| return 0 | |
| fi | |
| done | |
| return 1 | |
| } | |
| # Find binary | |
| if PLAYIT_BIN_PATH="$(determine_playit_bin)"; then | |
| echo "$LOG_PREFIX playit binary found: $PLAYIT_BIN_PATH" | |
| else | |
| echo "$LOG_PREFIX playit binary NOT found. Will continue but playit won't run." >&2 | |
| PLAYIT_BIN_PATH="" | |
| fi | |
| # Prepare playit log | |
| rm -f "$PLAYIT_LOG" || true | |
| touch "$PLAYIT_LOG" | |
| chmod 600 "$PLAYIT_LOG" || true | |
| PLAYIT_PID=0 | |
| start_playit() { | |
| if [ -n "${PLAYIT_BIN_PATH}" ] && [ -n "${PLAYIT_SECRET_VAR}" ]; then | |
| echo "$LOG_PREFIX starting playit agent..." | |
| # quote secret to avoid word-splitting; use nohup so it doesn't die when shell exits | |
| nohup "$PLAYIT_BIN_PATH" --secret "$PLAYIT_SECRET_VAR" start >>"$PLAYIT_LOG" 2>&1 & | |
| PLAYIT_PID=$! | |
| echo "$LOG_PREFIX Playit agent started with PID=$PLAYIT_PID" | |
| else | |
| if [ -z "${PLAYIT_BIN_PATH}" ]; then | |
| echo "$LOG_PREFIX playit binary not available; skipping playit startup" | |
| else | |
| echo "$LOG_PREFIX PLAYIT_SECRET not provided; skipping playit startup" | |
| fi | |
| fi | |
| } | |
| stop_playit() { | |
| if [ "$PLAYIT_PID" -ne 0 ] && kill -0 "$PLAYIT_PID" >/dev/null 2>&1; then | |
| echo "$LOG_PREFIX stopping playit (pid=$PLAYIT_PID)" | |
| kill "$PLAYIT_PID" || true | |
| sleep 1 | |
| kill -9 "$PLAYIT_PID" 2>/dev/null || true | |
| fi | |
| } | |
| # Trap termination to stop playit cleanly | |
| trap 'echo "$LOG_PREFIX received termination signal"; stop_playit; exit 0' TERM INT | |
| # Start playit (if configured) | |
| start_playit | |
| echo "$LOG_PREFIX starting nginx..." | |
| mkdir -p /tmp/nginx/{logs,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp,sbin,html} | |
| # chmod 1777 /tmp/nginx/logs /tmp/nginx/proxy_temp | |
| # chmod 1777 /tmp/nginx/fastcgi_temp /tmp/nginx/uwsgi_temp /tmp/nginx/scgi_temp | |
| #chmod 1777 /tmp/nginx /tmp/media | |
| NGINX_PREFIX="/tmp/nginx" | |
| exec "$NGINX_BIN" -c "$NGINX_CONF" -p "$NGINX_PREFIX" -g "daemon off;" | |
| # exec "$NGINX_BIN" -c "$NGINX_CONF" -g "daemon off;" | |
| echo "$LOG_PREFIX nginx started" |