auto-save 2026-05-15 11:18 (+1, ~4)
This commit is contained in:
53
scripts/start-dev-background.sh
Executable file
53
scripts/start-dev-background.sh
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
API_DIR="$ROOT_DIR/api"
|
||||
WEB_DIR="$ROOT_DIR/web"
|
||||
LOG_DIR="$ROOT_DIR/.logs"
|
||||
PID_DIR="$ROOT_DIR/.pids"
|
||||
|
||||
mkdir -p "$LOG_DIR" "$PID_DIR"
|
||||
|
||||
port_is_listening() {
|
||||
local port="$1"
|
||||
lsof -tiTCP:"$port" -sTCP:LISTEN >/dev/null 2>&1
|
||||
}
|
||||
|
||||
start_api() {
|
||||
if port_is_listening 4291; then
|
||||
echo "api already running on 4291"
|
||||
return
|
||||
fi
|
||||
if [[ ! -x "$API_DIR/.venv/bin/uvicorn" ]]; then
|
||||
echo "missing api/.venv/bin/uvicorn" >&2
|
||||
exit 1
|
||||
fi
|
||||
(
|
||||
cd "$API_DIR"
|
||||
nohup .venv/bin/uvicorn main:app --host 127.0.0.1 --port 4291 >> "$LOG_DIR/api.log" 2>&1 &
|
||||
echo $! > "$PID_DIR/api.pid"
|
||||
)
|
||||
echo "api started on 4291, log: $LOG_DIR/api.log"
|
||||
}
|
||||
|
||||
start_web() {
|
||||
if port_is_listening 4290; then
|
||||
echo "web already running on 4290"
|
||||
return
|
||||
fi
|
||||
if ! command -v pnpm >/dev/null 2>&1; then
|
||||
echo "missing pnpm in PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
(
|
||||
cd "$WEB_DIR"
|
||||
nohup pnpm dev >> "$LOG_DIR/web.log" 2>&1 &
|
||||
echo $! > "$PID_DIR/web.pid"
|
||||
)
|
||||
echo "web started on 4290, log: $LOG_DIR/web.log"
|
||||
}
|
||||
|
||||
start_api
|
||||
start_web
|
||||
echo "open http://localhost:4290"
|
||||
26
scripts/stop-dev-background.sh
Executable file
26
scripts/stop-dev-background.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
PID_DIR="$ROOT_DIR/.pids"
|
||||
|
||||
stop_pid_file() {
|
||||
local name="$1"
|
||||
local file="$PID_DIR/$name.pid"
|
||||
if [[ ! -f "$file" ]]; then
|
||||
echo "$name pid file not found"
|
||||
return
|
||||
fi
|
||||
local pid
|
||||
pid="$(cat "$file")"
|
||||
if [[ -n "$pid" ]] && kill -0 "$pid" >/dev/null 2>&1; then
|
||||
kill -TERM "$pid"
|
||||
echo "$name stopped: $pid"
|
||||
else
|
||||
echo "$name already stopped"
|
||||
fi
|
||||
rm -f "$file"
|
||||
}
|
||||
|
||||
stop_pid_file api
|
||||
stop_pid_file web
|
||||
Reference in New Issue
Block a user