You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

50 lines
1.2 KiB

#!/usr/bin/env bash
# Development server with auto-restart on config file changes.
#
# Normal code changes (controllers, templates, etc.) are still hot-reloaded
# by Phoenix automatically. This script only handles the cases Phoenix can't:
# config/config.exs, config/dev.exs, and config/runtime.exs.
#
# Usage:
# chmod +x dev.sh
# source .env && ./dev.sh
set -euo pipefail
CONFIG_FILES=(
config/config.exs
config/dev.exs
config/runtime.exs
)
cleanup() {
if [ -n "${SERVER_PID:-}" ] && kill -0 "$SERVER_PID" 2>/dev/null; then
echo ""
echo "[dev] Stopping server (pid $SERVER_PID)..."
kill "$SERVER_PID"
wait "$SERVER_PID" 2>/dev/null || true
fi
exit 0
}
trap cleanup INT TERM
echo "[dev] Watching config files for changes: ${CONFIG_FILES[*]}"
echo "[dev] Normal code changes are still hot-reloaded automatically."
echo "[dev] Press Ctrl+C to stop."
echo ""
while true; do
echo "[dev] Starting server..."
mix phx.server &
SERVER_PID=$!
# Block until any config file is modified
inotifywait -q -e modify "${CONFIG_FILES[@]}" 2>/dev/null
echo ""
echo "[dev] Config changed — restarting server..."
kill "$SERVER_PID" 2>/dev/null
wait "$SERVER_PID" 2>/dev/null || true
echo ""
done