From ba5cec5fe160495e9ed35b2790467402e450e917 Mon Sep 17 00:00:00 2001 From: David Eisinger Date: Mon, 1 Dec 2025 10:53:07 -0500 Subject: [PATCH] Improve bin/server --- bin/server | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/bin/server b/bin/server index 4e914db..455453d 100755 --- a/bin/server +++ b/bin/server @@ -1,8 +1,28 @@ -cd bin/dither && \ - ROOT=/Users/dce/code/davideisinger.com/content \ - KEY=/Users/dce/code/davideisinger.com/secret.key \ - bundle exec ruby dither.rb & +#!/usr/bin/env bash +set -euo pipefail -sleep 1 +repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +dither_dir="${repo_root}/bin/dither" + +pushd "${dither_dir}" >/dev/null +ROOT="${repo_root}/content" KEY="${repo_root}/secret.key" bundle exec ruby dither.rb & +dither_pid=$! +popd >/dev/null + +cleanup() { + if kill -0 "${dither_pid}" 2>/dev/null; then + kill "${dither_pid}" 2>/dev/null || true + wait "${dither_pid}" 2>/dev/null || true + fi +} +trap cleanup EXIT INT TERM + +# Wait until the dither server is listening instead of guessing with sleep. +for _ in {1..50}; do + if (echo >/dev/tcp/localhost/4567) >/dev/null 2>&1; then + break + fi + sleep 0.1 +done DITHER_SERVER=http://localhost:4567 hugo server