Files
ReadeckProxy/docker/app/watch.sh
T
2026-04-22 22:34:03 +03:00

47 lines
1.1 KiB
Bash

#!/bin/bash
set -e
APP_PID=""
build_and_run() {
echo "==> Building..."
if swift build 2>&1; then
echo "==> Build succeeded, starting app..."
if [ -n "$APP_PID" ] && kill -0 "$APP_PID" 2>/dev/null; then
kill "$APP_PID" 2>/dev/null || true
wait "$APP_PID" 2>/dev/null || true
fi
swift run App serve --env development --hostname 0.0.0.0 --port "${APP_PORT:-8080}" &
APP_PID=$!
echo "==> App running (PID: $APP_PID)"
else
echo "==> Build failed, keeping previous version running"
fi
}
cleanup() {
echo "==> Shutting down..."
if [ -n "$APP_PID" ]; then
kill "$APP_PID" 2>/dev/null || true
wait "$APP_PID" 2>/dev/null || true
fi
exit 0
}
trap cleanup SIGTERM SIGINT
# Initial build
build_and_run
# Watch for changes in Sources and Resources
echo "==> Watching for file changes..."
while true; do
inotifywait -r -e modify,create,delete,move \
--include '\.(swift|leaf)$' \
Sources/ Resources/ Package.swift 2>/dev/null
echo "==> Change detected, rebuilding..."
sleep 1 # debounce rapid saves
build_and_run
done