Files
c-relay-pg/admin/serve.sh
T
Laan Tungir 50653dc86a v2.1.38 - Custom backfill feature: ad-hoc backfill jobs with arbitrary NIP-01 filters + admin UI isolation
- New caching_custom_backfill_jobs and caching_custom_backfill_batches tables
- Admin API (POST create/cancel, GET list) at admin/api/custom_backfill.php
- Admin UI form with preset buttons and job status table on Backfill page
- Caching daemon module (custom_backfill.c) processes jobs independently
- pg_inbox functions for job/batch claim, progress update, and cancel
- Three batch modes: author-batched, id-batched, time-window scan
- Fixed done_batches overcount on job completion
- Admin config now environment-variable driven (C_RELAY_DB_*)
- admin/serve.sh supports separate instances for different databases
- make_and_restart_relay.sh only kills relay on target port, not all relays
2026-08-07 14:49:13 -04:00

57 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# Launch the admin PHP built-in server, fully detached from the calling shell.
#
# Usage:
# ./admin/serve.sh [port] (default port 8088, default db crelay_prod)
# C_RELAY_DB_NAME=crelay ./admin/serve.sh 8089 (port 8089, db crelay)
#
# Environment variables (all optional):
# C_RELAY_DB_HOST (default: localhost)
# C_RELAY_DB_PORT (default: 5432)
# C_RELAY_DB_NAME (default: crelay_prod)
# C_RELAY_DB_USER (default: crelay)
# C_RELAY_DB_PASSWORD (default: crelay)
#
# These are passed through to the PHP server so admin/lib/config.php
# can read them. This allows running multiple admin instances for
# different relays without editing config files.
PORT="${1:-8088}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Kill any existing instance on this port.
pkill -f "php -S 127.0.0.1:$PORT" 2>/dev/null
sleep 1
# Build env vars to export for the PHP process.
EXPORT_VARS=""
for var in C_RELAY_DB_HOST C_RELAY_DB_PORT C_RELAY_DB_NAME C_RELAY_DB_USER C_RELAY_DB_PASSWORD; do
if [ -n "${!var}" ]; then
EXPORT_VARS="$EXPORT_VARS $var=${!var}"
fi
done
# Start fully detached in its own session so SIGTERM to the launcher
# does not propagate to the PHP server.
if [ -n "$EXPORT_VARS" ]; then
# shellcheck disable=SC2086
setsid env $EXPORT_VARS php -S 127.0.0.1:$PORT -t "$SCRIPT_DIR" > "$SCRIPT_DIR/php_server.log" 2>&1 < /dev/null &
else
setsid php -S 127.0.0.1:$PORT -t "$SCRIPT_DIR" > "$SCRIPT_DIR/php_server.log" 2>&1 < /dev/null &
fi
PHP_PID=$!
disown $PHP_PID 2>/dev/null
# Give it a moment to bind, then report.
sleep 1
if kill -0 "$PHP_PID" 2>/dev/null; then
echo "admin PHP server started on http://127.0.0.1:$PORT (PID $PHP_PID)"
echo "Serving from: $SCRIPT_DIR"
echo "Database: ${C_RELAY_DB_NAME:-crelay_prod}"
echo "Log: $SCRIPT_DIR/php_server.log"
else
echo "ERROR: PHP server failed to start. Log:"
cat "$SCRIPT_DIR/php_server.log" 2>/dev/null
exit 1
fi