stop-server.sh 747 B

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. # Stop the brainstorm server and clean up
  3. # Usage: stop-server.sh <screen_dir>
  4. #
  5. # Kills the server process. Only deletes session directory if it's
  6. # under /tmp (ephemeral). Persistent directories (.superpowers/) are
  7. # kept so mockups can be reviewed later.
  8. SCREEN_DIR="$1"
  9. if [[ -z "$SCREEN_DIR" ]]; then
  10. echo '{"error": "Usage: stop-server.sh <screen_dir>"}'
  11. exit 1
  12. fi
  13. PID_FILE="${SCREEN_DIR}/.server.pid"
  14. if [[ -f "$PID_FILE" ]]; then
  15. pid=$(cat "$PID_FILE")
  16. kill "$pid" 2>/dev/null
  17. rm -f "$PID_FILE" "${SCREEN_DIR}/.server.log"
  18. # Only delete ephemeral /tmp directories
  19. if [[ "$SCREEN_DIR" == /tmp/* ]]; then
  20. rm -rf "$SCREEN_DIR"
  21. fi
  22. echo '{"status": "stopped"}'
  23. else
  24. echo '{"status": "not_running"}'
  25. fi