Spaces:
Running
Running
Download deploy_vps.sh from AkshithSurya/spherex-projects: direct link, hf CLI and curl.
- Browser
- Download file 2.83 kB
-
https://huggingface.co/spaces/AkshithSurya/spherex-projects/resolve/main/deploy_vps.sh
- Command line
-
hf download hf://spaces/AkshithSurya/spherex-projects/deploy_vps.sh
-
curl -L -o deploy_vps.sh https://huggingface.co/spaces/AkshithSurya/spherex-projects/resolve/main/deploy_vps.sh
2.83 kB
| set -euo pipefail | |
| APP_DIR="/opt/spherex-explorer" | |
| APP_USER="www-data" | |
| APP_PORT=8000 | |
| echo ">>> [1/6] Installing system packages..." | |
| apt-get update | |
| apt-get install -y --no-install-recommends \ | |
| python3 \ | |
| python3-pip \ | |
| python3-venv \ | |
| nginx \ | |
| curl \ | |
| git | |
| echo ">>> [2/6] Preparing application directory at ${APP_DIR}..." | |
| mkdir -p "${APP_DIR}" | |
| mkdir -p "${APP_DIR}/hips_cache" | |
| mkdir -p "${APP_DIR}/spherex_data" | |
| mkdir -p "${APP_DIR}/spherex_mosaics" | |
| if [ -f "./s.py" ] && [ "$(pwd)" != "${APP_DIR}" ]; then | |
| echo "Copying repository files from $(pwd) to ${APP_DIR}..." | |
| rsync -av --exclude="spherex_data/*.fits" --exclude=".git" --exclude="*.Identifier" ./ "${APP_DIR}/" | |
| fi | |
| echo ">>> [3/6] Setting up Python virtual environment..." | |
| python3 -m venv "${APP_DIR}/venv" | |
| "${APP_DIR}/venv/bin/pip" install --upgrade pip | |
| "${APP_DIR}/venv/bin/pip" install -r "${APP_DIR}/requirements.txt" | |
| echo ">>> [4/6] Setting permissions..." | |
| chown -R "${APP_USER}:${APP_USER}" "${APP_DIR}" | |
| chmod -R 775 "${APP_DIR}/hips_cache" "${APP_DIR}/spherex_data" "${APP_DIR}/spherex_mosaics" | |
| echo ">>> [5/6] Creating systemd service..." | |
| cat <<EOF > /etc/systemd/system/spherex.service | |
| [Unit] | |
| Description=SPHEREx Data Explorer Backend Service | |
| After=network.target | |
| [Service] | |
| Type=simple | |
| User=${APP_USER} | |
| Group=${APP_USER} | |
| WorkingDirectory=${APP_DIR} | |
| Environment="SPHEREX_ALLOW_REMOTE=1" | |
| Environment="PORT=${APP_PORT}" | |
| Environment="PYTHONUNBUFFERED=1" | |
| ExecStart=${APP_DIR}/venv/bin/python3 ${APP_DIR}/s.py | |
| Restart=always | |
| RestartSec=5 | |
| ProtectSystem=full | |
| PrivateTmp=true | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOF | |
| systemctl daemon-reload | |
| systemctl enable --now spherex.service | |
| echo ">>> [6/6] Configuring Nginx reverse proxy..." | |
| cat <<'EOF' > /etc/nginx/sites-available/spherex | |
| server { | |
| listen 80; | |
| server_name _; | |
| client_max_body_size 64M; | |
| location / { | |
| proxy_pass http://127.0.0.1:8000; | |
| proxy_http_version 1.1; | |
| proxy_set_header Host $host; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header X-Forwarded-Proto $scheme; | |
| proxy_read_timeout 120s; | |
| proxy_send_timeout 120s; | |
| } | |
| } | |
| EOF | |
| ln -sf /etc/nginx/sites-available/spherex /etc/nginx/sites-enabled/spherex | |
| rm -f /etc/nginx/sites-enabled/default | |
| nginx -t && systemctl reload nginx | |
| echo "==============================================================================" | |
| echo "Deployment Complete!" | |
| echo "SPHEREx Data Explorer is running on systemd (port 8000) and Nginx (port 80)." | |
| echo "Check status: systemctl status spherex" | |
| echo "Check logs: journalctl -u spherex -f" | |
| echo "To add HTTPS: certbot --nginx -d your-domain.com" | |
| echo "==============================================================================" | |