47 lines
1.4 KiB
Bash
Executable file
47 lines
1.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
ENV_FILE="$REPO_DIR/.env"
|
|
PID_FILE="$REPO_DIR/data/sparrow.pid"
|
|
LOG_FILE="$REPO_DIR/data/sparrow.log"
|
|
|
|
[[ -f "$ENV_FILE" ]] && source "$ENV_FILE"
|
|
SPARROW_PORT="${SPARROW_PORT:-8513}"
|
|
|
|
cmd="${1:-help}"
|
|
|
|
start() {
|
|
mkdir -p "$REPO_DIR/data"
|
|
if [[ -f "$PID_FILE" ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
|
|
echo "sparrow already running (PID $(cat "$PID_FILE"))"
|
|
return
|
|
fi
|
|
echo "Starting sparrow on port $SPARROW_PORT..."
|
|
conda run -n cf \
|
|
uvicorn app.main:app --host "${SPARROW_HOST:-0.0.0.0}" --port "$SPARROW_PORT" \
|
|
>> "$LOG_FILE" 2>&1 &
|
|
echo $! > "$PID_FILE"
|
|
echo "Started (PID $!). Logs: $LOG_FILE"
|
|
}
|
|
|
|
stop() {
|
|
if [[ -f "$PID_FILE" ]]; then
|
|
kill "$(cat "$PID_FILE")" 2>/dev/null && echo "Stopped." || echo "Not running."
|
|
rm -f "$PID_FILE"
|
|
else
|
|
echo "Not running."
|
|
fi
|
|
}
|
|
|
|
case "$cmd" in
|
|
start) start ;;
|
|
stop) stop ;;
|
|
restart) stop; sleep 1; start ;;
|
|
status) [[ -f "$PID_FILE" ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null \
|
|
&& echo "running (PID $(cat "$PID_FILE"))" || echo "stopped" ;;
|
|
logs) tail -f "$LOG_FILE" ;;
|
|
open) xdg-open "http://localhost:$SPARROW_PORT" 2>/dev/null || \
|
|
open "http://localhost:$SPARROW_PORT" 2>/dev/null || true ;;
|
|
*) echo "Usage: $0 {start|stop|restart|status|logs|open}" ;;
|
|
esac
|