OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git-v3 / scripts / legacy / pgv3-start.sh

56 lines · bash ref:
#!/bin/bash
# Start pear-git-v3 in tmux session (pear-seed convention, parallel to
# pear-git's pear-git-start.sh). Storage is PERSISTENT — outlives daemon
# restarts and machine reboots.

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"

SESSION="pear-seed"
WINDOW="pear-git-v3"

# Storage — kept separate from pear-git v1's storage so the v1 → v3
# migration (Phase 5) can proceed without overlap. Override via env.
STORAGE="${PEAR_GIT_STORAGE:-/home/fleeky/pgv3-storage}"
REPOS="${PEAR_GIT_REPOS:-/home/fleeky/git-repos}"
HTTP_PORT="${PEAR_GIT_HTTP:-4040}"
HOST="${PEAR_GIT_HOST:-0.0.0.0}"

# Ensure storage dir exists (won't touch if it already does)
mkdir -p "$STORAGE"

# tmux session bring-up
if ! tmux has-session -t "$SESSION" 2>/dev/null; then
  echo "Creating tmux session: $SESSION"
  tmux new-session -d -s "$SESSION" -n "$WINDOW"
else
  if tmux list-windows -t "$SESSION" | grep -q "^[0-9]*: $WINDOW\\b"; then
    echo "pgv3 window already exists in $SESSION session" >&2
    echo "   Use ./scripts/pgv3-stop.sh first" >&2
    exit 1
  fi
  tmux new-window -t "$SESSION" -n "$WINDOW"
fi

echo "Created tmux window: $SESSION:$WINDOW"

# Command to run, inside the tmux window. Piped through tee for live log.
CMD="cd $PROJECT_DIR && PEAR_GIT_HOST=$HOST PEAR_GIT_REPOS=$REPOS PEAR_GIT_STORAGE=$STORAGE PEAR_GIT_HTTP=$HTTP_PORT node server.js 2>&1 | tee /tmp/pgv3.log"

tmux send-keys -t "$SESSION:$WINDOW" "$CMD" C-m

echo ""
echo "pgv3 starting on http://$HOST:$HTTP_PORT"
echo "  storage: $STORAGE"
echo "  repos:   $REPOS"
echo "  log:     /tmp/pgv3.log"
echo ""
echo "Tmux:"
echo "  attach:  tmux attach -t $SESSION"
echo "  detach:  C-b d"
echo ""
echo "Stop:"
echo "  $PROJECT_DIR/scripts/pgv3-stop.sh"