33 lines
819 B
Bash
Executable File
33 lines
819 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Start every dev server declared in stack.conf. Ctrl-C stops all of them.
|
|
set -euo pipefail
|
|
|
|
here="$(cd "$(dirname "$0")" && pwd)"
|
|
source "$here/stack.conf"
|
|
|
|
# The workspace root, which holds every repo of the stack as a sibling.
|
|
cd "$here/.."
|
|
|
|
pids=()
|
|
|
|
cleanup() {
|
|
trap - EXIT INT TERM
|
|
[ ${#pids[@]} -gt 0 ] && kill -TERM "${pids[@]}" 2>/dev/null
|
|
wait 2>/dev/null || true
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
for service in "${SERVICES[@]}"; do
|
|
IFS='|' read -r dir setup run <<<"$service"
|
|
[ -n "$run" ] || continue
|
|
echo "==> $dir: $run"
|
|
(cd "$dir" && exec bash -c "$run") &
|
|
pids+=($!)
|
|
done
|
|
|
|
[ ${#pids[@]} -gt 0 ] || { echo "no run command in stack.conf" >&2; exit 1; }
|
|
|
|
# Return as soon as one server exits, so cleanup stops the others rather than
|
|
# leaving half a stack running.
|
|
wait -n || true
|