Spaces:
Runtime error
Runtime error
Delete start_backend.sh with huggingface_hub
Browse files- start_backend.sh +0 -109
start_backend.sh
DELETED
|
@@ -1,109 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
set -e
|
| 3 |
-
|
| 4 |
-
echo "=== Starting backend services ==="
|
| 5 |
-
|
| 6 |
-
# ββ Download sub2api binary (cached in persistent storage) ββ
|
| 7 |
-
SUB2API_BIN="/data/sub2api/sub2api"
|
| 8 |
-
SUB2API_VER="0.1.136"
|
| 9 |
-
if [ ! -f "$SUB2API_BIN" ]; then
|
| 10 |
-
echo "Downloading sub2api v${SUB2API_VER}..."
|
| 11 |
-
ARCH=$(uname -m)
|
| 12 |
-
if [ "$ARCH" = "x86_64" ]; then SUFFIX="linux_amd64"; else SUFFIX="linux_arm64"; fi
|
| 13 |
-
URL="https://github.com/Wei-Shaw/sub2api/releases/download/v${SUB2API_VER}/sub2api_${SUB2API_VER}_${SUFFIX}.tar.gz"
|
| 14 |
-
echo "URL: $URL"
|
| 15 |
-
mkdir -p /data/sub2api /tmp/sub2api_dl
|
| 16 |
-
for attempt in 1 2 3; do
|
| 17 |
-
echo "Download attempt $attempt..."
|
| 18 |
-
if wget --timeout=180 -q "$URL" -O /tmp/sub2api_dl/sub2api.tar.gz; then
|
| 19 |
-
echo "wget download successful"
|
| 20 |
-
break
|
| 21 |
-
elif curl --max-time 180 -sL "$URL" -o /tmp/sub2api_dl/sub2api.tar.gz; then
|
| 22 |
-
echo "curl download successful"
|
| 23 |
-
break
|
| 24 |
-
else
|
| 25 |
-
echo "Download failed, retrying in 10s..."
|
| 26 |
-
sleep 10
|
| 27 |
-
fi
|
| 28 |
-
done
|
| 29 |
-
if [ ! -f /tmp/sub2api_dl/sub2api.tar.gz ] || [ ! -s /tmp/sub2api_dl/sub2api.tar.gz ]; then
|
| 30 |
-
echo "ERROR: Failed to download sub2api after 3 attempts"
|
| 31 |
-
exit 1
|
| 32 |
-
fi
|
| 33 |
-
tar -xzf /tmp/sub2api_dl/sub2api.tar.gz -C /tmp/sub2api_dl/
|
| 34 |
-
# Binary is at root level in tar, named 'sub2api'
|
| 35 |
-
cp /tmp/sub2api_dl/sub2api "$SUB2API_BIN"
|
| 36 |
-
chmod +x "$SUB2API_BIN"
|
| 37 |
-
rm -rf /tmp/sub2api_dl
|
| 38 |
-
echo "sub2api downloaded and cached at $SUB2API_BIN"
|
| 39 |
-
else
|
| 40 |
-
echo "sub2api already cached at $SUB2API_BIN"
|
| 41 |
-
fi
|
| 42 |
-
|
| 43 |
-
# ββ PostgreSQL ββ
|
| 44 |
-
if [ ! -f /data/postgres/PG_VERSION ]; then
|
| 45 |
-
echo "Initializing PostgreSQL..."
|
| 46 |
-
mkdir -p /data/postgres /run/postgresql
|
| 47 |
-
chown -R postgres:postgres /data/postgres /run/postgresql
|
| 48 |
-
|
| 49 |
-
# Try Debian-based PG init
|
| 50 |
-
PG_BIN=$(find /usr/lib/postgresql -name "pg_ctl" 2>/dev/null | head -1)
|
| 51 |
-
if [ -n "$PG_BIN" ]; then
|
| 52 |
-
su - postgres -c "$PG_BIN initdb -D /data/postgres"
|
| 53 |
-
su - postgres -c "$PG_BIN -D /data/postgres start -o '-c config_file=/etc/postgresql/postgresql.conf'"
|
| 54 |
-
else
|
| 55 |
-
su - postgres -c "pg_ctl initdb -D /data/postgres"
|
| 56 |
-
su - postgres -c "pg_ctl -D /data/postgres start"
|
| 57 |
-
fi
|
| 58 |
-
sleep 2
|
| 59 |
-
P="${POSTGRES_PASSWORD:-sub2api2026}"
|
| 60 |
-
U="${POSTGRES_USER:-sub2api}"
|
| 61 |
-
D="${POSTGRES_DB:-sub2api}"
|
| 62 |
-
su - postgres -c "psql -c \"CREATE USER $U WITH PASSWORD '$P' SUPERUSER;\""
|
| 63 |
-
su - postgres -c "psql -c \"CREATE DATABASE $D OWNER $U;\""
|
| 64 |
-
if [ -n "$PG_BIN" ]; then
|
| 65 |
-
su - postgres -c "$PG_BIN -D /data/postgres stop"
|
| 66 |
-
else
|
| 67 |
-
su - postgres -c "pg_ctl -D /data/postgres stop"
|
| 68 |
-
fi
|
| 69 |
-
echo "PostgreSQL initialized"
|
| 70 |
-
fi
|
| 71 |
-
|
| 72 |
-
chown postgres:postgres /data/postgres /run/postgresql
|
| 73 |
-
PG_BIN=$(find /usr/lib/postgresql -name "pg_ctl" 2>/dev/null | head -1)
|
| 74 |
-
if [ -n "$PG_BIN" ]; then
|
| 75 |
-
su - postgres -c "$PG_BIN -D /data/postgres start -o '-c config_file=/etc/postgresql/postgresql.conf'"
|
| 76 |
-
else
|
| 77 |
-
su - postgres -c "pg_ctl -D /data/postgres start"
|
| 78 |
-
fi
|
| 79 |
-
sleep 2
|
| 80 |
-
|
| 81 |
-
# ββ Redis ββ
|
| 82 |
-
mkdir -p /data/redis
|
| 83 |
-
redis-server /etc/redis.conf &
|
| 84 |
-
sleep 1
|
| 85 |
-
|
| 86 |
-
# ββ Secrets ββ
|
| 87 |
-
mkdir -p /data/sub2api
|
| 88 |
-
[ ! -f /data/sub2api/.jwt ] && openssl rand -hex 32 > /data/sub2api/.jwt
|
| 89 |
-
[ ! -f /data/sub2api/.totp ] && openssl rand -hex 16 > /data/sub2api/.totp
|
| 90 |
-
|
| 91 |
-
export JWT_SECRET=$(cat /data/sub2api/.jwt)
|
| 92 |
-
export TOTP_ENCRYPTION_KEY=$(cat /data/sub2api/.totp)
|
| 93 |
-
export AUTO_SETUP=true
|
| 94 |
-
export DATABASE_HOST=localhost
|
| 95 |
-
export DATABASE_PORT=5432
|
| 96 |
-
export DATABASE_USER=${POSTGRES_USER:-sub2api}
|
| 97 |
-
export DATABASE_PASSWORD=${POSTGRES_PASSWORD:-sub2api2026}
|
| 98 |
-
export DATABASE_DBNAME=${POSTGRES_DB:-sub2api}
|
| 99 |
-
export DATABASE_SSLMODE=disable
|
| 100 |
-
export REDIS_HOST=localhost
|
| 101 |
-
export REDIS_PORT=6379
|
| 102 |
-
export SERVER_HOST=0.0.0.0
|
| 103 |
-
export SERVER_PORT=7860
|
| 104 |
-
export DATA_DIR=/data/sub2api
|
| 105 |
-
export ADMIN_EMAIL=${ADMIN_EMAIL:-admin@sub2api.local}
|
| 106 |
-
export ADMIN_PASSWORD=${ADMIN_PASSWORD:-sub2api2026}
|
| 107 |
-
|
| 108 |
-
echo "Starting sub2api..."
|
| 109 |
-
exec "$SUB2API_BIN"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|