Files
learningcircuit--local-deep…/scripts/dev/restart_server.sh
T
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

135 lines
4.6 KiB
Bash
Executable File

#!/bin/bash
# Restart the LDR dev server.
#
# Usage:
# scripts/dev/restart_server.sh [PORT] [--debug] [--tmp]
#
# PORT Optional port (default: 5000). Passed via LDR_WEB_PORT.
# --debug DEBUG logging (LDR_APP_DEBUG=true, LDR_LOG_SETTINGS=summary).
# WARNING: debug logs may contain sensitive data (queries,
# answers, API responses) — local dev / feature testing only,
# never production or real user data.
# --tmp Disposable instance: point LDR_DATA_DIR at a throwaway dir
# (default /tmp/ldr-test) so encrypted user DBs, the auth DB,
# library, logs, research_outputs etc. land OUTSIDE your real
# data dir (~/.local/share/local-deep-research). Override the
# location by exporting LDR_DATA_DIR before running. Reuses one
# dir (doesn't accumulate throwaway databases). To start from a
# clean slate, wipe LDR_DATA_DIR yourself first (e.g.
# `rm -rf "$LDR_DATA_DIR"`) — this script never deletes data.
#
# Only the instance listening on the target PORT is stopped, so multiple
# instances on different ports (e.g. several agents each on their own port)
# coexist — restarting one does not kill the others.
#
# Referenced in:
# - tests/api_tests_with_login/README.md
# - examples/api_usage/http/README.md
# - examples/api_usage/http/advanced/simple_http_example.py
# Do not delete without updating those references.
set -u
usage() {
cat <<'EOF'
Restart the LDR dev server.
Usage:
scripts/dev/restart_server.sh [PORT] [--debug] [--tmp]
PORT Optional port (default: 5000).
--debug DEBUG logging (may log sensitive data; local dev only).
--tmp Disposable instance: LDR_DATA_DIR -> /tmp/ldr-test (override by
exporting LDR_DATA_DIR). Keeps test data out of your real dir.
This script never deletes data; wipe LDR_DATA_DIR yourself to
start from a clean slate.
--test Alias for --tmp.
Only the instance on the target PORT is stopped; instances on other ports
keep running.
EOF
}
PORT=5000
debug=0
use_tmp=0
for arg in "$@"; do
case "$arg" in
--debug) debug=1 ;;
--tmp|--test) use_tmp=1 ;;
-h|--help) usage; exit 0 ;;
''|*[!0-9]*) echo "Unknown argument: $arg" >&2; usage >&2; exit 2 ;;
*) PORT="$arg" ;;
esac
done
echo "Stopping existing LDR server on port ${PORT} (if any)..."
# Port-scoped stop: kill only the process LISTENing on PORT, leaving
# instances on other ports running. The port isn't in the process argv
# (it comes from LDR_WEB_PORT), so a broad pkill can't distinguish them.
if command -v fuser >/dev/null 2>&1; then
fuser -k "${PORT}/tcp" 2>/dev/null || echo "No existing server on port ${PORT}"
elif command -v lsof >/dev/null 2>&1; then
pids=$(lsof -ti "tcp:${PORT}" -sTCP:LISTEN 2>/dev/null)
if [ -n "${pids}" ]; then
# $pids may be several PIDs; word-splitting is intended here.
# shellcheck disable=SC2086
kill ${pids} 2>/dev/null
else
echo "No existing server on port ${PORT}"
fi
else
echo "Warning: neither fuser nor lsof found; cannot port-scope the stop." >&2
echo "Skipping stop to avoid killing instances on other ports." >&2
fi
sleep 1
# Change to the project root.
cd "$(dirname "$0")/../.." || exit 1
# --- environment for the launched server -------------------------------------
env_args=(LDR_WEB_PORT="${PORT}")
if [ "$use_tmp" -eq 1 ]; then
: "${LDR_DATA_DIR:=/tmp/ldr-test}"
mkdir -p "$LDR_DATA_DIR"
echo "Using disposable LDR_DATA_DIR=$LDR_DATA_DIR"
env_args+=(LDR_DATA_DIR="${LDR_DATA_DIR}")
fi
if [ "$debug" -eq 1 ]; then
env_args+=(LDR_APP_DEBUG=true LDR_LOG_SETTINGS=summary)
fi
LOG_FILE="/tmp/ldr_server_${PORT}.log"
if [ "$debug" -eq 1 ]; then
echo "Starting LDR server on port ${PORT} (DEBUG)..."
else
echo "Starting LDR server on port ${PORT}..."
fi
# Start server in background and detach from terminal. Backgrounding nohup
# directly (rather than wrapping in an extra `( ... & ) &` subshell) means
# $! captures the real server PID, not a transient subshell that has already
# exited. nohup ignores SIGHUP, so the server survives the launcher exiting
# and is reparented to init.
nohup env "${env_args[@]}" pdm run python -m local_deep_research.web.app > "${LOG_FILE}" 2>&1 &
SERVER_PID=$!
sleep 2
echo "Server started. PID: ${SERVER_PID}"
echo "Logs: ${LOG_FILE}"
echo "URL: http://127.0.0.1:${PORT}"
if [ "$debug" -eq 1 ]; then
echo ""
echo "WARNING: DEBUG mode — logs may contain sensitive data; local dev only."
fi
echo ""
echo "To view logs: tail -f ${LOG_FILE}"
echo "To stop server: fuser -k ${PORT}/tcp"
exit 0