ole2242527 commited on
Commit
1cb6fd6
·
verified ·
1 Parent(s): 3b301d1

Upload start-space.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. start-space.sh +15 -33
start-space.sh CHANGED
@@ -20,38 +20,20 @@ done
20
 
21
  ADMIN_EMAIL="${ADMIN_EMAIL:-2691539771@qq.com}"
22
  SERVER_PORT="${SERVER_PORT:-7860}"
23
- DATA_DIR="${DATA_DIR:-/data/gateway-data}"
24
 
25
- # PG/Redis use /tmp (ephemeral) — Storage Bucket mount causes initdb issues
26
- # sub2api config uses /data (persistent via Storage Bucket)
27
- PG_DATA="/tmp/gateway-postgres"
28
- REDIS_DATA="/tmp/gateway-redis"
29
 
30
- mkdir -p "$DATA_DIR" "$REDIS_DATA" "$PG_DATA"
31
- chown -R sub2api:sub2api "$DATA_DIR" "$REDIS_DATA"
32
- chown -R postgres:postgres "$PG_DATA"
33
-
34
- # Start Redis (ephemeral, fast — no persistence needed for cache)
35
- redis-server --daemonize yes --bind 127.0.0.1 --port 6379 --dir "$REDIS_DATA" --save "" --appendonly no
36
 
37
  if [ -z "${DATABASE_HOST:-}" ]; then
38
- if [ ! -s "$PG_DATA/PG_VERSION" ]; then
39
- echo "DEBUG: PG_VERSION not found, cleaning stale PG data..."
40
- echo "DEBUG: Listing $PG_DATA contents before cleanup:"
41
- ls -la "$PG_DATA" 2>/dev/null || echo "DEBUG: Directory does not exist or is empty"
42
- echo "DEBUG: Attempting rm -rf $PG_DATA..."
43
- rm -rf "$PG_DATA" && echo "DEBUG: rm -rf succeeded" || echo "DEBUG: rm -rf FAILED"
44
- echo "DEBUG: Listing after rm -rf:"
45
- ls -la "$PG_DATA" 2>/dev/null || echo "DEBUG: Directory gone after rm"
46
- mkdir -p "$PG_DATA"
47
- chown postgres:postgres "$PG_DATA"
48
- echo "DEBUG: Running initdb..."
49
- su-exec postgres initdb -D "$PG_DATA" --auth=trust >"$PG_DATA/init.log"
50
- else
51
- echo "PG_VERSION found, skipping initdb (existing PG data)"
52
  fi
53
 
54
- su-exec postgres pg_ctl -D "$PG_DATA" -l "$PG_DATA/gateway-postgres.log" -o "-c listen_addresses=127.0.0.1 -c port=5432 -c unix_socket_directories=/tmp" start
55
  createdb -h 127.0.0.1 -U postgres gatewaydb 2>/dev/null || true
56
 
57
  DATABASE_HOST="127.0.0.1"
@@ -60,7 +42,7 @@ if [ -z "${DATABASE_HOST:-}" ]; then
60
  DATABASE_PASSWORD=""
61
  DATABASE_DBNAME="gatewaydb"
62
  DATABASE_SSLMODE="disable"
63
- echo "Using ephemeral local PostgreSQL. sub2api config persisted at /data."
64
  else
65
  DATABASE_PORT="${DATABASE_PORT:-5432}"
66
  DATABASE_USER="${DATABASE_USER:-postgres}"
@@ -110,7 +92,7 @@ sync_balance_cache_once() {
110
  -d "$DATABASE_DBNAME" \
111
  -qAt \
112
  -F '|' \
113
- -c "select id, balance::double precision from users where deleted_at is null and status = 'active';" 2>/data/balance-cache-sync.err || true)"
114
 
115
  if [ -z "$rows" ]; then
116
  return 0
@@ -171,7 +153,7 @@ database:
171
  conn_max_idle_time_minutes: ${DATABASE_CONN_MAX_IDLE_TIME_MINUTES:-5}
172
  redis:
173
  host: "${REDIS_HOST}"
174
- port: "${REDIS_PORT}"
175
  password: "${REDIS_PASSWORD:-}"
176
  db: ${REDIS_DB:-0}
177
  enable_tls: ${REDIS_ENABLE_TLS:-false}
@@ -281,7 +263,7 @@ PY
281
  -p "$DATABASE_PORT" \
282
  -U "$DATABASE_USER" \
283
  -d "$sync_dbname" \
284
- -tAc "select to_regclass('public.users') is not null;" 2>/data/admin-user-check.err || true)"
285
  table_exists="$(printf '%s' "$table_exists" | tr -d '[:space:]')"
286
  admin_count="$(PGPASSWORD="${DATABASE_PASSWORD:-}" psql \
287
  -h "$DATABASE_HOST" \
@@ -298,14 +280,14 @@ PY
298
  -U "$DATABASE_USER" \
299
  -d "$sync_dbname" \
300
  -v ON_ERROR_STOP=1 \
301
- -c "update users set password_hash = '${password_hash}', role = 'admin', status = 'active', updated_at = now() where email = '${ADMIN_EMAIL}'; insert into users (email, password_hash, role, balance, concurrency, status, created_at, updated_at) select '${ADMIN_EMAIL}', '${password_hash}', 'admin', 0, 5, 'active', now(), now() where not exists (select 1 from users where email = '${ADMIN_EMAIL}');" >/data/admin-password-sync.out 2>/data/admin-password-sync.err
302
 
303
  stored_hash="$(PGPASSWORD="${DATABASE_PASSWORD:-}" psql \
304
  -h "$DATABASE_HOST" \
305
  -p "$DATABASE_PORT" \
306
  -U "$DATABASE_USER" \
307
  -d "$sync_dbname" \
308
- -tAc "select password_hash from users where role = 'admin' limit 1;" 2>/data/admin-password-verify.err || true)"
309
  export STORED_ADMIN_PASSWORD_HASH="$stored_hash"
310
  verify_result="$(python3 - <<'PY'
311
  import bcrypt
@@ -329,7 +311,7 @@ PY
329
  done
330
 
331
  echo "Admin password sync skipped: admin user not found before timeout." >&2
332
- cat /data/admin-user-check.err >&2 || true
333
  }
334
 
335
  maybe_skip_auto_setup
 
20
 
21
  ADMIN_EMAIL="${ADMIN_EMAIL:-2691539771@qq.com}"
22
  SERVER_PORT="${SERVER_PORT:-7860}"
23
+ DATA_DIR="${DATA_DIR:-/tmp/gateway-data}"
24
 
25
+ mkdir -p "$DATA_DIR" /tmp/gateway-redis /tmp/gateway-postgres
26
+ chown -R sub2api:sub2api "$DATA_DIR" /tmp/gateway-redis
27
+ chown -R postgres:postgres /tmp/gateway-postgres
 
28
 
29
+ redis-server --daemonize yes --bind 127.0.0.1 --port 6379 --dir /tmp/gateway-redis --save "" --appendonly no
 
 
 
 
 
30
 
31
  if [ -z "${DATABASE_HOST:-}" ]; then
32
+ if [ ! -s /tmp/gateway-postgres/PG_VERSION ]; then
33
+ su-exec postgres initdb -D /tmp/gateway-postgres --auth=trust >/tmp/gateway-postgres-init.log
 
 
 
 
 
 
 
 
 
 
 
 
34
  fi
35
 
36
+ su-exec postgres pg_ctl -D /tmp/gateway-postgres -l /tmp/gateway-postgres.log -o "-c listen_addresses=127.0.0.1 -c port=5432 -c unix_socket_directories=/tmp" start
37
  createdb -h 127.0.0.1 -U postgres gatewaydb 2>/dev/null || true
38
 
39
  DATABASE_HOST="127.0.0.1"
 
42
  DATABASE_PASSWORD=""
43
  DATABASE_DBNAME="gatewaydb"
44
  DATABASE_SSLMODE="disable"
45
+ echo "Using ephemeral local PostgreSQL. Configure Supabase secrets for persistent data."
46
  else
47
  DATABASE_PORT="${DATABASE_PORT:-5432}"
48
  DATABASE_USER="${DATABASE_USER:-postgres}"
 
92
  -d "$DATABASE_DBNAME" \
93
  -qAt \
94
  -F '|' \
95
+ -c "select id, balance::double precision from users where deleted_at is null and status = 'active';" 2>/tmp/balance-cache-sync.err || true)"
96
 
97
  if [ -z "$rows" ]; then
98
  return 0
 
153
  conn_max_idle_time_minutes: ${DATABASE_CONN_MAX_IDLE_TIME_MINUTES:-5}
154
  redis:
155
  host: "${REDIS_HOST}"
156
+ port: ${REDIS_PORT}
157
  password: "${REDIS_PASSWORD:-}"
158
  db: ${REDIS_DB:-0}
159
  enable_tls: ${REDIS_ENABLE_TLS:-false}
 
263
  -p "$DATABASE_PORT" \
264
  -U "$DATABASE_USER" \
265
  -d "$sync_dbname" \
266
+ -tAc "select to_regclass('public.users') is not null;" 2>/tmp/admin-user-check.err || true)"
267
  table_exists="$(printf '%s' "$table_exists" | tr -d '[:space:]')"
268
  admin_count="$(PGPASSWORD="${DATABASE_PASSWORD:-}" psql \
269
  -h "$DATABASE_HOST" \
 
280
  -U "$DATABASE_USER" \
281
  -d "$sync_dbname" \
282
  -v ON_ERROR_STOP=1 \
283
+ -c "update users set password_hash = '${password_hash}', role = 'admin', status = 'active', updated_at = now() where email = '${ADMIN_EMAIL}'; insert into users (email, password_hash, role, balance, concurrency, status, created_at, updated_at) select '${ADMIN_EMAIL}', '${password_hash}', 'admin', 0, 5, 'active', now(), now() where not exists (select 1 from users where email = '${ADMIN_EMAIL}');" >/tmp/admin-password-sync.out 2>/tmp/admin-password-sync.err
284
 
285
  stored_hash="$(PGPASSWORD="${DATABASE_PASSWORD:-}" psql \
286
  -h "$DATABASE_HOST" \
287
  -p "$DATABASE_PORT" \
288
  -U "$DATABASE_USER" \
289
  -d "$sync_dbname" \
290
+ -tAc "select password_hash from users where role = 'admin' limit 1;" 2>/tmp/admin-password-verify.err || true)"
291
  export STORED_ADMIN_PASSWORD_HASH="$stored_hash"
292
  verify_result="$(python3 - <<'PY'
293
  import bcrypt
 
311
  done
312
 
313
  echo "Admin password sync skipped: admin user not found before timeout." >&2
314
+ cat /tmp/admin-user-check.err >&2 || true
315
  }
316
 
317
  maybe_skip_auto_setup