start-static.sh 724 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. RUN_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
  4. WEBAPP_DIR="${RUN_ROOT}/runtime/webapp"
  5. LOG_DIR="${RUN_ROOT}/runtime/logs"
  6. PID_FILE="${RUN_ROOT}/runtime/zq-static.pid"
  7. LOG_FILE="${LOG_DIR}/zq-static.log"
  8. PORT="${ZQ_STATIC_PORT:-4180}"
  9. mkdir -p "${LOG_DIR}"
  10. if [[ -f "${PID_FILE}" ]]; then
  11. pid="$(cat "${PID_FILE}")"
  12. if [[ -n "${pid}" ]] && kill -0 "${pid}" 2>/dev/null; then
  13. echo "ZQ 静态预览已在运行:http://127.0.0.1:${PORT}/"
  14. exit 0
  15. fi
  16. rm -f "${PID_FILE}"
  17. fi
  18. nohup python3 -m http.server "${PORT}" --bind 127.0.0.1 --directory "${WEBAPP_DIR}" > "${LOG_FILE}" 2>&1 &
  19. echo $! > "${PID_FILE}"
  20. echo "ZQ 静态预览启动中:http://127.0.0.1:${PORT}/"