server (814B)
1 #!/usr/bin/env bash 2 set -euo pipefail 3 4 repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) 5 dither_dir="${repo_root}/bin/dither" 6 cache_dir="${DITHER_CACHE_DIR:-${repo_root}/.cache/dither}" 7 8 mkdir -p "${cache_dir}" 9 10 pushd "${dither_dir}" >/dev/null 11 ROOT="${repo_root}/content" KEY="${repo_root}/secret.key" DITHER_CACHE_DIR="${cache_dir}" bundle exec ruby dither.rb & 12 dither_pid=$! 13 popd >/dev/null 14 15 cleanup() { 16 if kill -0 "${dither_pid}" 2>/dev/null; then 17 kill "${dither_pid}" 2>/dev/null || true 18 wait "${dither_pid}" 2>/dev/null || true 19 fi 20 } 21 trap cleanup EXIT INT TERM 22 23 # Wait until the dither server is listening instead of guessing with sleep. 24 for _ in {1..50}; do 25 if (echo >/dev/tcp/localhost/4567) >/dev/null 2>&1; then 26 break 27 fi 28 sleep 0.1 29 done 30 31 DITHER_SERVER=http://localhost:4567 hugo server