Make 'nix run' spin up the whole stack in one command

This commit is contained in:
kurogeek committed 2026-10-15 07:36:56 +00:00
1 parent c8b08fe258
commit 4d77464988
3 files changed
+56 -26

No files matched your search

+14 -3
View File
@@ -65,8 +65,9 @@ db_start() {
echo "db: already running (pid $(cat "$MYSQL_PID"))"
return
fi
mariadbd --datadir="$MYSQL_DATA" --socket="$MYSQL_SOCK" --pid-file="$MYSQL_PID" \
--port="$DB_PORT" --bind-address=127.0.0.1 --skip-name-resolve \
# Ignore terminal Ctrl-C in the DB so `up` can shut it down cleanly after the app servers.
(trap '' INT; exec mariadbd --datadir="$MYSQL_DATA" --socket="$MYSQL_SOCK" --pid-file="$MYSQL_PID" \
--port="$DB_PORT" --bind-address=127.0.0.1 --skip-name-resolve) \
>"$MYSQL_LOG" 2>&1 &
for _ in $(seq 1 50); do
mariadb-admin --socket="$MYSQL_SOCK" -uroot ping >/dev/null 2>&1 && break
@@ -121,9 +122,19 @@ serve() {
}
up() {
for app in "$FRONTEND" "$BACKEND"; do
[ -f "$app/vendor/autoload.php" ] || composer_install
done
db_start
local pids=()
trap 'kill "${pids[@]}" 2>/dev/null; wait; db_stop' EXIT INT TERM
cleanup() {
trap - EXIT INT TERM
set +e
kill "${pids[@]}" 2>/dev/null
wait "${pids[@]}" 2>/dev/null
db_stop
}
trap cleanup EXIT INT TERM
(cd "$FRONTEND" && php artisan serve --host=127.0.0.1 --port="$FRONTEND_PORT") & pids+=($!)
(cd "$BACKEND" && php artisan serve --host=127.0.0.1 --port="$BACKEND_PORT") & pids+=($!)
echo "frontend: http://127.0.0.1:$FRONTEND_PORT"