prop/bin/notebook
Graham McIntire 548e277bec Add bin/notebook script to start Phoenix + Livebook together
Starts Phoenix with a named node and Livebook attached to it on
port 8081. Single command, Ctrl-C stops both.
2026-04-07 11:15:49 -05:00

40 lines
1 KiB
Bash
Executable file

#!/bin/bash
# Start Phoenix + Livebook together. Livebook attaches to the Phoenix node
# and gets full access to Repo, Scorer, Weather, etc.
#
# Usage: bin/notebook
# Then open http://localhost:8081
set -e
COOKIE="microwaveprop_nb"
NODE="prop@$(hostname -s)"
PORT="${LIVEBOOK_PORT:-8081}"
NOTEBOOK="notebooks/algorithm_analysis.livemd"
echo "Starting Phoenix on :4000 and Livebook on :${PORT}..."
echo "Livebook will be at http://localhost:${PORT}"
echo ""
# Start Phoenix in background with a node name
elixir --sname prop --cookie "$COOKIE" -S mix phx.server &
PHOENIX_PID=$!
# Wait for the node to come up
sleep 3
# Start Livebook attached to the Phoenix node
LIVEBOOK_HOME="$(pwd)/notebooks" \
livebook server \
--port "$PORT" \
--default-runtime "attached:${NODE}:${COOKIE}" \
--open "$NOTEBOOK" &
LIVEBOOK_PID=$!
# Trap ctrl-c to kill both
trap "kill $PHOENIX_PID $LIVEBOOK_PID 2>/dev/null; exit" INT TERM
echo "Phoenix PID: $PHOENIX_PID, Livebook PID: $LIVEBOOK_PID"
echo "Press Ctrl-C to stop both."
wait