#!/usr/bin/env bash # Start sqlite_api in the background. Logs to sqlite_api.log. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" REGISTRY_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)" LOG="$SCRIPT_DIR/sqlite_api.log" PID_FILE="$SCRIPT_DIR/sqlite_api.pid" # Kill previous instance if running if [ -f "$PID_FILE" ]; then old_pid=$(cat "$PID_FILE") if kill -0 "$old_pid" 2>/dev/null; then echo "Stopping previous instance (PID $old_pid)" kill "$old_pid" sleep 0.5 fi rm -f "$PID_FILE" fi export FN_REGISTRY_ROOT="$REGISTRY_ROOT" cd "$REGISTRY_ROOT" CGO_ENABLED=1 go run -tags fts5 ./projects/fn_monitoring/apps/sqlite_api/ "$@" \ >"$LOG" 2>&1 & echo $! > "$PID_FILE" echo "sqlite_api started (PID $!, log: $LOG)" sleep 0.5 if curl -sf http://127.0.0.1:8484/health >/dev/null 2>&1; then echo "Health check OK" else echo "Waiting for startup..." sleep 1.5 if curl -sf http://127.0.0.1:8484/health >/dev/null 2>&1; then echo "Health check OK" else echo "Warning: health check failed — check $LOG" fi fi